#include <connectionReader.h>
Inheritance diagram for ConnectionReader:
Public Member Functions | |
ConnectionReader (ConnectionManager *manager, int num_threads) | |
Creates a new ConnectionReader with the indicated number of threads to handle requests. | |
virtual | ~ConnectionReader () |
bool | add_connection (const PointerTo< Connection > &connection) |
Adds a new socket to the list of sockets the ConnectionReader will monitor. | |
bool | remove_connection (const PointerTo< Connection > &connection) |
Removes a socket from the list of sockets being monitored. | |
bool | is_connection_ok (const PointerTo< 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. | |
void | poll () |
Explicitly polls the available sockets to see if any of them have any noise. | |
ConnectionManager * | get_manager () const |
Returns a pointer to the ConnectionManager object that serves this ConnectionReader. | |
bool | is_polling () const |
Returns true if the reader is a polling reader, i.e. | |
int | get_num_threads () const |
Returns the number of threads the ConnectionReader has been created with. | |
void | set_raw_mode (bool mode) |
Sets the ConnectionReader 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 | |
virtual void | receive_datagram (const NetDatagram &datagram)=0 |
void | shutdown () |
Terminates all threads cleanly. | |
void | clear_manager () |
This should normally only be called when the associated ConnectionManager destructs. | |
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 | process_incoming_data (SocketInfo *sinfo) |
This is run within a thread when the call to PR_Poll() indicates there is data available on a socket. | |
virtual void | process_incoming_udp_data (SocketInfo *sinfo) |
virtual void | process_incoming_tcp_data (SocketInfo *sinfo) |
virtual void | process_raw_incoming_udp_data (SocketInfo *sinfo) |
virtual void | process_raw_incoming_tcp_data (SocketInfo *sinfo) |
Protected Attributes | |
ConnectionManager * | _manager |
Private Types | |
typedef pvector< PRThread * > | Threads |
typedef pvector< PRPollDesc > | Poll |
typedef pvector< SocketInfo * > | Sockets |
Private Member Functions | |
void | thread_run () |
This is the actual executing function for each thread. | |
SocketInfo * | get_next_available_socket (PRIntervalTime timeout, PRInt32 current_thread_index) |
Polls the known connections for activity and returns the next one known to have activity, or NULL if no activity is detected within the timeout interval. | |
void | rebuild_poll_list () |
Rebuilds the _poll and _polled_sockets arrays based on the sockets that are currently available for polling. | |
Static Private Member Functions | |
void | thread_start (void *data) |
The static wrapper around the thread's executing function. | |
Private Attributes | |
bool | _raw_mode |
bool | _shutdown |
Threads | _threads |
PRLock * | _startup_mutex |
bool | _polling |
Poll | _poll |
Sockets | _polled_sockets |
int | _next_index |
int | _num_results |
PRLock * | _select_mutex |
PRInt32 | _currently_polling_thread |
Sockets | _sockets |
Sockets | _removed_sockets |
bool | _reexamine_sockets |
PRLock * | _sockets_mutex |
Friends | |
class | ConnectionManager |
A ConnectionReader may define an arbitrary number of threads (at least one) to process datagrams coming in from an arbitrary number of sockets that it is monitoring. The number of threads is specified at construction time and cannot be changed, but the set of sockets that is to be monitored may be constantly modified at will.
This is an abstract class because it doesn't define how to process each received datagram. See QueuedConnectionReader. Also note that ConnectionListener derives from this class, extending it to accept connections on a rendezvous socket rather than read datagrams.
Definition at line 83 of file connectionReader.h.
|
Definition at line 159 of file connectionReader.h. |
|
Definition at line 160 of file connectionReader.h. |
|
Definition at line 152 of file connectionReader.h. |
|
Creates a new ConnectionReader with the indicated number of threads to handle requests. If num_threads is 0, the sockets will only be read by polling, during an explicit poll() call. (QueuedConnectionReader will do this automatically.) Definition at line 97 of file connectionReader.cxx. |
|
Definition at line 146 of file connectionReader.cxx. |
|
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 210 of file connectionReader.cxx. References _reexamine_sockets, _removed_sockets, _sockets, and _sockets_mutex. |
|
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 487 of file connectionReader.cxx. |
|
To be called when a socket has been fully read and is ready for polling for additional data.
Definition at line 502 of file connectionReader.cxx. |
|
Returns a pointer to the ConnectionManager object that serves this ConnectionReader.
Definition at line 364 of file connectionReader.cxx. References _threads. |
|
Polls the known connections for activity and returns the next one known to have activity, or NULL if no activity is detected within the timeout interval. This function may block indefinitely if it is being called by multiple threads; if there are no other threads, it may block only if timeout != PR_INTERVAL_NO_WAIT. Definition at line 967 of file connectionReader.cxx. References _polled_sockets. |
|
Returns the number of threads the ConnectionReader has been created with.
Definition at line 394 of file connectionReader.cxx. |
|
Returns the current setting of the raw mode flag. See set_raw_mode(). Definition at line 428 of file connectionReader.cxx. |
|
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 296 of file connectionReader.cxx. References _manager. |
|
Returns true if the reader is a polling reader, i.e. it has no threads. Definition at line 379 of file connectionReader.cxx. |
|
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 342 of file connectionReader.cxx. References _raw_mode. Referenced by QueuedConnectionListener::~QueuedConnectionListener(). |
|
This is run within a thread when the call to PR_Poll() indicates there is data available on a socket.
Reimplemented in ConnectionListener. Definition at line 543 of file connectionReader.cxx. References _manager, ConnectionManager::connection_reset(), NULL, and pprerror(). |
|
Definition at line 640 of file connectionReader.cxx. |
|
Definition at line 567 of file connectionReader.cxx. |
|
Definition at line 839 of file connectionReader.cxx. References _next_index, _num_results, _poll, _polled_sockets, _reexamine_sockets, _shutdown, and NULL. |
|
Definition at line 785 of file connectionReader.cxx. |
|
Rebuilds the _poll and _polled_sockets arrays based on the sockets that are currently available for polling.
Definition at line 1089 of file connectionReader.cxx. |
|
Implemented in ConnectionListener, QueuedConnectionReader, and RecentConnectionReader. |
|
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 253 of file connectionReader.cxx. |
|
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. Definition at line 413 of file connectionReader.cxx. Referenced by HTTPClient::HTTPClient(). |
|
Terminates all threads cleanly. Normally this is only called by the destructor. Definition at line 443 of file connectionReader.cxx. Referenced by QueuedConnectionListener::QueuedConnectionListener(). |
|
This is the actual executing function for each thread.
Definition at line 919 of file connectionReader.cxx. |
|
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 904 of file connectionReader.cxx. |
|
Definition at line 187 of file connectionReader.h. |
|
Definition at line 172 of file connectionReader.h. |
|
Definition at line 146 of file connectionReader.h. Referenced by ConnectionReader::SocketInfo::get_socket(), is_connection_ok(), process_incoming_data(), and ConnectionListener::process_incoming_data(). |
|
Definition at line 163 of file connectionReader.h. Referenced by process_raw_incoming_tcp_data(). |
|
Definition at line 164 of file connectionReader.h. Referenced by process_raw_incoming_tcp_data(). |
|
Definition at line 161 of file connectionReader.h. Referenced by process_raw_incoming_tcp_data(). |
|
Definition at line 162 of file connectionReader.h. Referenced by get_next_available_socket(), and process_raw_incoming_tcp_data(). |
|
Definition at line 155 of file connectionReader.h. |
|
Definition at line 149 of file connectionReader.h. Referenced by poll(). |
|
Definition at line 182 of file connectionReader.h. Referenced by add_connection(), and process_raw_incoming_tcp_data(). |
|
Definition at line 179 of file connectionReader.h. Referenced by add_connection(). |
|
Definition at line 167 of file connectionReader.h. |
|
Definition at line 150 of file connectionReader.h. Referenced by process_raw_incoming_tcp_data(). |
|
Definition at line 176 of file connectionReader.h. Referenced by add_connection(). |
|
Definition at line 184 of file connectionReader.h. Referenced by add_connection(). |
|
Definition at line 154 of file connectionReader.h. |
|
Definition at line 153 of file connectionReader.h. Referenced by ConnectionWriter::ConnectionWriter(), and get_manager(). |