21 #ifndef CO_CONNECTION_H 22 #define CO_CONNECTION_H 27 #include <boost/noncopyable.hpp> 28 #include <lunchbox/bitOperation.h> 29 #include <lunchbox/referenced.h> 32 #include <sys/types.h> 59 class Connection :
public lunchbox::Referenced,
public boost::noncopyable
86 CO_API
State getState()
const;
89 bool isClosed()
const {
return getState() == STATE_CLOSED; }
91 bool isClosing()
const {
return getState() == STATE_CLOSING; }
93 bool isConnected()
const {
return getState() == STATE_CONNECTED; }
95 bool isListening()
const {
return getState() == STATE_LISTENING; }
97 CO_API
bool isMulticast()
const;
137 void addListener(ConnectionListener* listener);
140 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);
229 CO_API
void lockSend()
const;
232 CO_API
void unlockSend()
const;
235 virtual void finish() {}
248 virtual Notifier getNotifier()
const = 0;
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&);
328 #endif // CO_CONNECTION_H State
The current state of the Connection.
Defines export visibility macros for library Collage.
The connection has been connected and is open.
The connection is listening for connects.
A connect() or listen() is in progress.
virtual ConnectionPtr acceptSync()
Complete an accept operation.
int Notifier
The Notifier used by the ConnectionSet to detect readiness of a Connection.
Object-oriented network library.
lunchbox::RefPtr< const ConnectionDescription > ConstConnectionDescriptionPtr
A reference pointer for const ConnectionDescription pointers.
virtual void close()
Close a connected or listening connection.
virtual bool connect()
Connect to the remote peer.
virtual bool listen()
Put the connection into the listening state.
lunchbox::RefPtr< ConnectionDescription > ConnectionDescriptionPtr
A reference pointer for ConnectionDescription pointers.
lunchbox::RefPtr< Connection > ConnectionPtr
A reference pointer for Connection pointers.
virtual void acceptNB()
Start an accept operation.
An interface definition for communication between hosts.
ReadStatus
< error codes for readSync()