OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
contrail::sandesh::transport::TTransport Class Reference

#include <TTransport.h>

Inheritance diagram for contrail::sandesh::transport::TTransport:

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 ()
 

Detailed Description

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.

Constructor & Destructor Documentation

virtual contrail::sandesh::transport::TTransport::~TTransport ( )
inlinevirtual

Virtual deconstructor.

Definition at line 62 of file TTransport.h.

contrail::sandesh::transport::TTransport::TTransport ( )
inlineprotected

Simple constructor.

Definition at line 246 of file TTransport.h.

Member Function Documentation

const uint8_t* contrail::sandesh::transport::TTransport::borrow ( uint8_t *  buf,
uint32_t *  len 
)
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.

Parameters
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.
Returns
If the borrow succeeds, return a pointer to the borrowed data. This might be equal to buf, or it might be a pointer into the transport's internal buffers.
Exceptions
TTransportExceptionif an error occurs

Definition at line 216 of file TTransport.h.

Here is the call graph for this function:

virtual const uint8_t* contrail::sandesh::transport::TTransport::borrow_virt ( uint8_t *  ,
uint32_t *   
)
inlinevirtual
virtual void contrail::sandesh::transport::TTransport::close ( )
inlinevirtual

Closes the transport.

Reimplemented in contrail::sandesh::transport::TMemoryBuffer, and contrail::sandesh::transport::TFDTransport.

Definition at line 96 of file TTransport.h.

void contrail::sandesh::transport::TTransport::consume ( uint32_t  len)
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?

Parameters
lenHow many bytes to consume
Exceptions
TTransportExceptionIf an error occurs

Definition at line 233 of file TTransport.h.

Here is the call graph for this function:

virtual void contrail::sandesh::transport::TTransport::consume_virt ( uint32_t  )
inlinevirtual
virtual void contrail::sandesh::transport::TTransport::flush ( )
inlinevirtual

Flushes any pending data to be written. Typically used with buffered transport mechanisms.

Exceptions
TTransportExceptionif an error occurs

Definition at line 185 of file TTransport.h.

virtual bool contrail::sandesh::transport::TTransport::isOpen ( )
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.

virtual void contrail::sandesh::transport::TTransport::open ( )
inlinevirtual

Opens the transport for communications.

Returns
bool Whether the transport was successfully opened

Reimplemented in contrail::sandesh::transport::TMemoryBuffer, and contrail::sandesh::transport::TFDTransport.

Definition at line 88 of file TTransport.h.

virtual bool contrail::sandesh::transport::TTransport::peek ( )
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.

Here is the call graph for this function:

int32_t contrail::sandesh::transport::TTransport::read ( uint8_t *  buf,
uint32_t  len 
)
inline

Attempt to read up to the specified number of bytes into the string.

Parameters
bufReference to the location to write the data
lenHow many bytes to read
Returns
How many bytes were actually read, -1 on error

Definition at line 108 of file TTransport.h.

Here is the call graph for this function:

virtual int32_t contrail::sandesh::transport::TTransport::read_virt ( uint8_t *  ,
uint32_t   
)
inlinevirtual
int32_t contrail::sandesh::transport::TTransport::readAll ( uint8_t *  buf,
uint32_t  len 
)
inline

Reads the given amount of data in its entirety no matter what.

Parameters
sReference to location for read data
lenHow many bytes to read
Returns
How many bytes read, which must be equal to size, -1 on error

Definition at line 125 of file TTransport.h.

Here is the call graph for this function:

virtual int32_t contrail::sandesh::transport::TTransport::readAll_virt ( uint8_t *  buf,
uint32_t  len 
)
inlinevirtual
virtual uint32_t contrail::sandesh::transport::TTransport::readEnd ( )
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

Returns
number of bytes read if available, 0 otherwise.

Reimplemented in contrail::sandesh::transport::TMemoryBuffer.

Definition at line 140 of file TTransport.h.

int contrail::sandesh::transport::TTransport::write ( const uint8_t *  buf,
uint32_t  len 
)
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

Parameters
bufThe data to write out
Exceptions
TTransportExceptionif an error occurs

Definition at line 157 of file TTransport.h.

Here is the call graph for this function:

virtual int contrail::sandesh::transport::TTransport::write_virt ( const uint8_t *  ,
uint32_t   
)
inlinevirtual
virtual uint32_t contrail::sandesh::transport::TTransport::writeEnd ( )
inlinevirtual

Called when write is completed. This can be over-ridden to perform a transport-specific action at the end of a request.

Returns
number of bytes written if available, 0 otherwise

Reimplemented in contrail::sandesh::transport::TMemoryBuffer.

Definition at line 174 of file TTransport.h.


The documentation for this class was generated from the following file: