This is an abstract base class for a family of classes that listen for activity on a socket and respond to it, for instance by reading a datagram and serving it (or queueing it up for later service).
A ConnectionReader may define an arbitrary number of threads (at least one) to process datagrams coming in from an arbitrary number of sockets that it is monitoring. The number of threads is specified at construction time and cannot be changed, but the set of sockets that is to be monitored may be constantly modified at will.
This is an abstract class because it doesn’t define how to process each received datagram. See QueuedConnectionReader. Also note that ConnectionListener derives from this class, extending it to accept connections on a rendezvous socket rather than read datagrams.
addConnection(connection: Connection) → bool¶
Adds a new socket to the list of sockets the ConnectionReader will monitor. A datagram that comes in on any of the monitored sockets will be reported. In the case of a ConnectionListener, this adds a new rendezvous socket; any activity on any of the monitored sockets will cause a connection to be accepted.
The return value is true if the connection was added, false if it was already there.
addConnection()is thread-safe, and may be called at will by any thread.
removeConnection(connection: Connection) → bool¶
Removes a socket from the list of sockets being monitored. Returns true if the socket was correctly removed, false if it was not on the list in the first place.
removeConnection()is thread-safe, and may be called at will by any thread.
isConnectionOk(connection: Connection) → bool¶
Returns true if the indicated connection has been added to the ConnectionReader and is being monitored properly, false if it is not known, or if there was some error condition detected on the connection. (If there was an error condition, normally the ConnectionManager would have been informed and closed the connection.)
poll() → None¶
Explicitly polls the available sockets to see if any of them have any noise. This function does nothing unless this is a polling-type ConnectionReader, i.e. it was created with zero threads (and
isPolling()will return true).
It is not necessary to call this explicitly for a QueuedConnectionReader.
getManager() → ConnectionManager¶
Returns a pointer to the ConnectionManager object that serves this ConnectionReader.
- Return type
isPolling() → bool¶
Returns true if the reader is a polling reader, i.e. it has no threads.
getNumThreads() → int¶
Returns the number of threads the ConnectionReader has been created with.
setRawMode(mode: bool) → None¶
Sets the ConnectionReader into raw mode (or turns off raw mode). In raw mode, datagram headers are not expected; instead, all the data available on the pipe is treated as a single datagram.
This is similar to set_tcp_header_size(0), except that it also turns off headers for UDP packets.
setTcpHeaderSize(tcp_header_size: int) → None¶
Sets the header size of TCP packets. At the present, legal values for this are 0, 2, or 4; this specifies the number of bytes to use encode the datagram length at the start of each TCP datagram. Sender and receiver must independently agree on this.
shutdown() → None¶
Terminates all threads cleanly. Normally this is only called by the destructor, but it may be called explicitly before destruction.