The Micro C++ Library
micxx::ServerSocket Class Reference

A ServerSocket represents a Transmission Control Protocol (TCP) server endpoint of a StreamSocket. It adds the capability to listen for and to accept other TCP client connections. More...

#include <micxx.hxx>

Inherits micxx::Socket.

Inherited by micxx::SSLServerSocket.

List of all members.

Public Member Functions

 ServerSocket ()
 Create a new unbound, disconnected ServerSocket.
virtual ClientSocketaccept ()
 Accept a new ClientSocket connection.
virtual void bind (unsigned short port)
virtual void bind (const SocketAddress &socketAddress)
virtual int getBacklog () const
 The backlog defines the maximum length for the (underlying) queue of pending connections.
virtual void listen (int abacklog=SOMAXCONN)
 Start listening for incoming ClientSocket connections.
virtual std::string toString () const
 Returns a printable representation.

Protected Member Functions

virtual ClientSocketcreateSocket (socket_t rawSocket, SocketAddress *socketAddress)
 Create a ClientSocket instance during accept().

Detailed Description

A ServerSocket represents a Transmission Control Protocol (TCP) server endpoint of a StreamSocket. It adds the capability to listen for and to accept other TCP client connections.

Example:

 #include <micxx.hxx>
 micxx::ServerSocket serverSocket;
 serverSocket.bind(8000);
 serverSocket.listen();
 while (true)
 {
     micxx::AutoPtr<micxx::ClientSocket> socket = serverSocket.accept();
     ...
     socket->recv(...);
     socket->send(...);
     ...
 }
Note:
Although ServerSocket is derived from Mutex, itself does no locking at all. If you intend to use ServerSocket concurrently from different threads, you could use the inherited Mutex to synchronize access to the instance (depending on the scenario in which it is used).
Author:
Norbert Klose
Date:
December, 2006

Constructor & Destructor Documentation

micxx::ServerSocket::ServerSocket ( )

Create a new unbound, disconnected ServerSocket.


Member Function Documentation

virtual ClientSocket* micxx::ServerSocket::accept ( ) [virtual]

Accept a new ClientSocket connection.

Returns:
A new allocated ClientSocket representing the new client connection. The caller must delete the returned ClientSocket.
virtual void micxx::ServerSocket::bind ( unsigned short  port) [virtual]
virtual void micxx::ServerSocket::bind ( const SocketAddress socketAddress) [virtual]
See also:
Socket::bind(const SocketAddress&)

Reimplemented from micxx::Socket.

virtual ClientSocket* micxx::ServerSocket::createSocket ( socket_t  rawSocket,
SocketAddress socketAddress 
) [protected, virtual]

Create a ClientSocket instance during accept().

This implementation just returns a ClientSocket. Derived classes may overwrite this method to return instances derived from ClientSocket.

Parameters:
rawSocketthe socket descriptor
socketAddressthe socket address to be used internally. The new socket takes ownership of the allocated SocketAdress and gets responsible for deleting it. In any case the implementation is responsible for deleting it.

Reimplemented in micxx::SSLServerSocket.

virtual int micxx::ServerSocket::getBacklog ( ) const [virtual]

The backlog defines the maximum length for the (underlying) queue of pending connections.

If a connection request arrives with the queue full, the client may receive an error with an indication of ECONNREFUSED.

Returns:
The backlog parameter from listen(int) or SOMAXCONN.
virtual void micxx::ServerSocket::listen ( int  abacklog = SOMAXCONN) [virtual]

Start listening for incoming ClientSocket connections.

To accept connections, a ServerSocket is first allocated and bound to a local address with the one of the functions bind(unsigned short) or bind(const SocketAddress&). Optionally a backlog for incoming connections is specified (otherwise the default SOMAXCONN is used), and then the connections are accepted with accept().

Parameters:
abacklogThe abacklog parameter defines the maximum length for the (underlying) queue of pending connections.
See also:
getBacklog() const
virtual std::string micxx::ServerSocket::toString ( ) const [virtual]

Returns a printable representation.

Reimplemented from micxx::Socket.


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