SocketReactorDescription and design of the socket reactor interface. The SocketReactor is a low level event dispatching scheme to use together with sockets. For more information on the reactor pattern. See Pattern Oriented Software Architecture by Schmidt et al. (see http://www.cs.wustl.edu/~schmidt/POSA/) event_mask { read = 1 << 0, connect = 1 << 0, // select cant't detect difference between readability and connection write = 1 << 1, accept= 1 << 1, // select cant't detect difference between writeability and accept error = 1 << 2 }; // attach SocketBase to this reactor should we take socket_t instead? // throw if socket already attached? or replace callback void attach(SocketBase& socket, boost::function<void (SocketBase& socket, event_mask)> callback, event_mask mask); // detach SocketBase from this reactor void detach(SocketBase& socket); // add a timer callback (returning a new duration when to fire again or duration = 0 if not to fire again) bool set_timer(time_duration_t fireTime, boost::function<time_duration_t ()>); // dispatch an event returns true if event is dispatched and false on timeout. bool dispatch(time_duration_t duration); Do we need to close a reactor and can these operations be implemented safely. // perform asynchrounous close. void close(); // join this reactor and wait for close to finish void join(); How should destruction be handled and defined? |
Description and design of the socket reactor interface.
The SocketReactor is a low level event dispatching scheme to use together with sockets.
For more information on the reactor pattern. See Pattern Oriented Software Architecture by Schmidt et al. (see http://www.cs.wustl.edu/~schmidt/POSA/)
event_mask { read = 1 << 0, connect = 1 << 0, // select cant't detect difference between readability and connection write = 1 << 1, accept= 1 << 1, // select cant't detect difference between writeability and accept error = 1 << 2 };
// attach SocketBase to this reactor should we take socket_t instead? // throw if socket already attached? or replace callback void attach(SocketBase& socket, boost::function<void (SocketBase& socket, event_mask)> callback, event_mask mask); // detach SocketBase from this reactor void detach(SocketBase& socket);
// add a timer callback (returning a new duration when to fire again or duration = 0 if not to fire again) bool set_timer(time_duration_t fireTime, boost::function<time_duration_t ()>); // dispatch an event returns true if event is dispatched and false on timeout. bool dispatch(time_duration_t duration);
Do we need to close a reactor and can these operations be implemented safely.
// perform asynchrounous close. void close(); // join this reactor and wait for close to finish void join();
How should destruction be handled and defined?