21 #ifndef CO_CONNECTION_H
22 #define CO_CONNECTION_H
27 #include <lunchbox/referenced.h>
29 #include <sys/types.h>
34 # define EQ_DEFAULT_PORT (4242)
36 # define EQ_DEFAULT_PORT (4242 + getuid())
41 namespace detail {
class Connection; }
60 class Connection :
public lunchbox::Referenced,
public lunchbox::NonCopyable
108 bool operator == (
const Connection& rhs )
const;
144 void addListener( ConnectionListener* listener );
147 void removeListener( ConnectionListener* listener );
187 CO_API
void recvNB( BufferPtr buffer,
const uint64_t bytes );
204 CO_API
bool recvSync( BufferPtr& buffer,
const bool block =
true );
206 BufferPtr resetRecvData();
226 CO_API
bool send(
const void* buffer,
const uint64_t bytes,
227 const bool isLocked =
false );
236 virtual void finish() {}
281 virtual void readNB(
void* buffer,
const uint64_t bytes ) = 0;
296 virtual int64_t
readSync(
void* buffer,
const uint64_t bytes,
297 const bool block ) = 0;
309 virtual int64_t
write(
const void* buffer,
const uint64_t bytes ) = 0;
317 CO_API
void _setState(
const State state );
324 detail::Connection*
const _impl;
327 CO_API std::ostream& operator << ( std::ostream&,
const Connection& );
335 #endif //CO_CONNECTION_H
CO_API void unlockSend() const
Unlock the connection.
virtual int64_t readSync(void *buffer, const uint64_t bytes, const bool block)=0
Finish reading data from the connection.
virtual void readNB(void *buffer, const uint64_t bytes)=0
Start a read operation on the connection.
virtual void acceptNB()
Start an accept operation.
virtual ~Connection()
Destruct this connection.
lunchbox::RefPtr< ConnectionDescription > ConnectionDescriptionPtr
A reference pointer for ConnectionDescription pointers.
static CO_API ConnectionPtr create(ConnectionDescriptionPtr desc)
Create a new connection.
virtual bool connect()
Connect to the remote peer.
An interface definition for communication between hosts.
virtual ConnectionPtr acceptSync()
Complete an accept operation.
CO_API State getState() const
CO_API bool recvSync(BufferPtr &buffer, const bool block=true)
Finish reading data from the connection.
State
The current state of the Connection.
CO_API ConnectionDescriptionPtr _getDescription()
A close() is in progress.
ReadStatus
< error codes for readSync()
virtual void close()
Close a connected or listening connection.
A connect() or listen() is in progress.
The connection is listening for connects.
CO_API void lockSend() const
Lock the connection, no other thread can send data.
CO_API void recvNB(BufferPtr buffer, const uint64_t bytes)
Start a read operation on the connection.
int Notifier
The Notifier used by the ConnectionSet to detect readiness of a Connection.
CO_API bool isMulticast() const
virtual Notifier getNotifier() const =0
virtual bool listen()
Put the connection into the listening state.
Connection()
Construct a new connection.
CO_API bool send(const void *buffer, const uint64_t bytes, const bool isLocked=false)
Send data using the connection.
CO_API ConstConnectionDescriptionPtr getDescription() const
lunchbox::RefPtr< const ConnectionDescription > ConstConnectionDescriptionPtr
A reference pointer for const ConnectionDescription pointers.
The connection has been connected and is open.
virtual int64_t write(const void *buffer, const uint64_t bytes)=0
Write data to the connection.
lunchbox::RefPtr< Connection > ConnectionPtr
A reference pointer for Connection pointers.