Panda3D
Public Member Functions | List of all members
ConnectionWriter Class Reference

This class handles threaded delivery of datagrams to various TCP or UDP sockets. More...

Inheritance diagram for ConnectionWriter:
DatagramSinkNet

Public Member Functions

 __init__ (ConnectionManager manager, int num_threads, str thread_name)
 Creates a new ConnectionWriter with the indicated number of threads to handle output. More...
 
int getCurrentQueueSize ()
 Returns the current number of things in the queue. More...
 
ConnectionManager getManager ()
 Returns a pointer to the ConnectionManager object that serves this ConnectionWriter. More...
 
int getMaxQueueSize ()
 Returns the maximum size the queue is allowed to grow to. More...
 
int getNumThreads ()
 Returns the number of threads the ConnectionWriter has been created with. More...
 
bool getRawMode ()
 Returns the current setting of the raw mode flag. More...
 
int getTcpHeaderSize ()
 Returns the current setting of TCP header size. More...
 
bool isImmediate ()
 Returns true if the writer is an immediate writer, i.e. More...
 
bool isValidForUdp (const Datagram datagram)
 Returns true if the datagram is small enough to be sent over a UDP packet, false otherwise. More...
 
bool send (const Datagram datagram, Connection connection, const NetAddress address, bool block)
 Enqueues a datagram for transmittal on the indicated socket. More...
 
bool send (const Datagram datagram, Connection connection, bool block)
 Enqueues a datagram for transmittal on the indicated socket. More...
 
 setMaxQueueSize (int max_size)
 Limits the number of packets that may be pending on the outbound queue. More...
 
 setRawMode (bool mode)
 Sets the ConnectionWriter into raw mode (or turns off raw mode). More...
 
 setTcpHeaderSize (int tcp_header_size)
 Sets the header size of TCP packets. More...
 
 shutdown ()
 Stops all the threads and cleans them up. More...
 

Detailed Description

This class handles threaded delivery of datagrams to various TCP or UDP sockets.

A ConnectionWriter may define an arbitrary number of threads (0 or more) to write its datagrams to sockets. The number of threads is specified at construction time and cannot be changed.

Member Function Documentation

◆ __init__()

__init__ ( ConnectionManager  manager,
int  num_threads,
str  thread_name 
)

Creates a new ConnectionWriter with the indicated number of threads to handle output.

If num_threads is 0, all datagrams will be sent immediately instead of queueing for later transmission by a thread.

◆ getCurrentQueueSize()

int getCurrentQueueSize ( )

Returns the current number of things in the queue.

◆ getManager()

ConnectionManager getManager ( )

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

◆ getMaxQueueSize()

int getMaxQueueSize ( )

Returns the maximum size the queue is allowed to grow to.

See set_max_queue_size().

◆ getNumThreads()

int getNumThreads ( )

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

◆ getRawMode()

bool getRawMode ( )

Returns the current setting of the raw mode flag.

See set_raw_mode().

◆ getTcpHeaderSize()

int getTcpHeaderSize ( )

Returns the current setting of TCP header size.

See set_tcp_header_size().

◆ isImmediate()

bool isImmediate ( )

Returns true if the writer is an immediate writer, i.e.

it has no threads.

◆ isValidForUdp()

bool isValidForUdp ( const Datagram  datagram)

Returns true if the datagram is small enough to be sent over a UDP packet, false otherwise.

◆ send() [1/2]

bool send ( const Datagram  datagram,
Connection  connection,
const NetAddress  address,
bool  block 
)

Enqueues a datagram for transmittal on the indicated socket.

This form of the function allows the specification of a destination host address, and so is appropriate for UDP packets. Use the other send() method for sending TCP packets.

Returns true if successful, false if there was an error. In the normal, threaded case, this function only returns false if the send queue is filled; it's impossible to detect a transmission error at this point.

If block is true, this will not return false if the send queue is filled; instead, it will wait until there is space available.

◆ send() [2/2]

bool send ( const Datagram  datagram,
Connection  connection,
bool  block 
)

Enqueues a datagram for transmittal on the indicated socket.

Since the host address is not specified with this form, this function should only be used for sending TCP packets. Use the other send() method for sending UDP packets.

Returns true if successful, false if there was an error. In the normal, threaded case, this function only returns false if the send queue is filled; it's impossible to detect a transmission error at this point.

If block is true, this will not return false if the send queue is filled; instead, it will wait until there is space available.

◆ setMaxQueueSize()

setMaxQueueSize ( int  max_size)

Limits the number of packets that may be pending on the outbound queue.

This only has an effect when using threads; if num_threads is 0, then all packets are sent immediately.

◆ setRawMode()

setRawMode ( bool  mode)

Sets the ConnectionWriter into raw mode (or turns off raw mode).

In raw mode, datagrams are not sent along with their headers; the bytes in the datagram are simply sent down the pipe.

Setting the ConnectionWriter to raw mode must be done with care. This can only be done when the matching ConnectionReader is also set to raw mode, or when the ConnectionWriter is communicating to a process that does not expect datagrams.

◆ setTcpHeaderSize()

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

◆ shutdown()

shutdown ( )

Stops all the threads and cleans them up.

This is called automatically by the destructor, but it may be called explicitly before destruction.