Panda3D
Public Member Functions

DatagramGeneratorNet Class Reference

This class provides datagrams one-at-a-time as read directly from the net, via a TCP connection. More...

Inheritance diagram for DatagramGeneratorNet:
DatagramGenerator ConnectionReader QueuedReturnDatagram

List of all members.

Public Member Functions

 DatagramGeneratorNet (ConnectionManager manager, int num_threads)
 Creates a new DatagramGeneratorNet with the indicated number of threads to handle requests.
bool addConnection (Connection connection)
 Adds a new socket to the list of sockets the ConnectionReader will monitor.
int getCurrentQueueSize ()
bool getDatagram (Datagram data)
 Reads the next datagram from the stream.
VirtualFile getFile ()
 Returns the VirtualFile that provides the source for these datagrams, if any, or NULL if the datagrams do not originate from a VirtualFile.
int getFilePos ()
 Returns the current file position within the data stream, if any, or 0 if the file position is not meaningful or cannot be determined.
ConnectionManager getManager ()
 Returns a pointer to the ConnectionManager object that serves this ConnectionReader.
int getMaxQueueSize ()
int getNumThreads ()
 Returns the number of threads the ConnectionReader has been created with.
bool getOverflowFlag ()
bool getRawMode ()
 Returns the current setting of the raw mode flag.
int getTcpHeaderSize ()
 Returns the current setting of TCP header size.
bool isConnectionOk (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 isEof ()
 Returns true if the stream has been closed normally.
bool isError ()
 Returns true if the stream has an error condition.
bool isPolling ()
 Returns true if the reader is a polling reader, i.e.
 poll ()
 Explicitly polls the available sockets to see if any of them have any noise.
bool removeConnection (Connection connection)
 Removes a socket from the list of sockets being monitored.
 resetOverflowFlag ()
 setMaxQueueSize (int max_size)
 setRawMode (bool mode)
 Sets the ConnectionReader into raw mode (or turns off raw mode).
 setTcpHeaderSize (int tcp_header_size)
 Sets the header size of TCP packets.
 shutdown ()
 Terminates all threads cleanly.

Detailed Description

This class provides datagrams one-at-a-time as read directly from the net, via a TCP connection.

If a datagram is not available, get_datagram() will block until one is.


Constructor & Destructor Documentation

DatagramGeneratorNet ( ConnectionManager  manager,
int  num_threads 
)

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

Normally num_threads should be either 0 or 1 to guarantee that datagrams are generated in the same order in which they were received.


Member Function Documentation

bool addConnection ( 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.

int getCurrentQueueSize ( ) [inherited]
bool getDatagram ( Datagram  data)

Reads the next datagram from the stream.

Blocks until a datagram is available. Returns true on success, false on stream closed or error.

Reimplemented from DatagramGenerator.

VirtualFile getFile ( ) [inherited]

Returns the VirtualFile that provides the source for these datagrams, if any, or NULL if the datagrams do not originate from a VirtualFile.

int getFilePos ( ) [inherited]

Returns the current file position within the data stream, if any, or 0 if the file position is not meaningful or cannot be determined.

For DatagramGenerators that return a meaningful file position, this will be pointing to the first byte following the datagram returned after a call to get_datagram().

ConnectionManager getManager ( ) [inherited]

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

int getMaxQueueSize ( ) [inherited]
int getNumThreads ( ) [inherited]

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

bool getOverflowFlag ( ) [inherited]
bool getRawMode ( ) [inherited]

Returns the current setting of the raw mode flag.

See set_raw_mode().

int getTcpHeaderSize ( ) [inherited]

Returns the current setting of TCP header size.

See set_tcp_header_size().

bool isConnectionOk ( 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.)

bool isEof ( )

Returns true if the stream has been closed normally.

This test may only be made after a call to get_datagram() has failed.

Reimplemented from DatagramGenerator.

bool isError ( )

Returns true if the stream has an error condition.

Reimplemented from DatagramGenerator.

bool isPolling ( ) [inherited]

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

it has no threads.

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.

bool removeConnection ( 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.

resetOverflowFlag ( ) [inherited]
setMaxQueueSize ( int  max_size) [inherited]
setRawMode ( 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.

setTcpHeaderSize ( 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.

shutdown ( ) [inherited]

Terminates all threads cleanly.

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

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties