Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

ConnectionWriter Class Reference

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

#include <connectionWriter.h>

List of all members.

Public Member Functions

 ConnectionWriter (ConnectionManager *manager, int num_threads)
 Creates a new ConnectionWriter with the indicated number of threads to handle output.

 ~ConnectionWriter ()
bool send (const Datagram &datagram, const PointerTo< Connection > &connection)
 Enqueues a datagram for transmittal on the indicated socket.

bool send (const Datagram &datagram, const PointerTo< Connection > &connection, const NetAddress &address)
 Enqueues a datagram for transmittal on the indicated socket.

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.

ConnectionManagerget_manager () const
 Returns a pointer to the ConnectionManager object that serves this ConnectionWriter.

bool is_immediate () const
 Returns true if the writer is an immediate writer, i.e.

int get_num_threads () const
 Returns the number of threads the ConnectionWriter has been created with.

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

bool get_raw_mode () const
 Returns the current setting of the raw mode flag.


Protected Member Functions

void clear_manager ()
 This should normally only be called when the associated ConnectionManager destructs.


Protected Attributes

ConnectionManager_manager

Private Types

typedef pvector< PRThread * > Threads

Private Member Functions

void thread_run ()
 This is the actual executing function for each thread.

bool send_datagram (const NetDatagram &datagram)

Static Private Member Functions

void thread_start (void *data)
 The static wrapper around the thread's executing function.


Private Attributes

bool _raw_mode
DatagramQueue _queue
Threads _threads
bool _immediate

Friends

class ConnectionManager


Detailed Description

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

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

Definition at line 57 of file connectionWriter.h.


Member Typedef Documentation

typedef pvector<PRThread *> ConnectionWriter::Threads [private]
 

Definition at line 93 of file connectionWriter.h.


Constructor & Destructor Documentation

ConnectionWriter::ConnectionWriter ConnectionManager manager,
int  num_threads
 

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.

Definition at line 49 of file connectionWriter.cxx.

References ConnectionReader::_threads.

ConnectionWriter::~ConnectionWriter  ) 
 

Definition at line 79 of file connectionWriter.cxx.


Member Function Documentation

void ConnectionWriter::clear_manager  )  [protected]
 

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 336 of file connectionWriter.cxx.

ConnectionManager * ConnectionWriter::get_manager  )  const
 

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

Definition at line 237 of file connectionWriter.cxx.

References _raw_mode.

int ConnectionWriter::get_num_threads  )  const
 

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

Definition at line 267 of file connectionWriter.cxx.

bool ConnectionWriter::get_raw_mode  )  const
 

Returns the current setting of the raw mode flag.

See set_raw_mode().

Definition at line 313 of file connectionWriter.cxx.

bool ConnectionWriter::is_immediate  )  const
 

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

it has no threads.

Definition at line 252 of file connectionWriter.cxx.

References _manager, and NULL.

bool ConnectionWriter::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.

Definition at line 222 of file connectionWriter.cxx.

References _raw_mode.

bool ConnectionWriter::send const Datagram datagram,
const PointerTo< Connection > &  connection,
const NetAddress address
 

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.

Definition at line 182 of file connectionWriter.cxx.

References _manager.

bool ConnectionWriter::send const Datagram datagram,
const PointerTo< Connection > &  connection
 

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.

Definition at line 134 of file connectionWriter.cxx.

References _queue, Datagram::get_length(), Connection::get_socket(), DatagramQueue::insert(), nassertr, NULL, Connection::send_datagram(), Connection::send_raw_datagram(), NetDatagram::set_address(), and NetDatagram::set_connection().

bool ConnectionWriter::send_datagram const NetDatagram datagram  )  [private]
 

void ConnectionWriter::set_raw_mode 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.

Definition at line 298 of file connectionWriter.cxx.

Referenced by HTTPClient::HTTPClient().

void ConnectionWriter::thread_run  )  [private]
 

This is the actual executing function for each thread.

Definition at line 370 of file connectionWriter.cxx.

void ConnectionWriter::thread_start void *  data  )  [static, private]
 

The static wrapper around the thread's executing function.

This must be a static member function because it is passed through the C interface to PR_CreateThread().

Definition at line 355 of file connectionWriter.cxx.


Friends And Related Function Documentation

friend class ConnectionManager [friend]
 

Definition at line 97 of file connectionWriter.h.


Member Data Documentation

bool ConnectionWriter::_immediate [private]
 

Definition at line 95 of file connectionWriter.h.

ConnectionManager* ConnectionWriter::_manager [protected]
 

Definition at line 87 of file connectionWriter.h.

Referenced by is_immediate(), and send().

DatagramQueue ConnectionWriter::_queue [private]
 

Definition at line 91 of file connectionWriter.h.

Referenced by send().

bool ConnectionWriter::_raw_mode [private]
 

Definition at line 90 of file connectionWriter.h.

Referenced by get_manager(), and is_valid_for_udp().

Threads ConnectionWriter::_threads [private]
 

Definition at line 94 of file connectionWriter.h.


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:48:49 2003 for Panda by doxygen1.3