Implementation of a wrapper around a socket. More...
#include <lliosocket.h>
Public Types | |
enum | |
Anonymous enumeration to help identify ports. | |
enum | EType |
Type of socket to create. | |
typedef boost::shared_ptr < LLSocket > | ptr_t |
Reference counted shared pointers to sockets. | |
Public Member Functions | |
bool | blockingConnect (const LLHost &host) |
Perform a blocking connect to a host. Do not use in production. | |
U16 | getPort () const |
Get the type of socket. | |
apr_socket_t * | getSocket () const |
Get the apr socket implementation. | |
~LLSocket () | |
Do not call this directly. | |
Static Public Member Functions | |
static ptr_t | create (apr_socket_t *socket, apr_pool_t *pool) |
Create a LLSocket when you already have an apr socket. | |
static ptr_t | create (apr_pool_t *pool, EType type, U16 port=PORT_EPHEMERAL) |
Create a socket. | |
Protected Member Functions | |
LLSocket (apr_socket_t *socket, apr_pool_t *pool) | |
Protected constructor since should only make sockets with one of the two create() calls. | |
void | setOptions () |
Set default socket options. |
Implementation of a wrapper around a socket.
An instance of this class represents a single socket over it's entire life - from uninitialized, to connected, to a listening socket depending on it's purpose. This class simplifies our access into the socket interface by only providing stream/tcp and datagram/udp sockets - the only types we are interested in, since those are the only properly supported by all of our platforms.
bool LLSocket::blockingConnect | ( | const LLHost & | host | ) |
Perform a blocking connect to a host. Do not use in production.
host | The host to connect this socket to. |
LLSocket::ptr_t LLSocket::create | ( | apr_socket_t * | socket, | |
apr_pool_t * | pool | |||
) | [static] |
Create a LLSocket when you already have an apr socket.
This method assumes an ephemeral port. This is typically used by calls which spawn a socket such as a call to accept()
as in the server socket. This call should not fail if you have a valid apr socket. Because of the nature of how accept() works, you are expected to create a new pool for the socket, use that pool for the accept, and pass it in here where it will be bound with the socket and destroyed at the same time.
socket | The apr socket to use | |
pool | The pool used to create the socket. *NOTE: The pool passed in will be DESTROYED. |
LLSocket::ptr_t LLSocket::create | ( | apr_pool_t * | pool, | |
EType | type, | |||
U16 | port = PORT_EPHEMERAL | |||
) | [static] |
Create a socket.
This is the call you would use if you intend to create a listen socket. If you intend the socket to be known to external clients without prior port notification, do not use PORT_EPHEMERAL.
pool | The apr pool to use. A child pool will be created and associated with the socket. | |
type | The type of socket to create | |
port | The port for the socket |
U16 LLSocket::getPort | ( | ) | const [inline] |
Get the type of socket.
Get the port. This will return PORT_EPHEMERAL if bind was never called.
apr_socket_t* LLSocket::getSocket | ( | ) | const [inline] |
Get the apr socket implementation.