Panda3D
Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes

QueuedConnectionListener Class Reference

This flavor of ConnectionListener will queue up all of the TCP connections it established for later detection by the client code. More...

#include "queuedConnectionListener.h"

Inheritance diagram for QueuedConnectionListener:
ConnectionListener QueuedReturn< ConnectionListenerData > ConnectionReader

List of all members.

Public Member Functions

 QueuedConnectionListener (ConnectionManager *manager, int num_threads)
bool add_connection (Connection *connection)
 Adds a new socket to the list of sockets the ConnectionReader will monitor.
int get_current_queue_size () const
ConnectionManagerget_manager () const
 Returns a pointer to the ConnectionManager object that serves this ConnectionReader.
int get_max_queue_size () const
bool get_new_connection (PT(Connection)&rendezvous, NetAddress &address, PT(Connection)&new_connection)
 If a previous call to new_connection_available() returned true, this function will return information about the newly established connection.
bool get_new_connection (PT(Connection)&new_connection)
 This flavor of get_new_connection() simply returns a new connection, assuming the user doesn't care about the rendezvous socket that originated it or the address it came from.
int get_num_threads () const
 Returns the number of threads the ConnectionReader has been created with.
bool get_overflow_flag () const
bool get_raw_mode () const
 Returns the current setting of the raw mode flag.
int get_tcp_header_size () const
 Returns the current setting of TCP header size.
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.
bool is_polling () const
 Returns true if the reader is a polling reader, i.e.
bool new_connection_available ()
 Returns true if a new connection was recently established; the connection information may then be retrieved via get_new_connection().
void poll ()
 Explicitly polls the available sockets to see if any of them have any noise.
bool remove_connection (Connection *connection)
 Removes a socket from the list of sockets being monitored.
void reset_overflow_flag ()
void set_max_queue_size (int max_size)
void set_raw_mode (bool mode)
 Sets the ConnectionReader into raw mode (or turns off raw mode).
void set_tcp_header_size (int tcp_header_size)
 Sets the header size of TCP packets.
void shutdown ()
 Terminates all threads cleanly.

Protected Types

typedef pvector< SocketInfo * > Sockets

Protected Member Functions

void clear_manager ()
 This should normally only be called when the associated ConnectionManager destructs.
virtual void connection_opened (const PT(Connection)&rendezvous, const NetAddress &address, const PT(Connection)&new_connection)
 An internal function called by ConnectionListener() when a new TCP connection has been established.
bool enqueue_thing (const ConnectionListenerData &thing)
bool enqueue_unique_thing (const ConnectionListenerData &thing)
void finish_socket (SocketInfo *sinfo)
 To be called when a socket has been fully read and is ready for polling for additional data.
virtual void flush_read_connection (Connection *connection)
 Attempts to read all the possible data from the indicated connection, which has just delivered a write error (and has therefore already been closed).
bool get_thing (ConnectionListenerData &thing)
virtual bool process_incoming_data (SocketInfo *sinfo)
 This is the function that is called when activity is detected on a rendezvous port.
virtual bool process_incoming_tcp_data (SocketInfo *sinfo)
virtual bool process_incoming_udp_data (SocketInfo *sinfo)
virtual bool process_raw_incoming_tcp_data (SocketInfo *sinfo)
virtual bool process_raw_incoming_udp_data (SocketInfo *sinfo)
virtual void receive_datagram (const NetDatagram &datagram)
 This function must be declared because it is pure virtual in the base class, but it isn't used in this class and doesn't do anything.
bool thing_available () const

Protected Attributes

ConnectionManager_manager
Sockets _removed_sockets
Sockets _sockets
LightMutex _sockets_mutex

Detailed Description

This flavor of ConnectionListener will queue up all of the TCP connections it established for later detection by the client code.

Definition at line 48 of file queuedConnectionListener.h.


Member Function Documentation

bool ConnectionReader::add_connection ( Connection connection) [inherited]

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 196 of file connectionReader.cxx.

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

void ConnectionReader::clear_manager ( ) [protected, inherited]

This should normally only be called when the associated ConnectionManager destructs.

It resets the ConnectionManager pointer to NULL so we don't have a floating pointer. This makes the ConnectionReader invalid; presumably it also will be destructed momentarily.

Definition at line 471 of file connectionReader.cxx.

void QueuedConnectionListener::connection_opened ( const PT(Connection)&  rendezvous,
const NetAddress address,
const PT(Connection)&  new_connection 
) [protected, virtual]

An internal function called by ConnectionListener() when a new TCP connection has been established.

The QueuedConnectionListener simply queues up this fact for later retrieval by get_new_connection().

Implements ConnectionListener.

Definition at line 115 of file queuedConnectionListener.cxx.

