21 #ifndef CO_CONNECTION_H
22 #define CO_CONNECTION_H
27 #include <lunchbox/bitOperation.h>
28 #include <lunchbox/referenced.h>
29 #include <boost/noncopyable.hpp>
31 #include <sys/types.h>
37 namespace detail {
class Connection; }
56 class Connection :
public lunchbox::Referenced,
public boost::noncopyable
104 bool operator == (
const Connection& rhs )
const;
140 void addListener( ConnectionListener* listener );
143 void removeListener( ConnectionListener* listener );
186 CO_API
void recvNB( BufferPtr buffer,
const uint64_t bytes );
203 CO_API
bool recvSync( BufferPtr& buffer,
const bool block =
true );
205 BufferPtr resetRecvData();
225 CO_API
bool send(
const void* buffer,
const uint64_t bytes,
226 const bool isLocked =
false );
235 virtual void finish() {}
280 virtual void readNB(
void* buffer,
const uint64_t bytes ) = 0;
294 virtual int64_t
readSync(
void* buffer,
const uint64_t bytes,
295 const bool block ) = 0;
307 virtual int64_t
write(
const void* buffer,
const uint64_t bytes ) = 0;
315 CO_API
void _setState(
const State state );
322 detail::Connection*
const _impl;
325 CO_API std::ostream& operator << ( std::ostream&,
const Connection& );
334 #endif //CO_CONNECTION_H
State
The current state of the Connection.
Defines export visibility macros for library Collage.
Connection()
Construct a new connection.
lunchbox::RefPtr< ConnectionDescription > ConnectionDescriptionPtr
A reference pointer for ConnectionDescription pointers.
The connection has been connected and is open.
CO_API void recvNB(BufferPtr buffer, const uint64_t bytes)
Start a read operation on the connection.
CO_API bool recvSync(BufferPtr &buffer, const bool block=true)
Finish reading data from the connection.
virtual Notifier getNotifier() const =0
CO_API void lockSend() const
Lock the connection, no other thread can send data.
The connection is listening for connects.
A connect() or listen() is in progress.
virtual ConnectionPtr acceptSync()
Complete an accept operation.
static CO_API ConnectionPtr create(ConnectionDescriptionPtr desc)
Create a new connection.
virtual ~Connection()
Destruct this connection.
virtual int64_t readSync(void *buffer, const uint64_t bytes, const bool block)=0
Finish reading data from the connection.
int Notifier
The Notifier used by the ConnectionSet to detect readiness of a Connection.
virtual void readNB(void *buffer, const uint64_t bytes)=0
Start a read operation on the connection.
CO_API State getState() const
virtual void close()
Close a connected or listening connection.
CO_API bool isMulticast() const
virtual bool connect()
Connect to the remote peer.
A close() is in progress.
virtual int64_t write(const void *buffer, const uint64_t bytes)=0
Write data to the connection.
virtual bool listen()
Put the connection into the listening state.
CO_API bool send(const void *buffer, const uint64_t bytes, const bool isLocked=false)
Send data using the connection.
CO_API void unlockSend() const
Unlock the connection.
virtual void acceptNB()
Start an accept operation.
An interface definition for communication between hosts.
ReadStatus
< error codes for readSync()
lunchbox::RefPtr< const ConnectionDescription > ConstConnectionDescriptionPtr
A reference pointer for const ConnectionDescription pointers.
CO_API ConstConnectionDescriptionPtr getDescription() const
CO_API ConnectionDescriptionPtr _getDescription()
lunchbox::RefPtr< Connection > ConnectionPtr
A reference pointer for Connection pointers.