Panda3D
Classes | Public Member Functions | Friends | List of all members
ConnectionReader Class Referenceabstract

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). More...

#include "connectionReader.h"

Inheritance diagram for ConnectionReader:
ConnectionListener DatagramGeneratorNet PStatReader QueuedConnectionReader RecentConnectionReader PStatListener QueuedConnectionListener

Public Member Functions

 ConnectionReader (ConnectionManager *manager, int num_threads, const std::string &thread_name=std::string())
 Creates a new ConnectionReader with the indicated number of threads to handle requests. More...
 
bool add_connection (Connection *connection)
 Adds a new socket to the list of sockets the ConnectionReader will monitor. More...
 
ConnectionManagerget_manager () const
 Returns a pointer to the ConnectionManager object that serves this ConnectionReader. More...
 
int get_num_threads () const
 Returns the number of threads the ConnectionReader has been created with. More...
 
bool get_raw_mode () const
 Returns the current setting of the raw mode flag. More...
 
int get_tcp_header_size () const
 Returns the current setting of TCP header size. More...
 
bool is_connection_ok (Connection *connection)
 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. More...
 
bool is_polling () const
 Returns true if the reader is a polling reader, i.e. More...
 
void poll ()
 Explicitly polls the available sockets to see if any of them have any noise. More...
 
bool remove_connection (Connection *connection)
 Removes a socket from the list of sockets being monitored. More...
 
void set_raw_mode (bool mode)
 Sets the ConnectionReader into raw mode (or turns off raw mode). More...
 
void set_tcp_header_size (int tcp_header_size)
 Sets the header size of TCP packets. More...
 
void shutdown ()
 Terminates all threads cleanly. More...
 

Friends

class ConnectionManager
 
class ReaderThread
 

Detailed Description

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.

Definition at line 50 of file connectionReader.h.

Constructor & Destructor Documentation

◆ ConnectionReader()

ConnectionReader::ConnectionReader ( ConnectionManager manager,
int  num_threads,
const std::string &  thread_name = std::string() 
)
explicit

Creates a new ConnectionReader with the indicated number of threads to handle requests.

If num_threads is 0, the sockets will only be read by polling, during an explicit poll() call. (QueuedConnectionReader will do this automatically.)

Definition at line 89 of file connectionReader.cxx.

Member Function Documentation

◆ add_connection()

bool ConnectionReader::add_connection ( Connection connection)

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.

Definition at line 176 of file connectionReader.cxx.

Referenced by MayaToEggServer::poll(), and PStatReader::set_tcp_connection().

◆ get_manager()

ConnectionManager * ConnectionReader::get_manager ( ) const

Returns a pointer to the ConnectionManager object that serves this ConnectionReader.

Definition at line 296 of file connectionReader.cxx.

◆ get_num_threads()

int ConnectionReader::get_num_threads ( ) const

Returns the number of threads the ConnectionReader has been created with.

Definition at line 304 of file connectionReader.cxx.

◆ get_raw_mode()

bool ConnectionReader::get_raw_mode ( ) const

Returns the current setting of the raw mode flag.

See set_raw_mode().

Definition at line 325 of file connectionReader.cxx.

◆ get_tcp_header_size()

int ConnectionReader::get_tcp_header_size ( ) const

Returns the current setting of TCP header size.

See set_tcp_header_size().

Definition at line 344 of file connectionReader.cxx.

◆ is_connection_ok()

bool ConnectionReader::is_connection_ok ( Connection connection)

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.)

Definition at line 231 of file connectionReader.cxx.

◆ is_polling()

bool ConnectionReader::is_polling ( ) const
inline

Returns true if the reader is a polling reader, i.e.

it has no threads.

Definition at line 18 of file connectionReader.I.

Referenced by ConnectionManager::wait_for_readers().

◆ poll()

void ConnectionReader::poll ( )

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.

Definition at line 260 of file connectionReader.cxx.

Referenced by QueuedConnectionReader::data_available(), QueuedConnectionListener::new_connection_available(), MayaToEggServer::poll(), and PStatServer::poll().

◆ remove_connection()

bool ConnectionReader::remove_connection ( Connection connection)

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.

Definition at line 204 of file connectionReader.cxx.

◆ set_raw_mode()

void ConnectionReader::set_raw_mode ( bool  mode)

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.

Definition at line 317 of file connectionReader.cxx.

◆ set_tcp_header_size()

void ConnectionReader::set_tcp_header_size ( int  tcp_header_size)

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.

Definition at line 336 of file connectionReader.cxx.

◆ shutdown()

void ConnectionReader::shutdown ( )

Terminates all threads cleanly.

Normally this is only called by the destructor, but it may be called explicitly before destruction.

Definition at line 353 of file connectionReader.cxx.


The documentation for this class was generated from the following files: