claw::net::socket_server Class Reference

Class used to receive incoming connections. More...

#include <socket_server.hpp>

Inheritance diagram for claw::net::socket_server:
claw::net::basic_socket

List of all members.

Public Member Functions

 socket_server ()
 Constructor.
 socket_server (int port, unsigned int queue_size=s_default_queue_size)
 Constructor, open the socket.
socket_serveropen (int port, unsigned int queue_size=s_default_queue_size)
 Open the socket.
socket_serverclose ()
 Close the socket.
bool is_open () const
 Tell if the server is open.
 operator bool () const
 Tell if the server is working.
template<typename SocketStream >
void accept (SocketStream &sock, int time_limit)
 Accept an incoming connection.

Static Public Member Functions

static bool init ()
 Initialize the use of the socket library.
static bool release ()
 Close the socket library.

Static Private Attributes

static const unsigned int s_default_queue_size = 16
 Default queue size for calls to listen.

Detailed Description

Class used to receive incoming connections.

Author:
Julien Jorge

Definition at line 47 of file socket_server.hpp.


Constructor & Destructor Documentation

claw::net::socket_server::socket_server (  ) 

Constructor.

Postcondition:
is_open() == false

Definition at line 38 of file socket_server.cpp.

00039 {
00040   // nothing to do
00041 } // socket_server::socket_server()

claw::net::socket_server::socket_server ( int  port,
unsigned int  queue_size = s_default_queue_size 
)

Constructor, open the socket.

Parameters:
port The port to bind.
queue_size The size of the waiting queue for incoming connections.

Definition at line 49 of file socket_server.cpp.

References claw::net::basic_socket::open().

00050 {
00051   open(port, queue_size);
00052 } // socket_server::socket_server()


Member Function Documentation

template<typename SocketStream >
void claw::net::socket_server::accept ( SocketStream &  sock,
int  time_limit 
) [inline]

Accept an incoming connection.

Parameters:
sock (out) The socket created for this connection.
time_limit Maximum of seconds to wait before considering there won't be any connection. if time_limit is negative, the server wait until there is a connection.

Definition at line 41 of file socket_server.tpp.

References claw::socket_traits_unix::accept(), claw::net::basic_socket::m_descriptor, and claw::socket_traits_unix::select_read().

00042 {
00043   if ( socket_traits::select_read( m_descriptor, time_limit ) )
00044     sock.open( socket_traits::accept( m_descriptor ) );
00045 } // socket_server::accept()

claw::net::socket_server::socket_server * claw::net::socket_server::close (  ) 

Close the socket.

Reimplemented from claw::net::basic_socket.

Definition at line 81 of file socket_server.cpp.

References claw::net::basic_socket::close().

Referenced by open().

00082 {
00083   if ( basic_socket::close() )
00084     return this;
00085   else
00086     return NULL;
00087 } // socket_server::close()

bool claw::net::socket_server::init (  )  [static]

Initialize the use of the socket library.

Returns:
true if the initialization is successful.

Definition at line 112 of file socket_server.cpp.

00113 {
00114   return socket_traits::init();
00115 } // socket_server::init()

bool claw::net::socket_server::is_open (  )  const

Tell if the server is open.

Reimplemented from claw::net::basic_socket.

Definition at line 93 of file socket_server.cpp.

Referenced by operator bool().

00094 {
00095   return basic_socket::is_open();
00096 } // socket_server::is_open()

claw::net::socket_server::socket_server * claw::net::socket_server::open ( int  port,
unsigned int  queue_size = s_default_queue_size 
)

Open the socket.

Parameters:
port The port to bind.
queue_size The size of the waiting queue for incoming connections.
Returns:
this if everything works fine, NULL otherwise.

Definition at line 62 of file socket_server.cpp.

References close(), claw::socket_traits_unix::listen(), claw::net::basic_socket::m_descriptor, and claw::net::basic_socket::open().

00063 {
00064   socket_server* result = NULL;
00065 
00066   if ( basic_socket::open() )
00067     {
00068       if ( !socket_traits::listen(m_descriptor, port, queue_size) )
00069         basic_socket::close();
00070       else
00071         result = this;
00072     }
00073 
00074   return result;
00075 } // socket_server::open()

claw::net::socket_server::operator bool (  )  const

Tell if the server is working.

Definition at line 102 of file socket_server.cpp.

References is_open().

00103 {
00104   return is_open();
00105 } // socket_server::operator bool()

bool claw::net::socket_server::release (  )  [static]

Close the socket library.

Returns:
true if the operation is successful.

Definition at line 122 of file socket_server.cpp.

00123 {
00124   return socket_traits::release();
00125 } // socket_server::release()


Member Data Documentation

const unsigned int claw::net::socket_server::s_default_queue_size = 16 [static, private]

Default queue size for calls to listen.

Definition at line 69 of file socket_server.hpp.


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

Generated on 9 Nov 2009 for CLAW Library (a C++ Library Absolutely Wonderful) by  doxygen 1.6.1