#include <sue_tcps.hpp>
Inheritance diagram for SUETcpServer:
Public Methods | |
SUETcpServer (const char *a_ip, int a_port) | |
Constructor. | |
virtual | ~SUETcpServer () |
Destructor. | |
bool | Up (SUEEventSelector *a_selector) |
Bring the server up. | |
void | Down () |
Shut the server down. | |
unsigned long | GetIpOfLastAccepted () const |
Get the ip address of the last accepted session. | |
void | NotifySessionDown (SUETcpServerSession *sess) |
Session got down, kill its object. | |
Protected Methods | |
virtual SUETcpServerSession * | SpawnSession (int newsessionfd)=0 |
Method to create a custom SUETcpServerSession object. | |
Protected Attributes | |
SUEEventSelector * | selector |
The Selector to use. |
This class implements a generic multiuser TCP server. It is inherited from SUEFdHandler because it has the descriptor for listening socket and handles its events. In order to create your own server, do the following:
|
Constructor. The constructor. Parameters are:
|
|
Destructor.
|
|
Shut the server down. This method removes the object from Selector, closes the listening socket and shuts down all active tcp sessions created by the server. |
|
Get the ip address of the last accepted session.
|
|
Session got down, kill its object. This method is called by the SUETcpServerSession object when the session gets down. The method removes the Session object from the list of sessions and destroys the Session object calling delete sess;
|
|
Method to create a custom SUETcpServerSession object. This method is called when a new request is accepted. It just creates an object of a subclass of SUETcpServerSession and returns a pointer to it. Override this method to create and return YOUR SUETcpServerSession object. For example, SUETcpServerSession* MyServer::SpawnSession(int fd) { return new MySession(fd, timeout, selector, this, "MY GREETING\n"); }
|
|
Bring the server up. This method creates a socket to listen calling the socket(2) system call. Then it binds the socket to the ip address and port given to constructor of the object. After that, it calls listen(2) to listen the socket. In case everything's Ok, the method registers the object with the given Selector object to monitor the listening socket's activity. Method returns true if everything's Ok, or false if something went wrong. |
|
The Selector to use.
|