Panda3D
|
This class accepts datagrams one-at-a-time and sends them over the net, via a TCP connection. More...
#include "datagramSinkNet.h"
Public Member Functions | |
DatagramSinkNet (ConnectionManager *manager, int num_threads) | |
Creates a new DatagramSinkNet with the indicated number of threads to handle writing. | |
virtual void | flush () |
Ensures that all datagrams previously written will be visible on the stream. | |
int | get_current_queue_size () const |
Returns the current number of things in the queue. | |
ConnectionManager * | get_manager () const |
Returns a pointer to the ConnectionManager object that serves this ConnectionWriter. | |
int | get_max_queue_size () const |
Returns the maximum size the queue is allowed to grow to. | |
int | get_num_threads () const |
Returns the number of threads the ConnectionWriter has been created with. | |
bool | get_raw_mode () const |
Returns the current setting of the raw mode flag. | |
Connection * | get_target () const |
Returns the current target Connection, or NULL if the target has not yet been set. | |
int | get_tcp_header_size () const |
Returns the current setting of TCP header size. | |
virtual bool | is_error () |
Returns true if there is an error on the target connection, or if the target has never been set. | |
bool | is_immediate () const |
Returns true if the writer is an immediate writer, i.e. | |
bool | is_valid_for_udp (const Datagram &datagram) const |
Returns true if the datagram is small enough to be sent over a UDP packet, false otherwise. | |
virtual bool | put_datagram (const Datagram &data) |
Sends the given datagram to the target. | |
bool | send (const Datagram &datagram, const PT(Connection)&connection, bool block=false) |
Enqueues a datagram for transmittal on the indicated socket. | |
bool | send (const Datagram &datagram, const PT(Connection)&connection, const NetAddress &address, bool block=false) |
Enqueues a datagram for transmittal on the indicated socket. | |
void | set_max_queue_size (int max_size) |
Limits the number of packets that may be pending on the outbound queue. | |
void | set_raw_mode (bool mode) |
Sets the ConnectionWriter into raw mode (or turns off raw mode). | |
void | set_target (Connection *connection) |
Specifies the Connection that will receive all future Datagrams sent. | |
void | set_tcp_header_size (int tcp_header_size) |
Sets the header size of TCP packets. | |
void | shutdown () |
Stops all the threads and cleans them up. | |
Protected Member Functions | |
void | clear_manager () |
This should normally only be called when the associated ConnectionManager destructs. | |
Protected Attributes | |
ConnectionManager * | _manager |
This class accepts datagrams one-at-a-time and sends them over the net, via a TCP connection.
Definition at line 28 of file datagramSinkNet.h.
DatagramSinkNet::DatagramSinkNet | ( | ConnectionManager * | manager, |
int | num_threads | ||
) |
Creates a new DatagramSinkNet with the indicated number of threads to handle writing.
Normally num_threads should be either 0 or 1 to guarantee that datagrams are delivered in the same order in which they were sent.
Definition at line 29 of file datagramSinkNet.cxx.
void ConnectionWriter::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 ConnectionWriter invalid; presumably it also will be destructed momentarily.
Definition at line 371 of file connectionWriter.cxx.
References ConnectionWriter::shutdown().
void DatagramSinkNet::flush | ( | void | ) | [virtual] |
Ensures that all datagrams previously written will be visible on the stream.
Implements DatagramSink.
Definition at line 67 of file datagramSinkNet.cxx.
int ConnectionWriter::get_current_queue_size | ( | ) | const [inherited] |
Returns the current number of things in the queue.
Definition at line 141 of file connectionWriter.cxx.
References DatagramQueue::get_current_queue_size().
ConnectionManager * ConnectionWriter::get_manager | ( | ) | const [inherited] |
Returns a pointer to the ConnectionManager object that serves this ConnectionWriter.
Definition at line 253 of file connectionWriter.cxx.
int ConnectionWriter::get_max_queue_size | ( | ) | const [inherited] |
Returns the maximum size the queue is allowed to grow to.
See set_max_queue_size().
Definition at line 131 of file connectionWriter.cxx.
References DatagramQueue::get_max_queue_size().
int ConnectionWriter::get_num_threads | ( | ) | const [inherited] |
Returns the number of threads the ConnectionWriter has been created with.
Definition at line 275 of file connectionWriter.cxx.
bool ConnectionWriter::get_raw_mode | ( | ) | const [inherited] |
Returns the current setting of the raw mode flag.
See set_raw_mode().
Definition at line 305 of file connectionWriter.cxx.
Connection * DatagramSinkNet::get_target | ( | ) | const [inline] |
Returns the current target Connection, or NULL if the target has not yet been set.
See set_target().
Definition at line 34 of file datagramSinkNet.I.
int ConnectionWriter::get_tcp_header_size | ( | ) | const [inherited] |
Returns the current setting of TCP header size.
Definition at line 330 of file connectionWriter.cxx.
bool DatagramSinkNet::is_error | ( | ) | [virtual] |
Returns true if there is an error on the target connection, or if the target has never been set.
Implements DatagramSink.
Definition at line 56 of file datagramSinkNet.cxx.
bool ConnectionWriter::is_immediate | ( | ) | const [inherited] |
Returns true if the writer is an immediate writer, i.e.
it has no threads.
Definition at line 264 of file connectionWriter.cxx.
bool ConnectionWriter::is_valid_for_udp | ( | const Datagram & | datagram | ) | const [inherited] |
Returns true if the datagram is small enough to be sent over a UDP packet, false otherwise.
Definition at line 242 of file connectionWriter.cxx.
References Datagram::get_length().
bool DatagramSinkNet::put_datagram | ( | const Datagram & | data | ) | [virtual] |
Sends the given datagram to the target.
Returns true on success, false if there is an error. Blocks if necessary until the target is ready.
Implements DatagramSink.
Definition at line 42 of file datagramSinkNet.cxx.
References ConnectionWriter::send().
bool ConnectionWriter::send | ( | const Datagram & | datagram, |
const PT(Connection)& | connection, | ||
const NetAddress & | address, | ||
bool | block = false |
||
) | [inherited] |
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.
Definition at line 206 of file connectionWriter.cxx.
References Datagram::get_length(), Connection::get_socket(), DatagramQueue::insert(), TypedObject::is_exact_type(), NetDatagram::set_address(), and NetDatagram::set_connection().
bool ConnectionWriter::send | ( | const Datagram & | datagram, |
const PT(Connection)& | connection, | ||
bool | block = false |
||
) | [inherited] |
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.
Definition at line 166 of file connectionWriter.cxx.
References Connection::get_socket(), DatagramQueue::insert(), and TypedObject::is_exact_type().
Referenced by put_datagram().
void ConnectionWriter::set_max_queue_size | ( | int | max_size | ) | [inherited] |
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.
Definition at line 120 of file connectionWriter.cxx.
References DatagramQueue::set_max_queue_size().
void ConnectionWriter::set_raw_mode | ( | bool | mode | ) | [inherited] |
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.
Definition at line 294 of file connectionWriter.cxx.
void DatagramSinkNet::set_target | ( | Connection * | connection | ) | [inline] |
Specifies the Connection that will receive all future Datagrams sent.
Definition at line 23 of file datagramSinkNet.I.
void ConnectionWriter::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 319 of file connectionWriter.cxx.
void ConnectionWriter::shutdown | ( | ) | [inherited] |
Stops all the threads and cleans them up.
This is called automatically by the destructor, but it may be called explicitly before destruction.
Definition at line 342 of file connectionWriter.cxx.
References DatagramQueue::shutdown().
Referenced by ConnectionWriter::clear_manager().