Collage  1.2.1
High-performance C++ library for developing object-oriented distributed applications.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
co::BufferConnection Class Reference

A proxy connection buffering outgoing data into a memory buffer. More...

#include <bufferConnection.h>

+ Inheritance diagram for co::BufferConnection:
+ Collaboration diagram for co::BufferConnection:

Public Member Functions

CO_API BufferConnection ()
 Construct a new buffer connection. More...
 
virtual CO_API ~BufferConnection ()
 Destruct this buffer connection. More...
 
CO_API void sendBuffer (ConnectionPtr connection)
 Flush the accumulated data, sending it to the given connection. More...
 
CO_API const lunchbox::Bufferb & getBuffer () const
 
CO_API lunchbox::Bufferb & getBuffer ()
 
CO_API uint64_t getSize () const
 
- Public Member Functions inherited from co::Connection
CO_API State getState () const
 
bool isClosed () const
 
bool isClosing () const
 
bool isConnected () const
 
bool isListening () const
 
CO_API bool isMulticast () const
 
CO_API
ConstConnectionDescriptionPtr 
getDescription () const
 
bool operator== (const Connection &rhs) const
 
virtual bool connect ()
 Connect to the remote peer. More...
 
virtual bool listen ()
 Put the connection into the listening state. More...
 
virtual void close ()
 Close a connected or listening connection. More...
 
void addListener (ConnectionListener *listener)
 
void removeListener (ConnectionListener *listener)
 
virtual void acceptNB ()
 Start an accept operation. More...
 
virtual ConnectionPtr acceptSync ()
 Complete an accept operation. More...
 
CO_API void recvNB (BufferPtr buffer, const uint64_t bytes)
 Start a read operation on the connection. More...
 
CO_API bool recvSync (BufferPtr &buffer, const bool block=true)
 Finish reading data from the connection. More...
 
BufferPtr resetRecvData ()
 
CO_API bool send (const void *buffer, const uint64_t bytes, const bool isLocked=false)
 Send data using the connection. More...
 
CO_API void lockSend () const
 Lock the connection, no other thread can send data. More...
 
CO_API void unlockSend () const
 Unlock the connection. More...
 
virtual void finish ()
 

Protected Member Functions

void readNB (void *, const uint64_t) override
 Start a read operation on the connection. More...
 
int64_t readSync (void *, const uint64_t, const bool) override
 Finish reading data from the connection. More...
 
CO_API int64_t write (const void *buffer, const uint64_t bytes) override
 Write data to the connection. More...
 
Notifier getNotifier () const override
 
- Protected Member Functions inherited from co::Connection
 Connection ()
 Construct a new connection. More...
 
virtual ~Connection ()
 Destruct this connection. More...
 
CO_API void _setDescription (ConnectionDescriptionPtr description)
 
CO_API void _setState (const State state)
 
CO_API ConnectionDescriptionPtr _getDescription ()
 

Additional Inherited Members

- Public Types inherited from co::Connection
enum  State {
  STATE_CLOSED, STATE_CONNECTING, STATE_CONNECTED, STATE_LISTENING,
  STATE_CLOSING
}
 The current state of the Connection. More...
 
typedef int Notifier
 The Notifier used by the ConnectionSet to detect readiness of a Connection.
 
- Static Public Member Functions inherited from co::Connection
static CO_API ConnectionPtr create (ConnectionDescriptionPtr desc)
 Create a new connection. More...
 
- Protected Types inherited from co::Connection
enum  ReadStatus { READ_TIMEOUT = -2, READ_ERROR = -1 }
 < error codes for readSync()
 

Detailed Description

A proxy connection buffering outgoing data into a memory buffer.

Definition at line 31 of file bufferConnection.h.

Constructor & Destructor Documentation

CO_API co::BufferConnection::BufferConnection ( )

Construct a new buffer connection.

Version
1.0
virtual CO_API co::BufferConnection::~BufferConnection ( )
virtual

Destruct this buffer connection.

Version
1.0

Member Function Documentation

CO_API const lunchbox::Bufferb& co::BufferConnection::getBuffer ( ) const
Returns
the internal data buffer.
Version
1.0
CO_API lunchbox::Bufferb& co::BufferConnection::getBuffer ( )
Returns
the internal data buffer.
Version
1.0
Notifier co::BufferConnection::getNotifier ( ) const
inlineoverrideprotectedvirtual
Returns
the notifier signaling events.
Version
1.0

Implements co::Connection.

Definition at line 64 of file bufferConnection.h.

CO_API uint64_t co::BufferConnection::getSize ( ) const
Returns
the size of the accumulated data.
Version
1.0
void co::BufferConnection::readNB ( void *  buffer,
const uint64_t  bytes 
)
inlineoverrideprotectedvirtual

Start a read operation on the connection.

This method is the low-level counterpart used by recvNB(), implemented by the concrete connection.

This function returns immediately. The operation's Notifier will signal data availability, upon which readSync() is used to finish the operation.

Parameters
bufferthe buffer receiving the data.
bytesthe number of bytes to read.
See Also
readSync()

Implements co::Connection.

Definition at line 58 of file bufferConnection.h.

int64_t co::BufferConnection::readSync ( void *  buffer,
const uint64_t  bytes,
const bool  block 
)
inlineoverrideprotectedvirtual

Finish reading data from the connection.

This method is the low-level counterpart used by recvSync(), implemented by the concrete connection. It may return with a partial read.

Parameters
bufferthe buffer receiving the data.
bytesthe number of bytes to read.
blockinternal WAR parameter, ignore it in the implementation unless you know exactly why not.
Returns
the number of bytes read, or -1 upon error.

Implements co::Connection.

Definition at line 59 of file bufferConnection.h.

CO_API void co::BufferConnection::sendBuffer ( ConnectionPtr  connection)

Flush the accumulated data, sending it to the given connection.

Version
1.0
CO_API int64_t co::BufferConnection::write ( const void *  buffer,
const uint64_t  bytes 
)
overrideprotectedvirtual

Write data to the connection.

This method is the low-level counterpart used by send(), implemented by the concrete connection. It may return with a partial write.

Parameters
bufferthe buffer containing the message.
bytesthe number of bytes to write.
Returns
the number of bytes written, or -1 upon error.

Implements co::Connection.


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