#include <socklistener.h>
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. |
Subclasses may exist for any types of socket that need additional actions performed.
Definition at line 70 of file socklistener.h.
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.
SocketListener::~SocketListener | ( | ) | [virtual] |
Definition at line 31 of file socklistener.cc.
References Guard::destroy_mutex(), disconnect(), mutex, and MUTEX_LOG.
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.
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.
void SocketListener::disconnect | ( | void | ) | [virtual] |
Disconnect a connection.
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().
std::string SocketListener::class_name | ( | void | ) | const [inline, virtual] |
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().
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().
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().
SocketAddressP SocketListener::sock_addr [protected] |
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().