AURobotServers
4
|
#include <usockserv.h>
Public Member Functions | |
bool | blockSend (const char *buffer, int length, int msTimeout) |
char * | getClientName () |
virtual bool | getWelcomeMessage (unsigned char *buf, int *len) |
virtual void | gotNewMessage (unsigned char *message, int length) |
bool | handleConnection (int iConn, struct sockaddr_in iConnInfo) |
bool | isActive () |
virtual bool | justConnected () |
int | runConnection () |
bool | stopConnection () |
USockServConnection () | |
virtual | ~USockServConnection () |
Public Attributes | |
int | client |
int | msgSend |
pid_t | pid |
int | recvLoops |
USockServ * | serv |
Protected Member Functions | |
virtual void | info (const char *info, USig significance, int interface) |
Protected Attributes | |
int | conn |
bool | connected |
struct sockaddr_in | connInfo |
bool | stop |
pthread_t | thClient |
example server from 31370 Exersize 6: TCP/IP
USockServConnection::USockServConnection | ( | ) |
|
virtual |
Destructor - stops connection
References connected, and stopConnection().
bool USockServConnection::blockSend | ( | const char * | buffer, |
int | length, | ||
int | msTimeout | ||
) |
Send this bufferfull of data within this timeout period. Returns true if send. Returns false if not possible within timeout opperiod.
References conn, connected, and msgSend.
Referenced by isActive(), and USockServ::setPort().
char * USockServConnection::getClientName | ( | ) |
|
virtual |
Called at start of client connection and sends a welcome message if so desired. Should return false if no message is to be send.
Referenced by isActive(), and runConnection().
|
virtual |
A new message (or part of a message) has arraived. The message is assumed handled by this virtual function.
References client.
Referenced by isActive(), and runConnection().
bool USockServConnection::handleConnection | ( | int | iConn, |
struct sockaddr_in | iConnInfo | ||
) |
Handle this connection
References conn, connected, connInfo, justConnected(), runServerConn(), stop, and thClient.
Referenced by USockServ::isRunning(), and USockServ::runServerThread().
|
protectedvirtual |
Information that might be relevant for the user and might be printed on console or into logfile.
Referenced by isActive(), USockServ::isRunning(), and runConnection().
|
inline |
returns true if connection is open.
References blockSend(), buf, connected, getWelcomeMessage(), gotNewMessage(), info(), runConnection(), and stopConnection().
Referenced by USockServ::getFreeClientHandle(), USockServ::getUsedClientHandles(), and USockServ::setPort().
|
virtual |
tests wether a newly accepted connection can be accepted, and initiates any queues etc. that needs to be set up for the connection. This is also the place to send any welcome messages. The virtual function is called before receive thread is activated. Returns true if connection is acceptable.
Referenced by handleConnection(), USockServ::handleConnection(), and USockServ::isRunning().
int USockServConnection::runConnection | ( | ) |
This routine is running in a thread, and handles the connection protocol to this client. Returns when thread stopps.
References buf, client, conn, connected, einfo, getClientName(), getWelcomeMessage(), USockServ::gotConnectionProblems(), gotNewMessage(), info(), pid, recvLoops, serv, stop, and Wait().
Referenced by isActive(), and runServerConn().
bool USockServConnection::stopConnection | ( | ) |
Stop the connection if active
References conn, connected, pid, stop, and thClient.
Referenced by isActive(), and ~USockServConnection().
int USockServConnection::client |
index number of client connection (0 to MAX_CLIENTS_SERVED-1)
Referenced by gotNewMessage(), USockServ::isActive(), runConnection(), and USockServ::setPort().
|
protected |
Connection handle
Referenced by blockSend(), handleConnection(), runConnection(), stopConnection(), and USockServConnection().
|
protected |
Connection established flag
Referenced by blockSend(), getClientName(), handleConnection(), isActive(), runConnection(), stopConnection(), USockServConnection(), and ~USockServConnection().
|
protected |
Structure with adress information etc.
Referenced by getClientName(), and handleConnection().
int USockServConnection::msgSend |
statistics
Referenced by blockSend(), and USockServConnection().
pid_t USockServConnection::pid |
id of the read process
Referenced by runConnection(), and stopConnection().
int USockServConnection::recvLoops |
receive loops (poll loops)
Referenced by runConnection(), and USockServConnection().
USockServ* USockServConnection::serv |
parent structure
Referenced by runConnection().
|
protected |
Closing connection if true
Referenced by handleConnection(), runConnection(), USockServ::runServerThread(), USockServ::startServer(), stopConnection(), USockServ::stopServer(), USockServ::USockServ(), and USockServConnection().
|
protected |
Read thread handle
Referenced by handleConnection(), and stopConnection().