References QueuedReturn< ConnectionListenerData >::enqueue_thing().

void ConnectionReader::finish_socket ( SocketInfo sinfo) [protected, inherited]

To be called when a socket has been fully read and is ready for polling for additional data.

Definition at line 482 of file connectionReader.cxx.

Referenced by ConnectionListener::process_incoming_data().

void ConnectionReader::flush_read_connection ( Connection connection) [protected, virtual, inherited]

Attempts to read all the possible data from the indicated connection, which has just delivered a write error (and has therefore already been closed).

If the connection is not monitered by this reader, does nothing.

Definition at line 431 of file connectionReader.cxx.

References Socket_fdset::clear(), ConnectionReader::process_incoming_data(), and ConnectionReader::remove_connection().

ConnectionManager * ConnectionReader::get_manager ( ) const [inherited]

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

Definition at line 330 of file connectionReader.cxx.

bool QueuedConnectionListener::get_new_connection ( PT(Connection)&  rendezvous,
NetAddress address,
PT(Connection)&  new_connection 
)

If a previous call to new_connection_available() returned true, this function will return information about the newly established connection.

The rendezvous parameter is the particular rendezvous socket this new connection originally communicated with; it is provided in case the ConnectionListener was monitorind more than one and you care which one it was. The address parameter is the net address of the new client, and new_connection is the socket of the newly established connection.

The return value is true if a connection was successfully returned, or false if there was, in fact, no new connection. (This may happen if there are multiple threads accessing the QueuedConnectionListener).

Definition at line 76 of file queuedConnectionListener.cxx.

References QueuedReturn< ConnectionListenerData >::get_thing().

Referenced by get_new_connection(), and MayaToEggServer::poll().

bool QueuedConnectionListener::get_new_connection ( PT(Connection)&  new_connection)

This flavor of get_new_connection() simply returns a new connection, assuming the user doesn't care about the rendezvous socket that originated it or the address it came from.

Definition at line 99 of file queuedConnectionListener.cxx.

References get_new_connection().

int ConnectionReader::get_num_threads ( ) const [inherited]

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

Definition at line 341 of file connectionReader.cxx.

bool ConnectionReader::get_raw_mode ( ) const [inherited]

Returns the current setting of the raw mode flag.

See set_raw_mode().

Definition at line 368 of file connectionReader.cxx.

int ConnectionReader::get_tcp_header_size ( ) const [inherited]

Returns the current setting of TCP header size.

See set_tcp_header_size().

Definition at line 393 of file connectionReader.cxx.

bool ConnectionReader::is_connection_ok ( Connection connection) [inherited]

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 258 of file connectionReader.cxx.

bool ConnectionReader::is_polling ( ) const [inline, inherited]

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

it has no threads.

Definition at line 23 of file connectionReader.I.

Referenced by DatagramGeneratorNet::get_datagram().

bool QueuedConnectionListener::new_connection_available ( )

Returns true if a new connection was recently established; the connection information may then be retrieved via get_new_connection().

Definition at line 49 of file queuedConnectionListener.cxx.

References ConnectionReader::poll(), and QueuedReturn< ConnectionListenerData >::thing_available().

Referenced by MayaToEggServer::poll().

void ConnectionReader::poll ( ) [inherited]

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 292 of file connectionReader.cxx.

References TrueClock::get_global_ptr(), and ConnectionReader::process_incoming_data().

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

bool ConnectionListener::process_incoming_data ( SocketInfo sinfo) [protected, virtual, inherited]

This is the function that is called when activity is detected on a rendezvous port.

In this case, it performs the accept().

Reimplemented from ConnectionReader.

Definition at line 63 of file connectionListener.cxx.

References ConnectionReader::finish_socket(), Thread::force_yield(), NetAddress::get_ip_string(), Socket_IP::GetLastError(), and ConnectionManager::new_connection().

void ConnectionListener::receive_datagram ( const NetDatagram datagram) [protected, virtual, inherited]

This function must be declared because it is pure virtual in the base class, but it isn't used in this class and doesn't do anything.

Implements ConnectionReader.

Definition at line 50 of file connectionListener.cxx.

bool ConnectionReader::remove_connection ( Connection connection) [inherited]

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 227 of file connectionReader.cxx.

Referenced by ConnectionReader::flush_read_connection().

void ConnectionReader::set_raw_mode ( bool  mode) [inherited]

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 357 of file connectionReader.cxx.

void ConnectionReader::set_tcp_header_size ( int  tcp_header_size) [inherited]

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 382 of file connectionReader.cxx.

void ConnectionReader::shutdown ( ) [inherited]

Terminates all threads cleanly.

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

Definition at line 405 of file connectionReader.cxx.


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations