SocketServer Class Reference

#include <sockets.h>

Inheritance diagram for SocketServer:

Inheritance graph
[legend]
Collaboration diagram for SocketServer:

Collaboration graph
[legend]
List of all members.

Detailed Description

A listening socket server which accepts incoming connections (as SocketClient objects).

Definition at line 312 of file sockets.h.


Public Types

typedef SSEventHandler HandlerType
 Type of event handler used by this object.

Public Member Functions

 DECLARE_EVENT_TABLE (SocketServer *, SocketEvent)
 SocketServer (SSEventHandler ehandler=0)
 Constructor.
void destroy ()
 Destroy this socket.
SocketClientaccept (SCEventHandler ehandler=0)
 Accept an incoming connection.
void listen (IPV4Address addr)
 Puts the server into listening state.
IPV4Address getAddr () const
bool isConnected () const
 Helper method for Scheduler API; SocketServer's are never in connected state.
Accessors for various internal variables
bool isListening ()
bool hasIncoming ()

Private Member Functions

virtual ~SocketServer ()
 Destructor.
void close ()
 Closes the underlying socket.

Private Attributes

bool m_incoming
 Incoming connection is waiting.
bool m_listening
 If the socket is listening.
bool m_erronous
 If the socket is erronous.
IPV4Address m_addr
 Address where we are listening.

Friends

class SocketWatcher

Member Typedef Documentation

typedef SSEventHandler SocketServer::HandlerType
 

Type of event handler used by this object.

Definition at line 317 of file sockets.h.


Constructor & Destructor Documentation

SocketServer::SocketServer SSEventHandler  ehandler = 0  ) 
 

Constructor.

Parameters:
ehandler Callback function for events.

Definition at line 388 of file sockets.cpp.

References initSockets(), INVALID_SOCKET, logTrace(), setNonBlocking(), setReUsable(), and TRACE_SOCKET.

Here is the call graph for this function:

SocketServer::~SocketServer  )  [private, virtual]
 

Destructor.

Definition at line 408 of file sockets.cpp.

References logTrace(), and TRACE_SOCKET.

Here is the call graph for this function:


Member Function Documentation

SocketClient * SocketServer::accept SCEventHandler  ehandler = 0  ) 
 

Accept an incoming connection.

Parameters:
ehandler Callback function for events for the accepted socket.
Returns:
Accepted connection. May be NULL if accept() fails.

Definition at line 485 of file sockets.cpp.

References SocketWatcher::addSocket(), INVALID_SOCKET, SocketClient::m_connected, m_erronous, m_incoming, m_listening, SocketClient::m_peer, SocketBase::m_socket, setNonBlocking(), and socketError().

Here is the call graph for this function:

void SocketServer::close  )  [private]
 

Closes the underlying socket.

Definition at line 418 of file sockets.cpp.

References closesocket, logTrace(), logWarning(), m_listening, SocketWatcher::removeSocket(), socketError(), and TRACE_SOCKET.

Referenced by destroy(), and SocketWatcher::handleErronousSocket().

Here is the call graph for this function:

SocketServer::DECLARE_EVENT_TABLE SocketServer ,
SocketEvent 
 

void SocketServer::destroy  )  [virtual]
 

Destroy this socket.

It is safe to call this method multiple times.

Implements SocketBase.

Definition at line 413 of file sockets.cpp.

References close().

Here is the call graph for this function:

IPV4Address SocketServer::getAddr  )  const [inline]
 

Returns:
The local address the server.

Definition at line 362 of file sockets.h.

bool SocketServer::hasIncoming  )  [inline]
 

Definition at line 356 of file sockets.h.

bool SocketServer::isConnected  )  const [inline]
 

Helper method for Scheduler API; SocketServer's are never in connected state.

Definition at line 368 of file sockets.h.

bool SocketServer::isListening  )  [inline]
 

Definition at line 355 of file sockets.h.

void SocketServer::listen IPV4Address  addr  ) 
 

Puts the server into listening state.

Parameters:
addr Address to listen on.
Note:
If addr.m_ip == 0, the listener will listen on all available networks.

Definition at line 432 of file sockets.cpp.

References SocketWatcher::addSocket(), IPV4Address::getAddr(), IPV4Address::getPort(), logDebug(), logTrace(), m_addr, m_erronous, m_listening, IPV4Address::setAddr(), SOCKET_ERROR, socketError(), and TRACE_SOCKET.

Here is the call graph for this function:


Friends And Related Function Documentation

friend class SocketWatcher [friend]
 

Definition at line 375 of file sockets.h.


Member Data Documentation

IPV4Address SocketServer::m_addr [private]
 

Address where we are listening.

Definition at line 379 of file sockets.h.

Referenced by listen().

bool SocketServer::m_erronous [private]
 

If the socket is erronous.

Definition at line 378 of file sockets.h.

Referenced by accept(), SocketWatcher::handleErronousSocket(), and listen().

bool SocketServer::m_incoming [private]
 

Incoming connection is waiting.

Definition at line 376 of file sockets.h.

Referenced by accept(), and SocketWatcher::handleReadableSocket().

bool SocketServer::m_listening [private]
 

If the socket is listening.

Definition at line 377 of file sockets.h.

Referenced by accept(), close(), SocketWatcher::handleErronousSocket(), and listen().


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