Server< T > Class Template Reference

Generic TCP server class. More...

#include <socket.hpp>

Inheritance diagram for Server< T >:

Inheritance graph
[legend]
Collaboration diagram for Server< T >:

Collaboration graph
[legend]

List of all members.

Public Types

enum  State { Invalid, Created, Bound, Listening }

Public Member Functions

 Server ()
 Initializes the Server.
 Server (IPAddress addr, uint16_t port)
 Initializes the Server and binds to the specified address and port.
void Bind (IPAddress addr, uint16_t port)
 Bind the Server to the specified address and port.
void Listen (int maxconn, int backlog=10)
 Bind the Server to the specified address and port.
T * Poll ()
 Check for new connection requests.
std::list< T * > Select (int timeout)
 Check clients for incoming data and errors, and sends data in their send_buffer.
void BuryTheDead ()
 Destroys any dead clients, should be called periodically.
State State ()
int Connections ()
int MaxConnections ()

Public Attributes

fd_set read_fds
 Stores file descriptors for Select().
fd_set write_fds
 Stores file descriptors for Select().
fd_set except_fds
 Stores file descriptors for Select().
std::size_t recv_buffer_max
 Maximum amount of data that will be buffered for recieving per client.
std::size_t send_buffer_max
 Maximum amount of data that will be buffered for sending per client.
unsigned int maxconn
 Maximum number of connections the server will hold at one time.
std::list< T * > clients
 List of connected clients.

Protected Attributes

IPAddress address
 The address the server will listen on.
uint16_t port
 The port the server will listen on in host order.
uint16_t portn
 The port the server will listen on in network order.
SOCKET server
 Socket handle of the listener.
State state
 Current server state.

Private Member Functions

void Initialize ()
 Initializes all data and WinSock if required.


Detailed Description

template<class T = Client>
class Server< T >

Generic TCP server class.

Member Enumeration Documentation

template<class T = Client>
enum Server::State

Enumerator:
Invalid  There was an error preparing the server.
Created  Newly created server, not listening yet.
Bound  Server has been bound to a port but is not yet listening.
Listening  Server is listening and is ready to accept clients.


Constructor & Destructor Documentation

template<class T = Client>
Server< T >::Server (  )  [inline]

Initializes the Server.

template<class T = Client>
Server< T >::Server ( IPAddress  addr,
uint16_t  port 
) [inline]

Initializes the Server and binds to the specified address and port.

Parameters:
addr Address to bind to
port Port number to bind to


Member Function Documentation

template<class T = Client>
void Server< T >::Initialize (  )  [inline, private]

Initializes all data and WinSock if required.

This is called by every Socket constructor.

Exceptions:
Socket_InitFailed 

template<class T = Client>
void Server< T >::Bind ( IPAddress  addr,
uint16_t  port 
) [inline]

Bind the Server to the specified address and port.

Once this succeeds you should call Listen().

Parameters:
addr Address to bind to.
port Port number to bind to.
Exceptions:
Socket_BindFailed 

template<class T = Client>
void Server< T >::Listen ( int  maxconn,
int  backlog = 10 
) [inline]

Bind the Server to the specified address and port.

Parameters:
maxconn Maximum number of clients to have at one time.
backlog Number of connections to keep in the queue.
Exceptions:
Socket_ListenFailed 

template<class T = Client>
T* Server< T >::Poll (  )  [inline]

Check for new connection requests.

Returns:
NULL if there are no pending connections, a pointer to the Client otherwise.

template<class T = Client>
std::list<T *> Server< T >::Select ( int  timeout  )  [inline]

Check clients for incoming data and errors, and sends data in their send_buffer.

If data is recieved, it is added to their recv_buffer.

Exceptions:
Socket_SelectFailed 
Socket_Exception 
Returns:
Returns a list of clients that have data in their recv_buffer.

template<class T = Client>
void Server< T >::BuryTheDead (  )  [inline]

Destroys any dead clients, should be called periodically.

All pointers to Client objects from this Server should be considered invalid after execution.

template<class T = Client>
State Server< T >::State (  )  [inline]

template<class T = Client>
int Server< T >::Connections (  )  [inline]

template<class T = Client>
int Server< T >::MaxConnections (  )  [inline]


Member Data Documentation

template<class T = Client>
fd_set Server< T >::read_fds

Stores file descriptors for Select().

template<class T = Client>
fd_set Server< T >::write_fds

Stores file descriptors for Select().

template<class T = Client>
fd_set Server< T >::except_fds

Stores file descriptors for Select().

template<class T = Client>
std::size_t Server< T >::recv_buffer_max

Maximum amount of data that will be buffered for recieving per client.

template<class T = Client>
std::size_t Server< T >::send_buffer_max

Maximum amount of data that will be buffered for sending per client.

template<class T = Client>
unsigned int Server< T >::maxconn

Maximum number of connections the server will hold at one time.

template<class T = Client>
IPAddress Server< T >::address [protected]

The address the server will listen on.

template<class T = Client>
uint16_t Server< T >::port [protected]

The port the server will listen on in host order.

template<class T = Client>
uint16_t Server< T >::portn [protected]

The port the server will listen on in network order.

template<class T = Client>
SOCKET Server< T >::server [protected]

Socket handle of the listener.

template<class T = Client>
State Server< T >::state [protected]

Current server state.

See also:
State

template<class T = Client>
std::list<T *> Server< T >::clients

List of connected clients.


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

Generated on Sun Apr 5 20:28:24 2009 for EOServ by  doxygen 1.5.7.1