golib  0.5
goNet::goServer Class Reference

#include <goserver.h>

Public Member Functions

 goServer (int port)
 
goServerConnectionserverAcceptThread ()
 
bool disconnect (goServerConnection *con)
 
bool disconnect ()
 
bool sendFile (char *path, goServerConnection *con)
 
bool serverClose ()
 
bool runServer ()
 
bool stopServer ()
 
virtual bool requestHandler ()
 
void serverMessage (const char *)
 
void serverMessage (goString &)
 
void serverError (const char *)
 
- Public Member Functions inherited from goObjectBase
 goObjectBase ()
 Constructor.
 
virtual ~goObjectBase ()
 Destructor. More...
 
const char * getClassName () const
 Returns the class name. More...
 
int getClassID () const
 
virtual goSize_t memoryUsage () const
 Returns the size of this object or some measure of its memory consumption. More...
 
void setObjectName (const char *name)
 Set name string for an object. More...
 
void setObjectName (const goString &name)
 Set name string for an object. More...
 
const goStringgetObjectName () const
 Get the object name. More...
 
virtual bool writeObjectFile (FILE *) const
 Write object to a file. More...
 
virtual bool readObjectFile (FILE *)
 Read object from a file. More...
 
void connectObject (goObjectBase *object)
 Connects an object to this object. More...
 
void disconnectObject (const goObjectBase *object)
 Disconnects an object from this object.
 
virtual bool callObjectMethod (int methodID, goObjectMethodParameters *param=NULL)
 Call an object method by identifier. More...
 
virtual bool queueObjectMethod (int methodID, goObjectMethodParameters *param=NULL, bool blocking=false)
 Enqueue a method call to an internal list of methods. More...
 
bool callQueuedMethods ()
 Call all queued methods. More...
 

Protected Attributes

int socket
 
int port
 
char * hostname
 
struct sockaddr_in sock_addr
 
struct hostent * host
 
bool stopAccepting
 
goThread acceptThread
 
goMutex conMutex
 
goList< void * > connections
 

Additional Inherited Members

- Protected Member Functions inherited from goObjectBase
void setClassID (int id)
 Sets the class name.
 
void printClassMessage (const char *msg)
 Sets the class name. More...
 
void printClassMessage (goString &msg)
 Prints an informational message to the calling console. More...
 
void sendObjectMessage (int messageID, void *data=NULL)
 Sends a message to all connected objects.
 
void sendObjectMessage (goObjectBase *object, int messageID, void *data=NULL)
 Sends a message to a specific object.
 
virtual void receiveObjectMessage (const goObjectMessage &message)
 Receive a message. More...
 

Detailed Description

Accepts connections. When you create a server on a specified port, it starts accepting connections on that port when run() is called. The actual request handler has to be implemented by subclasses. The request handler is not automagically invoked. The calling program has to do that itself.

Todo:
serverAcceptThread(): Call a thread for every connection? That might be too special and should be implemented in a specialisation class.

Member Function Documentation

◆ disconnect() [1/2]

bool goNet::goServer::disconnect ( )

Disconnects the connection the connections list currently points at. This should be preferred over bool disconnect (goServerConnection* con) whenever the list is at the correct position anyway.
Not tested yet.

◆ disconnect() [2/2]

bool goNet::goServer::disconnect ( goServerConnection con)

Disconnects con. Searches the connections list front to back each time it is called, so use only with small lists or when speed doesn't matter. Only the address of con is compared.

◆ requestHandler()

bool goNet::goServer::requestHandler ( )
virtual

To be implemented by subclasses to handle requests coming in from the connections in the connection list.

◆ runServer()

bool goNet::goServer::runServer ( )

Accepts connections. This method starts a new thread that accepts connections and adds them to the connections list. It returns immediately after the thread is created with true on success, false on failure. Call stop() to stop the accepting thread.

Returns
true on success, false on failure

◆ serverAcceptThread()

goServerConnection * goNet::goServer::serverAcceptThread ( )

Accepts a connection for server server.

◆ stopServer()

bool goNet::goServer::stopServer ( )

Stops the accepting thread.

Returns
true on success, false on failure

The documentation for this class was generated from the following files: