Home | History | Annotate | Download | only in flip_server
      1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef NET_TOOLS_FLIP_SERVER_BUFFER_INTERFACE_H__
      6 #define NET_TOOLS_FLIP_SERVER_BUFFER_INTERFACE_H__
      7 
      8 namespace net {
      9 
     10 class BufferInterface {
     11  public:
     12 
     13   //   Returns the bytes which can be read from the buffer.  There is no
     14   //   guarantee that the bytes are contiguous.
     15   virtual int ReadableBytes() const = 0;
     16 
     17   // Summary:
     18   //   returns the size of this buffer
     19   // Returns:
     20   //   size of this buffer.
     21   virtual int BufferSize() const = 0;
     22 
     23   // Summary:
     24   //   returns the number of bytes free in this buffer.
     25   // Returns:
     26   //   number of bytes free.
     27   virtual int BytesFree() const = 0;
     28 
     29   // Summary:
     30   //   Returns true if empty.
     31   // Returns:
     32   //   true - if empty
     33   //   false - otherwise
     34   virtual bool Empty() const = 0;
     35 
     36   // Summary:
     37   //   Returns true if the buffer is full.
     38   virtual bool Full() const = 0;
     39 
     40   // Summary:
     41   //   returns the number of characters written.
     42   //   appends up-to-'size' bytes to the buffer.
     43   // Args:
     44   //   bytes - bytes which are read, and copied into the buffer.
     45   //   size  - number of bytes which are read and copied.
     46   //           this number shall be >= 0.
     47   virtual int Write(const char* bytes, int size) = 0;
     48 
     49   // Summary:
     50   //   Gets a pointer which can be written to (assigned to).
     51   //   this pointer (and size) can be used in functions like
     52   //   recv() or read(), etc.
     53   //   If *size is zero upon returning from this function, that it
     54   //   is unsafe to dereference *ptr.
     55   // Args:
     56   //   ptr - assigned a pointer to which we can write
     57   //   size - the amount of data (in bytes) that it is safe to write to ptr.
     58   virtual void GetWritablePtr(char **ptr, int* size) const = 0;
     59 
     60   // Summary:
     61   //   Gets a pointer which can be read from
     62   //   this pointer (and size) can be used in functions like
     63   //   send() or write(), etc.
     64   //   If *size is zero upon returning from this function, that it
     65   //   is unsafe to dereference *ptr.
     66   // Args:
     67   //   ptr - assigned a pointer from which we may read
     68   //   size - the amount of data (in bytes) that it is safe to read
     69   virtual void GetReadablePtr(char **ptr, int* size) const = 0;
     70 
     71   // Summary:
     72   //   Reads bytes out of the buffer, and writes them into 'bytes'.
     73   //   Returns the number of bytes read.
     74   //   Consumes bytes from the buffer (possibly, but not necessarily
     75   //   rendering them free)
     76   // Args:
     77   //   bytes - the pointer into which bytes are read from this buffer
     78   //           and written into
     79   //   size  - number of bytes which are read and copied.
     80   //           this number shall be >= 0.
     81   // Returns:
     82   //   the number of bytes read from 'bytes'
     83   virtual int Read(char* bytes, int size) = 0;
     84 
     85   // Summary:
     86   //   removes all data from the buffer
     87   virtual void Clear() = 0;
     88 
     89   // Summary:
     90   //   reserves contiguous writable empty space in the buffer of size bytes.
     91   //   Returns true if the reservation is successful.
     92   //   If a derive class chooses not to implement reservation, its
     93   //   implementation should return false.
     94   virtual bool Reserve(int size) = 0;
     95 
     96   // Summary:
     97   //   removes the oldest 'amount_to_consume' characters from this buffer,
     98   // Args:
     99   //   amount_to_advance - .. this should be self-explanatory =)
    100   //                       this number shall be >= 0.
    101   virtual void AdvanceReadablePtr(int amount_to_advance) = 0;
    102 
    103   // Summary:
    104   //   Moves the internal pointers around such that the
    105   //   amount of data specified here is expected to
    106   //   already be resident (as if it was Written)
    107   // Args:
    108   //   amount_to_advance - self explanatory.
    109   //                       this number shall be >= 0.
    110   virtual void AdvanceWritablePtr(int amount_to_advance) = 0;
    111 
    112   virtual ~BufferInterface() {}
    113 
    114  protected:
    115   BufferInterface() {}
    116 };
    117 
    118 }  // namespace net
    119 
    120 #endif  // NET_TOOLS_FLIP_SERVER_BUFFER_INTERFACE__H__
    121 
    122