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