NewNet::Reactor Class Reference

Monitors sockets and timeouts. This is what drives your application. More...

#include <nnreactor.h>

Inheritance diagram for NewNet::Reactor:

NewNet::Object List of all members.

Public Types

typedef Event< long > Timeout
 Convenience definition for timeouts.

Public Member Functions

 Reactor ()
 Constructor.
void add (Socket *socket)
 Add a socket to the reactor.
void remove (Socket *socket)
 Remove a socket from the reactor.
void run ()
 Start the main loop.
void stop ()
 Stop the main loop.
Timeout::CallbackaddTimeout (long msec, Timeout::Callback *callback)
 Add a new timeout to the reactor.
template<class ObjectType, typename MethodType>
Timeout::CallbackaddTimeout (long msec, ObjectType *object, MethodType method)
 Add a new timeout to the reactor.

Detailed Description

The Reactor class provides your application with a main-loop. It monitors the sockets and waits for timeouts to occur.

Definition at line 34 of file nnreactor.h.


Member Typedef Documentation

typedef Event<long> NewNet::Reactor::Timeout

A convenience definition for timeout callback. Note: Timeouts aren't actually used as events, bu the Event::Callback class is used to define the callback for a timeout.

Definition at line 73 of file nnreactor.h.


Constructor & Destructor Documentation

NewNet::Reactor::Reactor (  ) 

Create a new reactor

Definition at line 107 of file nnreactor.cpp.


Member Function Documentation

void NewNet::Reactor::add ( Socket socket  ) 

Add a socket to the reactor's watch list so that the socket will be able to receive and process events. Note: stores a RefPtr to the socket object

Definition at line 119 of file nnreactor.cpp.

References NewNet::Socket::reactor(), and NewNet::Socket::setReactor().

void NewNet::Reactor::remove ( Socket socket  ) 

Remove a socket from the reactor's watch list. Note: The reactor stores a RefPtr to the socket, if the reactor holds the last reference to the socket, it will get deleted automatically.

Definition at line 137 of file nnreactor.cpp.

References NewNet::Socket::reactor(), and NewNet::Socket::setReactor().

void NewNet::Reactor::run (  ) 

Call this to start the reactor's main loop. The reactor will start listening for events and waiting for timeouts to happen. This method will not return until there are no sockets and timeouts left, or when Reactor::stop() is called.

Definition at line 146 of file nnreactor.cpp.

References NewNet::Socket::SocketConnected, NewNet::Socket::SocketConnecting, NewNet::Socket::SocketDisconnected, NewNet::Socket::SocketDisconnecting, NewNet::Socket::SocketException, NewNet::Socket::SocketListening, NewNet::Socket::SocketUninitialized, NewNet::Socket::StateException, NewNet::Socket::StateReceive, and NewNet::Socket::StateSend.

void NewNet::Reactor::stop (  ) 

Call this to exit the reactor's main loop. Note that the reactor will first process any pending events before exiting.

Definition at line 323 of file nnreactor.cpp.

NewNet::Reactor::Timeout::Callback * NewNet::Reactor::addTimeout ( long  msec,
Timeout::Callback callback 
)

Add a new timeout callback to the reactor so that the callback will be invoked after approximately msec miliseconds. Note: stores a RefPtr to the callback object.

Definition at line 329 of file nnreactor.cpp.

Referenced by addTimeout().

template<class ObjectType, typename MethodType>
Timeout::Callback* NewNet::Reactor::addTimeout ( long  msec,
ObjectType *  object,
MethodType  method 
) [inline]

Add a new timeout callback to the reactor so that the method of the specified object will be invoked after approximately msec miliseconds. Note: stores a RefPtr to the generated callback object.

Definition at line 86 of file nnreactor.h.

References addTimeout(), and NewNet::Event< T >::bind().


The documentation for this class was generated from the following files:
Generated on Sun Jan 7 14:00:02 2007 for NewNet by  doxygen 1.5.1