#include <sue_tcpc.hpp>
Inheritance diagram for SUETcpClientSession:
Public Methods | |
const char * | InspectAddr () const |
int | InspectPort () const |
const char * | InspectLocalAddr () const |
int | InspectLocalPort () const |
SUETcpClientSession (const char *ipaddr, int ipport, int timeout, const char *greeting=0, const char *local_ip=0, int localport=0) | |
Constructor. | |
virtual | ~SUETcpClientSession () |
Destructor. | |
bool | Up (SUEEventSelector *a_selector) |
Actually start the session. | |
bool | Up (SUEEventSelector *a_selector, const char *src_ipaddr, int src_port) |
Start the session performing connect from the given address. | |
void | Down () |
Shuts the session down. | |
virtual void | HandleConnectionFailure () |
What to do if connection attempt failed. | |
virtual void | HandleNewInput ()=0 |
Hook for handling new input. |
This class deals with a client TCP session. You create your own class to represent whatever protocol you need. It is done in methods HandleNewInput() and HandleSessionTerminatingEvent() (see the UPPGenericDuplexSession class description for details on implementing a session object).
Having the class, you first create an object as appropriate, and then start your session by calling Up() method. Your handling methods may instruct other objects to write something to the session whenever they need (that is done using WriteChars() method). The session may be shut down any time using Down() method (the preferred way). If you need to notify someone the session's dead, override the ShutdownHook() method. In case you do, be sure to call Down() or Shutdown() from your destructor, or else the session will shut down during destruction of the base class so wrong version of ShutdownHook() is called. Yes, it IS safe to call Down() for already-shuted session. ShutdownHook() is called only once, when the session is actually shot.
|
Constructor.
|
|
Destructor.
|
|
Shuts the session down. The preferred method to shut the session down. |
|
What to do if connection attempt failed. This function is called when, after connect(2) had been called, select(2) indicated writability while getsockopt(2) indicated the connection wasn't successfull. By other words, the session is considered 'up' (because Up() returned true), but after that, it couldn't connect to the destination. By default, the function calls Shutdown() just like all the similar methods like HandleSessionTimeout() etc, but you can override it to customize this. |
|
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. Implements SUEGenericDuplexSession.
|
|
|
|
|
|
|
|
|
|
Start the session performing connect from the given address. This version of the method calls socket(2), then bind(2), then connect(2), so that the connection is made from the given address. |
|
Actually start the session. The method calls socket(2), then tries to connect(2) to the desired destination. In case of success, registers the session and the timeout at the selector and returns true. In case socket(2) or connect(2) fails, immediately returns false
|