# RecentConnectionReader

from pandac.PandaModules import RecentConnectionReader

Class : RecentConnectionReader
Description : This flavor of ConnectionReader will read from its sockets and retain only the single most recent datagram for inspection by client code. It's useful particularly for reading telemetry-type data from UDP sockets where you don't care about getting every last socket, and in fact if the sockets are coming too fast you'd prefer to skip some of them.
This class will always create one thread for itself.

## Inheritance:

RecentConnectionReader: ConnectionReader
ConnectionReader:

## Methods of RecentConnectionReader:

dataAvailable
getData

## Methods of ConnectionReader:

addConnection
getManager
getNumThreads
getRawMode
getTcpHeaderSize
isConnectionOk
isPolling
poll
removeConnection
setRawMode
setTcpHeaderSize

dataAvailable bool RecentConnectionReader::data_available(void); Description: Returns true if a datagram is available on the queue; call get_data() to extract the datagram.

getData bool RecentConnectionReader::get_data(NetDatagram &result); Description: If a previous call to data_available() returned true, this function will return the datagram that has become available. The return value is true if a datagram was successfully returned, or false if there was, in fact, no datagram available. (This may happen if there are multiple threads accessing the RecentConnectionReader). Description: This flavor of RecentConnectionReader::get_data(), works like the other, except that it only fills a Datagram object, not a NetDatagram object. This means that the Datagram cannot be queried for its source Connection and/or NetAddress, but it is useful in all other respects.

addConnection bool ConnectionReader::add_connection(Connection *connection); Description: 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. add_connection() is thread-safe, and may be called at will by any thread.

getManager ConnectionManager *ConnectionReader::get_manager(void) const; Description: Returns a pointer to the ConnectionManager object that serves this ConnectionReader.

getNumThreads int ConnectionReader::get_num_threads(void) const; Description: Returns the number of threads the ConnectionReader has been created with.

getRawMode bool ConnectionReader::get_raw_mode(void) const; Description: Returns the current setting of the raw mode flag. See set_raw_mode().

getTcpHeaderSize int ConnectionReader::get_tcp_header_size(void) const; Description: Returns the current setting of TCP header size. See set_tcp_header_size().

isConnectionOk bool ConnectionReader::is_connection_ok(Connection *connection); Description: 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.)

isPolling bool ConnectionReader::is_polling(void) const; Description: Returns true if the reader is a polling reader, i.e. it has no threads.

poll void ConnectionReader::poll(void); Description: 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 is_polling() will return true). It is not necessary to call this explicitly for a QueuedConnectionReader.

removeConnection bool ConnectionReader::remove_connection(Connection *connection); Description: 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. remove_connection() is thread-safe, and may be called at will by any thread.

setRawMode void ConnectionReader::set_raw_mode(bool mode); Description: 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 void ConnectionReader::set_tcp_header_size(int tcp_header_size); Description: 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.