SocketListener Class Reference
[Listener implementation classes]

A class describing how to listen on any type of socket. More...

#include <socklistener.h>

Inheritance diagram for SocketListener:

Inheritance graph
[legend]
Collaboration diagram for SocketListener:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 SocketListener (SocketAddressP &address)
virtual ~SocketListener ()
virtual ConnectorP listen_for_incoming ()
 Start listening for incoming connections on sock_fd.
virtual void disconnect ()
 Disconnect a connection.
std::string class_name (void) const
std::string get_id (void) const
 Generate a string to tell a human who we are.

Protected Member Functions

virtual int make_incoming_socket (void)
 Allocate a socket (fd) prepared for incoming connections.

Protected Attributes

SocketAddressP sock_addr
 The address of the socket on which we should listen.
int sock_fd
pthread_mutex_t mutex
 This mutex protects against changes to data members.


Detailed Description

A class describing how to listen on any type of socket.

Subclasses may exist for any types of socket that need additional actions performed.

Definition at line 70 of file socklistener.h.


Constructor & Destructor Documentation

SocketListener::SocketListener ( SocketAddressP address  ) 

Definition at line 19 of file socklistener.cc.

References Guard::initialize_mutex(), make_incoming_socket(), mutex, MUTEX_LOG, and sock_fd.

Here is the call graph for this function:

SocketListener::~SocketListener (  )  [virtual]

Definition at line 31 of file socklistener.cc.

References Guard::destroy_mutex(), disconnect(), mutex, and MUTEX_LOG.

Here is the call graph for this function:


Member Function Documentation

ConnectorP SocketListener::listen_for_incoming ( void   )  [virtual]

Start listening for incoming connections on sock_fd.

sock_fd needs to have been created, initialized, and bound with a call to make_incomfing_socket(). When a connection comes in, this method will instantiate a new SocketConnector, set its state to connected, and return it so that our caller can configure management of it. We will then be ready to accept() again, if we are invoked again.

Note:
While blocked in accept(2), we will keep our mutex locked. I think this is okay, because it would only prevent access to the SocketAddress and sock_fd data members, which noone else should be concerned about.

Implements Listener.

Definition at line 121 of file socklistener.cc.

References FDConnector::get_id(), get_id(), mutex, MUTEX_LOG, PTHREAD_CHECK_AND_THROW, sock_addr, and sock_fd.

Here is the call graph for this function:

void SocketListener::disconnect ( void   )  [virtual]

Disconnect a connection.

Todo:
Should this method be exposed? Or should we just expect the owner to delete us, which, btw, also calls disconnect()?
This function is called during the connection shutdown process.
Note:
If UDSListener ever gets collapsed into SocketListener, this would be the right place to delete the socket file.

Implements Listener.

Reimplemented in UDSListener.

Definition at line 46 of file socklistener.cc.

References mutex, MUTEX_LOG, and sock_fd.

Referenced by UDSListener::disconnect(), and ~SocketListener().

Here is the caller graph for this function:

std::string SocketListener::class_name ( void   )  const [inline, virtual]

Implements Listener.

Reimplemented in UDSListener.

Definition at line 82 of file socklistener.h.

std::string SocketListener::get_id ( void   )  const [virtual]

Generate a string to tell a human who we are.

Implements Listener.

Reimplemented in UDSListener.

Definition at line 206 of file socklistener.cc.

References sock_addr.

Referenced by listen_for_incoming(), and make_incoming_socket().

Here is the caller graph for this function:

int SocketListener::make_incoming_socket ( void   )  [protected, virtual]

Allocate a socket (fd) prepared for incoming connections.

Allocate a socket fd of the right family.

This includ * any one-time setup, creation/deletion of files or objects, socket(2) call(s), bind(2) call(s), etc.

It will also be bound to a local address and listen(2) will've been called so that the kernel will know to hold incoming connections for us. These connections must be accepted by calling listen_for_incoming().

Todo:
The fact that we lock a mutex here suggests that we want to make a new incoming socket only if we're not already in the process of doing that. So, check first. Note, however, that we're contending for an external resource; opening a socket at the given SocketAddress. We need to be mindful that we could be in a race with some other process for that resource, and handle failure (presumably in bind()) accordingly. We need to think about how a mutex can help us here.

Reimplemented in UDSListener.

Definition at line 64 of file socklistener.cc.

References get_id(), mutex, MUTEX_LOG, and sock_addr.

Referenced by UDSListener::make_incoming_socket(), and SocketListener().

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

The address of the socket on which we should listen.

Definition at line 92 of file socklistener.h.

Referenced by UDSListener::get_id(), get_id(), listen_for_incoming(), UDSListener::make_incoming_socket(), and make_incoming_socket().

int SocketListener::sock_fd [protected]

Definition at line 98 of file socklistener.h.

Referenced by disconnect(), listen_for_incoming(), and SocketListener().

pthread_mutex_t SocketListener::mutex [protected]

This mutex protects against changes to data members.

(This currently includes sock_addr and sock_fd)

Definition at line 102 of file socklistener.h.

Referenced by UDSListener::disconnect(), disconnect(), listen_for_incoming(), UDSListener::make_incoming_socket(), make_incoming_socket(), SocketListener(), and ~SocketListener().


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

Generated on Tue May 13 11:32:50 2008 for consmgr by  doxygen 1.5.5