23 #ifndef __ccxx_SocketSelector_hxx 24 #define __ccxx_SocketSelector_hxx 38 #include <sys/select.h> 86 bool writeData(
const byte_t* buf,
size_t count);
97 bool writeLine(
const String& text);
114 size_t readData(
ByteBuffer& buffer,
bool fully =
true);
126 size_t readData(
byte_t* buf,
size_t count,
bool fully =
true);
137 size_t readLine(
String& text,
size_t maxLen);
146 uint32_t readUInt32();
155 uint64_t readUInt64();
169 void setReadLowWaterMark(
size_t count);
180 void setReadHighWaterMark(
size_t count);
188 {
return(_readLoMark); }
194 bool isReadLow()
const;
200 bool isReadHigh()
const;
212 void setWriteLowWaterMark(
size_t count);
221 void setWriteHighWaterMark(
size_t count);
229 {
return(_writeLoMark); }
237 {
return(_writeHiMark); }
243 bool isWriteLow()
const;
250 bool isWriteHigh()
const;
255 size_t getBytesAvailableToRead()
const;
260 size_t getBytesAvailableToWrite()
const;
269 void close(
bool immediate =
false);
277 { _oobFlag =
false;
return(_oobData); }
286 {
return(_oobFlag); }
290 {
return(_lastRecv); }
293 bool isClosePending()
const;
302 Connection(
size_t bufferSize = DEFAULT_BUFFER_SIZE);
312 inline void setOOBFlag(
bool flag)
315 inline void setTimestamp(
time_ms_t stamp)
316 { _lastRecv = stamp; }
338 static const bool _isSameEndianness;
380 size_t getConnectionCount()
const;
425 virtual void dataReceived(
Connection* connection) = 0;
435 virtual void dataSent(
Connection* connection);
443 virtual void dataReceivedOOB(
Connection* connection);
452 virtual void connectionClosed(
Connection* connection) = 0;
461 virtual void connectionTimedOut(
Connection* connection) = 0;
470 virtual void exceptionOccurred(
Connection* connection,
473 class ConnectionList;
480 void _connectionTimedOut(
Connection* connection);
481 void _connectionClosed(
Connection* connection);
487 #ifndef CCXX_OS_WINDOWS 497 #endif // __ccxx_SocketSelector_hxx
byte_t getOOBData()
Get any pending out-of-band data byte, and clear the OOB flag.
Definition: SocketSelector.h++:276
A critical section, a synchronization primitive that is typically more efficient than but roughly sem...
Definition: CriticalSection.h++:51
time_ms_t getTimestamp() const
Get the time at which data was last received on this connection.
Definition: SocketSelector.h++:289
int64_t time_ms_t
A time expressed in milliseconds since the epoch (00:00:00, UTC, January 1, 1970).
Definition: Integers.h++:98
ConnectionList * _connections
The list of active connections.
Definition: SocketSelector.h++:473
CircularByteBuffer writeBuffer
Definition: SocketSelector.h++:323
A server (listening) socket for StreamSocket (TCP) connections.
Definition: ServerSocket.h++:40
A reliable, connection-oriented stream (TCP) socket.
Definition: StreamSocket.h++:38
An exception indicating an I/O error.
Definition: IOException.h++:36
size_t getReadLowWaterMark() const
Get the current value of the read low-water mark.
Definition: SocketSelector.h++:187
unsigned int uint_t
An alias for unsigned int.
Definition: Integers.h++:74
A mutual-exclusion lock.
Definition: Mutex.h++:49
A socket endpoint network address.
Definition: SocketAddress.h++:46
static const size_t DEFAULT_BUFFER_SIZE
The default I/O buffer size.
Definition: SocketSelector.h++:60
size_t getWriteHighWaterMark() const
Get the current value of the write high-water mark.
Definition: SocketSelector.h++:236
An integer counter whose value is modified in an atomic fashion.
Definition: AtomicCounter.h++:36
A socket I/O selector.
Definition: SocketSelector.h++:351
#define COMMONCPP_API
Definition: Common.h++:126
CircularByteBuffer readBuffer
Definition: SocketSelector.h++:322
An abstract object representing a network connection.
Definition: SocketSelector.h++:53
bool getOOBFlag() const
Test the out-of-band flag.
Definition: SocketSelector.h++:285
A buffer for storing a contiguous sequence of elements.
Definition: Buffer.h++:44
size_t getWriteLowWaterMark() const
Get the current value of the write low-water mark.
Definition: SocketSelector.h++:228
A flexible, reference counted, copy-on-write, thread-safe, nullable string.
Definition: String.h++:50
An object pool that allocates (presumably fixed-size) objects in a contiguous memory buffer...
Definition: StaticObjectPool.h++:45
#define CCXX_COPY_DECLS(CLASS)
Inlines declarations of a copy constructor and assignment operator for the class CLASS.
Definition: Common.h++:295
int timespan_ms_t
A timespan expressed in milliseconds.
Definition: Integers.h++:104
StreamSocket * getSocket()
Get the socket for this connection.
Definition: SocketSelector.h++:158
A thread of execution.
Definition: Thread.h++:55
Definition: AllocationMap.c++:25
unsigned char byte_t
An unsigned 8-bit value.
Definition: Integers.h++:68