LLSocket Class Reference

Implementation of a wrapper around a socket. More...

#include <lliosocket.h>

List of all members.

Public Types

typedef boost::shared_ptr<
LLSocket
ptr_t
 Reference counted shared pointers to sockets.
 STREAM_TCP
 DATAGRAM_UDP
 PORT_INVALID = (U16)-1
 PORT_EPHEMERAL = 0
enum  EType { STREAM_TCP, DATAGRAM_UDP }
 Type of socket to create. More...
enum  { PORT_INVALID = (U16)-1, PORT_EPHEMERAL = 0 }
 Anonymous enumeration to help identify ports. More...

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 Get the port.
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_pool_t *pool, EType type, U16 port=PORT_EPHEMERAL)
 Create a socket.
static ptr_t create (apr_socket_t *socket, apr_pool_t *pool)
 Create a LLSocket when you already have an apr 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.

Protected Attributes

apr_socket_t * mSocket
apr_pool_tmPool
U16 mPort


Detailed Description

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.

Definition at line 63 of file lliosocket.h.


Member Typedef Documentation

typedef boost::shared_ptr<LLSocket> LLSocket::ptr_t

Reference counted shared pointers to sockets.

Definition at line 69 of file lliosocket.h.


Member Enumeration Documentation

anonymous enum

Anonymous enumeration to help identify ports.

Enumerator:
PORT_INVALID 
PORT_EPHEMERAL 

Definition at line 83 of file lliosocket.h.

enum LLSocket::EType

Type of socket to create.

Enumerator:
STREAM_TCP 
DATAGRAM_UDP 

Definition at line 74 of file lliosocket.h.


Constructor & Destructor Documentation

LLSocket::LLSocket ( apr_socket_t *  socket,
apr_pool_t pool 
) [protected]

Protected constructor since should only make sockets with one of the two create() calls.

Definition at line 207 of file lliosocket.cpp.

References LLMemType::MTYPE_IO_TCP.

Referenced by create().

LLSocket::~LLSocket (  ) 

Do not call this directly.

Definition at line 215 of file lliosocket.cpp.

References mPool, mSocket, and LLMemType::MTYPE_IO_TCP.


Member Function Documentation

bool LLSocket::blockingConnect ( const LLHost host  ) 

Perform a blocking connect to a host. Do not use in production.

Parameters:
host The host to connect this socket to.
Returns:
Returns true if the connect was successful.

Definition at line 185 of file lliosocket.cpp.

References LLHost::getIPString(), LLHost::getPort(), ll_apr_warn_status(), MAXADDRSTR, mPool, mSocket, NULL, and setOptions().

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.

Parameters:
socket The apr socket to use
pool The pool used to create the socket. *NOTE: The pool passed in will be DESTROYED.
Returns:
A valid socket shared pointer if the call worked.

Definition at line 170 of file lliosocket.cpp.

References LLSocket(), LLMemType::MTYPE_IO_TCP, and PORT_EPHEMERAL.

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.

Parameters:
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
Returns:
A valid socket shared pointer if the call worked.

Definition at line 72 of file lliosocket.cpp.

References DATAGRAM_UDP, ll_apr_warn_status(), LL_DEFAULT_LISTEN_BACKLOG, lldebugs, llendl, LLSocket(), LLMemType::MTYPE_IO_TCP, NULL, PORT_EPHEMERAL, and STREAM_TCP.

Referenced by LLIOHTTPServer::create(), tut::pipe_and_pump_fitness::pipe_and_pump_fitness(), LLIOServerSocket::process_impl(), and LLVoiceClient::stateMachine().

U16 LLSocket::getPort (  )  const [inline]

Get the type of socket Get the port.

This will return PORT_EPHEMERAL if bind was never called.

Returns:
Returns the port associated with this socket.

Definition at line 144 of file lliosocket.h.

References mPort.

apr_socket_t* LLSocket::getSocket (  )  const [inline]

Get the apr socket implementation.

Returns:
Returns the raw apr socket.

Definition at line 151 of file lliosocket.h.

References mSocket.

void LLSocket::setOptions (  )  [protected]

Set default socket options.

Definition at line 230 of file lliosocket.cpp.

References ll_apr_warn_status(), LL_RECV_BUFFER_SIZE, LL_SEND_BUFFER_SIZE, mSocket, and LLMemType::MTYPE_IO_TCP.

Referenced by blockingConnect().


Member Data Documentation

apr_pool_t* LLSocket::mPool [protected]

Definition at line 176 of file lliosocket.h.

Referenced by blockingConnect(), and ~LLSocket().

U16 LLSocket::mPort [protected]

Definition at line 179 of file lliosocket.h.

Referenced by getPort().

apr_socket_t* LLSocket::mSocket [protected]

Definition at line 173 of file lliosocket.h.

Referenced by blockingConnect(), getSocket(), setOptions(), and ~LLSocket().


The documentation for this class was generated from the following files:
Generated on Thu Jul 1 06:11:47 2010 for Second Life Viewer by  doxygen 1.4.7