#include <sue_sess.hpp>
Inheritance diagram for SUEGenericDuplexSession:
Public Methods | |
SUEGenericDuplexSession (int a_timeout=0, const char *a_greeting=0) | |
Constructor. | |
virtual | ~SUEGenericDuplexSession () |
Destructor. | |
void | SetTimeout (int sec, int usec=0) |
Set timeout. | |
void | Startup (SUEEventSelector *a_selector, int a_fd, const char *a_greeting=0) |
Start the session. | |
void | Shutdown () |
Shut the session down. | |
void | GracefulShutdown () |
graceful shutdown | |
virtual void | HandleNewInput ()=0 |
Hook for handling new input. | |
virtual void | ShutdownHook () |
Overridable shutdown hook. | |
virtual void | HandleSessionTimeout () |
Hook for handling session timeout. | |
virtual void | HandleReadError () |
Hook for handling read error. | |
virtual void | HandleWriteError () |
Hook for handling write error. | |
virtual void | HandleRemoteClosing () |
Hook for handling session end by remote. | |
Protected Methods | |
virtual void | FdHandle (bool a_r, bool a_w, bool a_ex) |
callback function for file descriptor events | |
virtual void | TimeoutHandle () |
callback function for timeouts | |
virtual bool | WantRead () const |
virtual bool | WantWrite () const |
virtual bool | WantExcept () const |
Protected Attributes | |
SUEEventSelector * | the_selector |
Pointer to the SUEEventSelector object used here. | |
SUEBuffer | inputbuffer |
Reading queue. | |
SUEBuffer | outputbuffer |
Writing queue. | |
bool | inputresetstimeout |
Does the received input reset timeout. | |
bool | outputresetstimeout |
Does the performed output reset timeout. |
This class provides an abstract hope-to-be-generic duplex connection via a single file descriptor (e.g., a duplex socket). The class is capable of timing out the session.
All the input/output is made asynchronously and is hidden from the user. You just operate with two protected fields named inputbuffer and outputbuffer. They are both of type SUEBuffer. Chars read from the file descriptor are appended to the end of the inputbuffer. Chars in the outputbuffer are considered as chars to be sent to through the file descriptor.
You must create a child class of this and the child must override at least the HandleNewInput() and HandleRemoteClosing() methods. You might want to override ShutdownHook(), HandleSessionTimeout() and/or HandleReadError() as well.
Use Startup(), Shutdown() and GracefulShutdown() to control the session.
|
Constructor.
|
|
Destructor.
|
|
callback function for file descriptor events This function overrides SUEFdHandler::FdHandle(). It then performs read(2) on the socket and then calls the appropriate method depending on the results.
Implements SUEFdHandler. |
|
graceful shutdown Schedule shutdown of the session to the moment when output queue get empty. |
|
Hook for handling new input. This function is called whenever new data is read from the session channel (that is, select(2) told us there is possibility to read, and read(2) got more than zero chars from the session's file descriptor). All the chars are appended to the inputbuffer before this function is called. Implemented in SUETcpClientSession, and SUETcpServerSession. |
|
Hook for handling read error. This function is called when read(2) returns negative value. By default, it calls Shutdown(). Override this method if you need different behaviour (you do need it, don't you?) |
|
Hook for handling session end by remote. This function is called by the library in case select(2) tells the FD may be read and then read(2) returns 0 bytes. For sockets, it means the remote end has just closed connection.
|
|
Hook for handling session timeout. This function is called when the session is timed out. By default, it calls Shutdown(). Override this method if you need different behaviour (you do need it, don't you?)
|
|
Hook for handling write error. This function is called when write(2) returns negative value. By default, it calls Shutdown(). Override this method if you need different behaviour (you do need it, don't you?) |
|
Set timeout.
|
|
Shut the session down. Calling Shutdown() from within your handlers is the right way to end the session. This function unregisters all handlers at the selector and closes the file descriptor. After that, it calls ShutdownHook() method which can be overriden in a child class.
|
|
Overridable shutdown hook. Sometimes we need to notify someone the session's dead. This function is called by Shutdown() method after all the necessary steps of shutting down are done. By default it does nothing, but that can be overriden. You can even delete your object from within this method, it is safe unless you use deletion to initiate the shutdown.
|
|
Start the session. This method sets the file descriptor and registers the handlers at the selector.
Reimplemented in SUEInetDuplexSession. |
|
callback function for timeouts
Implements SUETimeoutHandler. |
|
In the current version, we don't expect nor handle exceptions Reimplemented from SUEFdHandler. |
|
We're always ready to read everything they sent us Reimplemented from SUEFdHandler. |
|
Sometimes (when the output queue is not empty) we need to know when to write. Reimplemented from SUEFdHandler. |
|
Reading queue.
|
|
Does the received input reset timeout.
|
|
Writing queue.
|
|
Does the performed output reset timeout.
|
|
Pointer to the SUEEventSelector object used here.
|