AURobotServers
4
|
#include <usockserv.h>
Public Member Functions | |
bool | blockSend (int client, const char *buffer, int length, int msTimeout) |
virtual int | getUsedClientHandles () |
virtual void | gotConnectionProblems (int client, int errnum, const char *leadText) |
bool | isActive (int client) |
bool | isRunning () |
int | runServerThread () |
int | setPort (int iPort) |
bool | startServer () |
int | stopServer () |
USockServ () | |
virtual | ~USockServ () |
Public Attributes | |
USockServConnection * | clientConn [MAX_CLIENTS_SERVED] |
UTime | startTime |
bool | verboseMessages |
Protected Member Functions | |
virtual int | getFreeClientHandle () |
virtual int | handleConnection (int iConn, struct sockaddr_in iConnInfo) |
virtual void | info (const char *info, USig significance, int interface) |
virtual bool | justConnected (int client) |
Private Attributes | |
int | port |
bool | running |
bool | stop |
pthread_t | thServ |
Socket server bas class, that opens a port and accepts connection until no more client handles. Each client are given a welcome message - if such is defined. When client messages are received (in a receive thread) the butes are transferred in a call to gotNewMessage(), and are assumed consumed here. Transmissions to the client are performed by a call to sendBlock().
USockServ::USockServ | ( | ) |
Constructor
References MAX_CLIENTS_SERVED, and USockServConnection::stop.
|
virtual |
Destructor
bool USockServ::blockSend | ( | int | client, |
const char * | buffer, | ||
int | length, | ||
int | msTimeout | ||
) |
Send data to client. if connection to client is open the data is send. returns false if client do not exist or data could not be send within timeout period.
|
protectedvirtual |
Get free handle to a client connection. Returns -1 if no handle is available.
References USockServConnection::isActive(), and MAX_CLIENTS_SERVED.
|
virtual |
Get count of used handles.
References USockServConnection::isActive(), and MAX_CLIENTS_SERVED.
|
virtual |
Connection error has occured, this is the details
References MAX_COM_INFO_SIZE.
Referenced by USockServConnection::runConnection().
|
protectedvirtual |
Handle connection for client number clnt. clnt is index to client handle.
References USockServConnection::justConnected().
|
protectedvirtual |
Information that might be relevant for the user and might be printed on console or into logfile.
References eerror.
bool USockServ::isActive | ( | int | client | ) |
Tests if there is an active connection for this client, returns true if client is active (connected).
References USockServConnection::client, and MAX_CLIENTS_SERVED.
|
inline |
Is server running. Returns false if server is not accepting connections.
References USockServConnection::handleConnection(), USockServConnection::info(), and USockServConnection::justConnected().
|
protectedvirtual |
tests wether a newly accepted connection can be accepted, and initiates any queues etc. that needs to be set up for the connection. Returns true if connection is acceptable.
int USockServ::runServerThread | ( | ) |
start function for socket server thread
References buf, USockServConnection::handleConnection(), and USockServConnection::stop.
Referenced by runSockServer().
|
inline |
Set server port number
References USockServConnection::blockSend(), USockServConnection::client, and USockServConnection::isActive().
bool USockServ::startServer | ( | ) |
Start server with set port number
References runSockServer(), and USockServConnection::stop.
int USockServ::stopServer | ( | ) |
Stop server
References USockServConnection::stop.
USockServConnection* USockServ::clientConn[MAX_CLIENTS_SERVED] |
Structure for the accepted connections
|
private |
Port where to accept connections
|
private |
Running is true when accepting calls
UTime USockServ::startTime |
Start time - used fior timing analysis
|
private |
Flag to stop active connections and stop accepting connections.
|
private |
Handle to accept thread
bool USockServ::verboseMessages |
Print more to info connection / console