1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
/*
* Modification History
*
* 2001-January-9 Jason Rohrer
* Created.
*
* 2002-March-27 Jason Rohrer
* Added a timeout to accept.
*/
#include "minorGems/common.h"
#ifndef SOCKET_SERVER_CLASS_INCLUDED
#define SOCKET_SERVER_CLASS_INCLUDED
#include <stdio.h>
#include "Socket.h"
/**
* Network socket server that listens for connections on a certain port.
*
* Note: Implementation for the functions defined here is provided
* separately for each platform (in the mac/ linux/ and win32/
* subdirectories).
*
* @author Jason Rohrer
*/
class SocketServer {
public:
/**
* Constructs a SocketServer and begins listening for connections.
*
* @param inPort the port to listen on.
* @param inMaxQueuedConnections the number of connection requests
* that will be queued before further requests are refused.
*/
SocketServer( int inPort, int inMaxQueuedConnections );
~SocketServer();
/**
* Accepts a an incoming connection on our port.
*
* @param inTimeoutInMilliseconds the timeout in milliseconds,
* or -1 for no timeout. Defaults to -1.
* @param outTimedOut pre-allocated char where timeout
* flag will be returned. If non-NULL, true will
* be inserted upon timeout, and false will be inserted
* upon other error or no error/timeout.
* Must be destroyed by caller if non-NULL.
* Defaults to NULL.
*
* @return a socket for the accepted connection,
* or NULL if a socket error/timeout occurred.
*/
Socket *acceptConnection( long inTimeoutInMilliseconds = -1,
char *outTimedOut = NULL );
private:
/**
* Used by platform-specific implementations.
*/
void *mNativeObjectPointer;
};
#endif
|