OpenSDN source code
|
#include <TTransport.h>
Public Member Functions | |
virtual | ~TTransport () |
virtual bool | isOpen () |
virtual bool | peek () |
virtual void | open () |
virtual void | close () |
int32_t | read (uint8_t *buf, uint32_t len) |
virtual int32_t | read_virt (uint8_t *, uint32_t) |
int32_t | readAll (uint8_t *buf, uint32_t len) |
virtual int32_t | readAll_virt (uint8_t *buf, uint32_t len) |
virtual uint32_t | readEnd () |
int | write (const uint8_t *buf, uint32_t len) |
virtual int | write_virt (const uint8_t *, uint32_t) |
virtual uint32_t | writeEnd () |
virtual void | flush () |
const uint8_t * | borrow (uint8_t *buf, uint32_t *len) |
virtual const uint8_t * | borrow_virt (uint8_t *, uint32_t *) |
void | consume (uint32_t len) |
virtual void | consume_virt (uint32_t) |
Protected Member Functions | |
TTransport () | |
Generic interface for a method of transporting data. A TTransport may be capable of either reading or writing, but not necessarily both.
Definition at line 57 of file TTransport.h.
|
inlinevirtual |
Virtual deconstructor.
Definition at line 62 of file TTransport.h.
|
inlineprotected |
Simple constructor.
Definition at line 246 of file TTransport.h.
|
inline |
Attempts to return a pointer to len
bytes, possibly copied into buf
. Does not consume the bytes read (i.e.: a later read will return the same data). This method is meant to support protocols that need to read variable-length fields. They can attempt to borrow the maximum amount of data that they will need, then consume (see next method) what they actually use. Some transports will not support this method and others will fail occasionally, so protocols must be prepared to use read if borrow fails.
buf A buffer where the data can be stored if needed. If borrow doesn't return buf, then the contents of buf after the call are undefined. This parameter may be NULL to indicate that the caller is not supplying storage, but would like a pointer into an internal buffer, if available.
len | *len should initially contain the number of bytes to borrow. If borrow succeeds, *len will contain the number of bytes available in the returned pointer. This will be at least what was requested, but may be more if borrow returns a pointer to an internal buffer, rather than buf. If borrow fails, the contents of *len are undefined. |
buf
, or it might be a pointer into the transport's internal buffers. TTransportException | if an error occurs |
Definition at line 216 of file TTransport.h.
|
inlinevirtual |
Reimplemented in contrail::sandesh::transport::TVirtualTransport< TBufferBase >, contrail::sandesh::transport::TVirtualTransport< TFDTransport >, and contrail::sandesh::transport::TVirtualTransport< TMemoryBuffer, TBufferBase >.
Definition at line 220 of file TTransport.h.
|
inlinevirtual |
Closes the transport.
Reimplemented in contrail::sandesh::transport::TMemoryBuffer, and contrail::sandesh::transport::TFDTransport.
Definition at line 96 of file TTransport.h.
|
inline |
Remove len bytes from the transport. This should always follow a borrow of at least len bytes, and should always succeed. TODO(dreiss): Is there any transport that could borrow but fail to consume, or that would require a buffer to dump the consumed data?
len | How many bytes to consume |
TTransportException | If an error occurs |
Definition at line 233 of file TTransport.h.
|
inlinevirtual |
Reimplemented in contrail::sandesh::transport::TVirtualTransport< TBufferBase >, contrail::sandesh::transport::TVirtualTransport< TFDTransport >, and contrail::sandesh::transport::TVirtualTransport< TMemoryBuffer, TBufferBase >.
Definition at line 237 of file TTransport.h.
|
inlinevirtual |
Flushes any pending data to be written. Typically used with buffered transport mechanisms.
TTransportException | if an error occurs |
Definition at line 185 of file TTransport.h.
|
inlinevirtual |
Whether this transport is open.
Reimplemented in contrail::sandesh::transport::TMemoryBuffer, and contrail::sandesh::transport::TFDTransport.
Definition at line 67 of file TTransport.h.
|
inlinevirtual |
Opens the transport for communications.
Reimplemented in contrail::sandesh::transport::TMemoryBuffer, and contrail::sandesh::transport::TFDTransport.
Definition at line 88 of file TTransport.h.
|
inlinevirtual |
Tests whether there is more data to read or if the remote side is still open. By default this is true whenever the transport is open, but implementations should add logic to test for this condition where possible (i.e. on a socket). This is used by a server to check if it should listen for another request.
Reimplemented in contrail::sandesh::transport::TMemoryBuffer.
Definition at line 79 of file TTransport.h.
|
inline |
Attempt to read up to the specified number of bytes into the string.
buf | Reference to the location to write the data |
len | How many bytes to read |
Definition at line 108 of file TTransport.h.
|
inlinevirtual |
Reimplemented in contrail::sandesh::transport::TVirtualTransport< TBufferBase >, contrail::sandesh::transport::TVirtualTransport< TFDTransport >, and contrail::sandesh::transport::TVirtualTransport< TMemoryBuffer, TBufferBase >.
Definition at line 112 of file TTransport.h.
|
inline |
Reads the given amount of data in its entirety no matter what.
s | Reference to location for read data |
len | How many bytes to read |
Definition at line 125 of file TTransport.h.
|
inlinevirtual |
Reimplemented in contrail::sandesh::transport::TVirtualTransport< TBufferBase >, contrail::sandesh::transport::TVirtualTransport< TFDTransport >, and contrail::sandesh::transport::TVirtualTransport< TMemoryBuffer, TBufferBase >.
Definition at line 129 of file TTransport.h.
|
inlinevirtual |
Called when read is completed. This can be over-ridden to perform a transport-specific action e.g. logging the request to a file
Reimplemented in contrail::sandesh::transport::TMemoryBuffer.
Definition at line 140 of file TTransport.h.
|
inline |
Writes the string in its entirety to the buffer.
Note: You must call flush() to ensure the data is actually written, and available to be read back in the future. Destroying a TTransport object does not automatically flush pending data–if you destroy a TTransport object with written but unflushed data, that data may be discarded. Returns 0 on success, non-zero otherwise
buf | The data to write out |
TTransportException | if an error occurs |
Definition at line 157 of file TTransport.h.
|
inlinevirtual |
Reimplemented in contrail::sandesh::transport::TVirtualTransport< TBufferBase >, contrail::sandesh::transport::TVirtualTransport< TFDTransport >, and contrail::sandesh::transport::TVirtualTransport< TMemoryBuffer, TBufferBase >.
Definition at line 161 of file TTransport.h.
|
inlinevirtual |
Called when write is completed. This can be over-ridden to perform a transport-specific action at the end of a request.
Reimplemented in contrail::sandesh::transport::TMemoryBuffer.
Definition at line 174 of file TTransport.h.