ucc::Socket Class Reference

A generic socket base class. More...

#include <socket.h>

Inheritance diagram for ucc::Socket:

Inheritance graph
[legend]

Data Structures

class  address
 A generic socket address class. More...

Public Member Functions

 Socket ()
 Create a socket object for use.
 Socket (Socket &existing)
 Create socket as duped handle of existing socket.
 Socket (socket_t socket)
 Create socket from existing socket descriptor.
 Socket (struct addrinfo *address)
 Create and connect a socket to an address from an address list.
 Socket (int family, int type, int protocol=0)
 Create an unbound socket of a specific type.
 Socket (char *address, char *port, int family=0, int type=0, int protocol=0, int backlog=0)
 Create a bound socket.
virtual ~Socket ()
 Shutdown, close, and destroy socket.
void cancel (void)
 Cancel pending i/o by shutting down the socket.
void release (void)
 Shutdown and close the socket.
bool isPending (unsigned value)
 See the number of bytes in the receive queue.
bool isConnected (void)
 Test if socket is connected.
bool waitPending (timeout_t timeout=0)
 Test for pending input data.
bool waitSending (timeout_t timeout=0)
 Test for output data sent.
unsigned getPending (void)
 Get the number of bytes of data in the socket receive buffer.
int broadcast (bool enable)
 Set socket for unicast mode broadcasts.
int keepalive (bool enable)
 Set socket for keepalive packets.
int blocking (bool enable)
 Set socket blocking I/O mode.
int multicast (unsigned ttl=1)
 Set multicast mode and multicast broadcast range.
int loopback (bool enable)
 Set loopback to read multicast packets we broadcast.
int getError (void)
 Get socket error code.
int ttl (unsigned char time)
 Set the time to live before packets expire.
int sendsize (unsigned size)
 Set the size of the socket send buffer.
int sendwait (unsigned size)
 Set the size to wait before sending.
int recvsize (unsigned size)
 Set the size of the socket receive buffer.
int gettype (void)
 Get the type of a socket.
unsigned segsize (unsigned size)
 Set segment size and get mtu of a socket.
bool setccid (uint8_t ccid)
 Set ccid of dccp socket.
int tos (int type)
 Set the type of service field of outgoing packets.
int priority (int scheduling)
 Set packet priority, 0 to 6 unless privileged.
void shutdown (void)
 Shutdown the socket communication channel.
int connectto (struct addrinfo *list)
 Connect our socket to a remote host from an address list.
int disconnect (void)
 Disconnect a connected socket.
int join (struct addrinfo *list)
 Join socket to multicast group.
int drop (struct addrinfo *list)
 Drop socket from multicast group.
size_t peek (void *data, size_t number)
 Peek at data waiting in the socket receive buffer.
virtual ssize_t get (void *data, size_t number, struct sockaddr_storage *address=((void *) 0))
 Read data from the socket receive buffer.
virtual ssize_t put (void *data, size_t number, struct sockaddr *address=((void *) 0))
 Write data to the socket send buffer.
virtual ssize_t gets (char *data, size_t size, timeout_t timeout=Timer::inf)
 Read a newline of text data from the socket and save in NULL terminated string.
ssize_t puts (char *string)
 Write a null terminated string to the socket.
 operator bool ()
 Test if socket is valid.
bool operator! ()
 Test if socket is invalid.
Socketoperator= (socket_t socket)
 Assign socket from a socket descriptor.
 operator socket_t ()
 Get the socket descriptor by casting.
socket_t operator* ()
 Get the socket descriptor by pointer reference.
FILE * open (bool mode=false)
 Get file handle for reading from a socket object.

Static Public Member Functions

static void cancel (socket_t socket)
 Cancel pending i/o by shutting down the socket.
static bool wait (socket_t socket, timeout_t timeout=0)
 Test for pending input data.
static int gettype (socket_t socket)
 Get the type of a socket.
static unsigned segsize (socket_t socket, unsigned size=0)
 Set segment size and get MTU.
static bool setccid (socket_t socket, uint8_t ccid)
 Set congestion control id.
static ssize_t readline (socket_t socket, char *data, size_t size, timeout_t timeout=Timer::inf)
 Read a newline of text data from the socket and save in NULL terminated string.
static ssize_t printf (socket_t socket, char *format,...)
 Print formatted string to socket.
static unsigned pending (socket_t socket)
 Get the number of bytes pending in the receive buffer of a socket descriptor.
static int sendsize (socket_t socket, unsigned size)
 Set the send size of a socket descriptor.
static int sendwait (socket_t socket, unsigned size)
 Set the size to wait before sending.
static int recvsize (socket_t socket, unsigned size)
 Set the receive size of a socket descriptor.
static int connectto (socket_t socket, struct addrinfo *list)
 Connect socket descriptor to a remote host from an address list.
static int disconnect (socket_t socket)
 Disconnect a connected socket descriptor.
static int drop (socket_t socket, struct addrinfo *list)
 Drop socket descriptor from multicast group.
static int join (socket_t socket, struct addrinfo *list)
 Join socket descriptor to multicast group.
static int error (socket_t socket)
 Get socket error code of socket descriptor.
static int multicast (socket_t socket, unsigned ttl=1)
 Set multicast mode and multicast broadcast range for socket descriptor.
static int loopback (socket_t socket, bool enable)
 Set loopback to read multicast packets socket descriptor broadcasts.
static int blocking (socket_t socket, bool enable)
 Set socket blocking I/O mode of socket descriptor.
static int keepalive (socket_t socket, bool enable)
 Set socket for keepalive packets for socket descriptor.
static int broadcast (socket_t socket, bool enable)
 Set socket for unicast mode broadcasts on socket descriptor.
static int priority (socket_t socket, int scheduling)
 Set packet priority of socket descriptor.
static int tos (socket_t socket, int type)
 Set type of service of socket descriptor.
static int ttl (socket_t socket, unsigned char time)
 Set the time to live for the socket descriptor.
static int getfamily (socket_t socket)
 Get the address family of the socket descriptor.
static int getfamily (struct sockaddr_storage &address)
 Get the address family of a socket address object.
static int getfamily (struct sockaddr_internet &address)
 Get the address family of an internet socket address object.
static ssize_t recvfrom (socket_t socket, void *buffer, size_t size, int flags=0, struct sockaddr_storage *address=((void *) 0))
 Get data waiting in receive queue.
static ssize_t sendto (socket_t socket, void *buffer, size_t size, int flags=0, struct sockaddr *address=((void *) 0))
 Send data on socket.
static ssize_t replyto (socket_t socket, void *buffer, size_t size, int flags, struct sockaddr_storage *address)
 Send reply on socket.
static ssize_t sendinet (socket_t socket, void *buffer, size_t size, int flags, struct sockaddr_internet *address)
 Send to internet socket.
static ssize_t recvinet (socket_t socket, void *buffer, size_t size, int flags=0, struct sockaddr_internet *address=((void *) 0))
 Get internet data waiting in receive queue.
static int bindto (socket_t socket, char *address, char *service, int protocol=0)
 Bind the socket descriptor to a known interface and service port.
static int listento (socket_t socket, struct sockaddr *address, int backlog=5)
 Bind the socket descriptor to a known interface listen on service port.
static int bindto (socket_t socket, struct sockaddr *address)
 Bind the socket descriptor to a known interface.
static socket_t acceptfrom (socket_t socket, struct sockaddr_storage *address=((void *) 0))
 Accept a socket connection from a remote host.
static socket_t create (int family, int type, int protocol)
 Create a socket object unbound.
static socket_t create (char *iface, char *service, int family=0, int type=0, int protocol=0, int backlog=0)
 Create a bound socket for a service.
static socket_t create (Socket::address &address)
 Create a connected socket for a service.
static void release (socket_t socket)
 Release (close) a socket.
static ssize_t sendto (Socket &socket, char *buffer, size_t size, struct sockaddr *address)
 Send to socket object.
static ssize_t recvfrom (Socket &socket, char *buffer, size_t size, struct sockaddr_storage *address)
 receive from socket object.
static void connectto (Socket &socket, Socket::address &address)
 Connect a socket.
static void disconnect (Socket &socket)
 Disconnect a connected socket.
static Socket acceptfrom (Socket &socket, struct sockaddr_storage *address)
 Accept connection through socket.
static char * gethostname (struct sockaddr *address, char *buffer, size_t size)
 Lookup and return the host name associated with a socket address.
static struct addrinfo * gethint (socket_t socket, struct addrinfo *hint)
 Create an address info lookup hint based on the family and type properties of a socket descriptor.
static socklen_t getaddr (socket_t socket, struct sockaddr_storage *address, char *hostname, char *service)
 Lookup a host name and service address based on the addressing family and socket type of a socket descriptor.
static socklen_t getlen (struct sockaddr *address)
 Get the size of a socket address.
static bool equal (struct sockaddr *address1, struct sockaddr *address2)
 Compare socket addresses.
static unsigned copy (struct sockaddr *target, struct sockaddr *origin)
 Copy a socket address.
static unsigned store (struct sockaddr_storage *storage, struct sockaddr *address)
 Store an address into an address object.
static unsigned store (struct sockaddr_internet *storage, struct sockaddr *address)
 Store an address into an internet address object.
static bool equalhost (struct sockaddr *address1, struct sockaddr *address2)
 Compare socket host addresses.
static bool equalfrom (struct sockaddr_storage *address1, struct sockaddr_storage *address2)
 Compare socket addresses.
static bool equalinet (struct sockaddr_internet *address1, struct sockaddr_internet *address2)
 Compare socket addresses.
static bool subnet (struct sockaddr *address1, struct sockaddr *address2)
 See if both addresses are in the same subnet.
static int getinterface (struct sockaddr *address, struct sockaddr *destination)
 Get the socket address of the interface needed to reach a destination address.
static char * getaddress (struct sockaddr *address, char *buffer, socklen_t size)
 Get the hostname of a socket address.
static short getservice (struct sockaddr *address)
 Get the service port of a socket.
static short inetservice (struct sockaddr_internet *address)
 Get the service port of an inet socket.
static unsigned keyindex (struct sockaddr *address, unsigned size)
 Convert a socket address and service into a hash map index.
static unsigned keyhost (struct sockaddr *address, unsigned size)
 Convert a socket host address into a hash map index.
static void init (void)
 Initialize socket subsystem.
static void family (int query)
 Set default socket family preference for query options when the socket type is otherwise not specified.
static void v4mapping (bool enable)
 Set the default socket behavior for v6-v4 mapping.
static FILE * open (socket_t socket, bool mode=false)
 Convert socket into FILE handle for reading.
static void close (FILE *file)
 Cleanly close a connected socket descriptor mapped to a file handle.
static int error (void)
 Return error code of last socket operation,.
static bool isNull (char *string)
 Simple function to validate that a given IP address string is a "zero" address.
static bool isNumeric (char *string)
 Simple function to validate that a given IP address string is a numeric address.

Protected Attributes

socket_t so

Friends

class address

Detailed Description

A generic socket base class.

This class can be used directly or as a base class for building network protocol stacks. This common base tries to handle UDP and TCP sockets, as well as support multicast, IPV4/IPV6 addressing, and additional addressing domains (such as Unix domain sockets).

Author:
David Sugar <dyfet@gnutelephony.org>

Definition at line 293 of file socket.h.


Constructor & Destructor Documentation

ucc::Socket::Socket ( Socket existing  ) 

Create socket as duped handle of existing socket.

Parameters:
existing socket to dup.

ucc::Socket::Socket ( socket_t  socket  ) 

Create socket from existing socket descriptor.

Parameters:
socket descriptor to use.

ucc::Socket::Socket ( struct addrinfo *  address  ) 

Create and connect a socket to an address from an address list.

The type of socket created is based on the type we are connecting to.

Parameters:
address list to connect with.

ucc::Socket::Socket ( int  family,
int  type,
int  protocol = 0 
)

Create an unbound socket of a specific type.

Parameters:
family of our new socket.
type (stream, udp, etc) of our new socket.
protocol number of our new socket.'

ucc::Socket::Socket ( char *  address,
char *  port,
int  family = 0,
int  type = 0,
int  protocol = 0,
int  backlog = 0 
)

Create a bound socket.

Parameters:
address to bind or "*" for all
port number of service to bind.
family to bind as.
type of socket to bind (stream, udp, etc).
protocol of socket to bind.
backlog for listening socket.


Member Function Documentation

static Socket ucc::Socket::acceptfrom ( Socket socket,
struct sockaddr_storage *  address 
) [inline, static]

Accept connection through socket.

Parameters:
socket object to accept from.
address accepting from.
Returns:
socket accepted.

Definition at line 1269 of file socket.h.

Here is the call graph for this function:

static socket_t ucc::Socket::acceptfrom ( socket_t  socket,
struct sockaddr_storage *  address = ((void *) 0) 
) [static]

Accept a socket connection from a remote host.

Parameters:
socket descriptor to accept from.
address of socket accepting.
Returns:
new socket accepted.

static int ucc::Socket::bindto ( socket_t  socket,
struct sockaddr *  address 
) [static]

Bind the socket descriptor to a known interface.

Parameters:
socket descriptor to bind.
address of interface to bind to.
Returns:
0 on success, -1 if error.

static int ucc::Socket::bindto ( socket_t  socket,
char *  address,
char *  service,
int  protocol = 0 
) [static]

Bind the socket descriptor to a known interface and service port.

Parameters:
socket descriptor to bind.
address to bind to or "*" for all.
service port to bind.
protocol to use or 0 if default.
Returns:
0 on success, -1 if error.

static int ucc::Socket::blocking ( socket_t  socket,
bool  enable 
) [static]

Set socket blocking I/O mode of socket descriptor.

Parameters:
socket descriptor.
enable true for blocking I/O.
Returns:
0 if success, -1 if error.

int ucc::Socket::blocking ( bool  enable  )  [inline]

Set socket blocking I/O mode.

Parameters:
enable true for blocking I/O.
Returns:
0 on success, -1 if error.

Definition at line 675 of file socket.h.

Here is the call graph for this function:

static int ucc::Socket::broadcast ( socket_t  socket,
bool  enable 
) [static]

Set socket for unicast mode broadcasts on socket descriptor.

Parameters:
socket descriptor.
enable broadcasting if true.
Returns:
0 if success, -1 if error.

int ucc::Socket::broadcast ( bool  enable  )  [inline]

Set socket for unicast mode broadcasts.

Parameters:
enable broadcasting if true.
Returns:
0 on success, -1 if error.

Definition at line 659 of file socket.h.

Here is the call graph for this function:

static void ucc::Socket::cancel ( socket_t  socket  )  [static]

Cancel pending i/o by shutting down the socket.

Parameters:
socket to shutdown.

static void ucc::Socket::close ( FILE *  file  )  [static]

Cleanly close a connected socket descriptor mapped to a file handle.

Parameters:
file handle to close.

static void ucc::Socket::connectto ( Socket socket,
Socket::address address 
) [inline, static]

Connect a socket.

Parameters:
socket object to connect.
address list to connect to.

Definition at line 1253 of file socket.h.

Here is the call graph for this function:

static int ucc::Socket::connectto ( socket_t  socket,
struct addrinfo *  list 
) [static]

Connect socket descriptor to a remote host from an address list.

For TCP (and DCCP) sockets, the entire list may be tried. For UDP, connect is only a state and the first valid entry in the list is used.

Parameters:
socket descriptor.
list of addresses to connect to.
Returns:
0 on success, -1 on error.

int ucc::Socket::connectto ( struct addrinfo *  list  )  [inline]

Connect our socket to a remote host from an address list.

For TCP (and DCCP) sockets, the entire list may be tried. For UDP, connect is only a state and the first valid entry in the list is used.

Parameters:
list of addresses to connect to.
Returns:
0 on success, -1 on error.

Definition at line 813 of file socket.h.

Here is the call graph for this function:

static unsigned ucc::Socket::copy ( struct sockaddr *  target,
struct sockaddr *  origin 
) [static]

Copy a socket address.

Parameters:
target address pointer to copy into.
origin address pointer to copy from.
Returns:
number of bytes copied, 0 if invalid.

static socket_t ucc::Socket::create ( Socket::address address  )  [static]

Create a connected socket for a service.

Parameters:
address of service for connect.
Returns:
socket desciptor.

static socket_t ucc::Socket::create ( char *  iface,
char *  service,
int  family = 0,
int  type = 0,
int  protocol = 0,
int  backlog = 0 
) [static]

Create a bound socket for a service.

Parameters:
iface to bind.
service port to bind.
family to select or AF_UNSPEC
type of socket to create.
protocol of socket to create.
backlog for listener.
Returns:
socket desciptor created or INVALID_SOCKET.

static socket_t ucc::Socket::create ( int  family,
int  type,
int  protocol 
) [static]

Create a socket object unbound.

Parameters:
family of socket.
type of socket.
protocol of socket.
Returns:
socket descriptor created or INVALID_SOCKET.

static void ucc::Socket::disconnect ( Socket socket  )  [inline, static]

Disconnect a connected socket.

Parameters:
socket object to disconnect.

Definition at line 1260 of file socket.h.

Here is the call graph for this function:

static int ucc::Socket::disconnect ( socket_t  socket  )  [static]

Disconnect a connected socket descriptor.

Parameters:
socket descriptor.
Returns:
0 on success, -1 on error.

int ucc::Socket::disconnect ( void   )  [inline]

Disconnect a connected socket.

Depending on the implimentation, this might be done by connecting to AF_UNSPEC, connecting to a 0 address, or connecting to self.

Returns:
0 on success, -1 on error.

Definition at line 822 of file socket.h.

Here is the call graph for this function:

static int ucc::Socket::drop ( socket_t  socket,
struct addrinfo *  list 
) [static]

Drop socket descriptor from multicast group.

Parameters:
socket descriptor.
list of groups to drop.
Returns:
0 on success, -1 on error.

int ucc::Socket::drop ( struct addrinfo *  list  )  [inline]

Drop socket from multicast group.

Parameters:
list of groups to drop.
Returns:
0 on success, -1 on error.

Definition at line 838 of file socket.h.

Here is the call graph for this function:

static bool ucc::Socket::equal ( struct sockaddr *  address1,
struct sockaddr *  address2 
) [static]

Compare socket addresses.

Test if the address and service matches or if there is no service, then just the host address values.

Parameters:
address1 to compare.
address2 to compare.
Returns:
true if same family and equal.

static bool ucc::Socket::equalfrom ( struct sockaddr_storage *  address1,
struct sockaddr_storage *  address2 
) [inline, static]

Compare socket addresses.

Test if the stored addresses received match. or if there is no service, then just the host address values.

Parameters:
address1 to compare.
address2 to compare.
Returns:
true if same family and equal.

Definition at line 1359 of file socket.h.

static bool ucc::Socket::equalhost ( struct sockaddr *  address1,
struct sockaddr *  address2 
) [static]

Compare socket host addresses.

Test if the host addressmatches or if there is no service, then just the host address values.

Parameters:
address1 to compare.
address2 to compare.
Returns:
true if same family and equal.

static bool ucc::Socket::equalinet ( struct sockaddr_internet *  address1,
struct sockaddr_internet *  address2 
) [inline, static]

Compare socket addresses.

Test if the internet addresses received match. or if there is no service, then just the host address values.

Parameters:
address1 to compare.
address2 to compare.
Returns:
true if same family and equal.

Definition at line 1369 of file socket.h.

static int ucc::Socket::error ( void   )  [static]

Return error code of last socket operation,.

Returns:
errno style error code.

static int ucc::Socket::error ( socket_t  socket  )  [static]

Get socket error code of socket descriptor.

Parameters:
socket descriptor.
Returns:
socket error code.

static void ucc::Socket::family ( int  query  )  [static]

Set default socket family preference for query options when the socket type is otherwise not specified.

Parameters:
query family to select.

virtual ssize_t ucc::Socket::get ( void *  data,
size_t  number,
struct sockaddr_storage *  address = ((void *) 0) 
) [virtual]

Read data from the socket receive buffer.

This is a virtual so that the ssl layer can override the core get method.

Parameters:
data pointer to save data in.
number of bytes to read.
address of peer data was received from.
Returns:
number of bytes actually read, 0 if none, -1 if error.

static socklen_t ucc::Socket::getaddr ( socket_t  socket,
struct sockaddr_storage *  address,
char *  hostname,
char *  service 
) [static]

Lookup a host name and service address based on the addressing family and socket type of a socket descriptor.

Store the result in a socket address structure.

Parameters:
socket descriptor.
address that is resolved.
hostname to resolve.
service port.
Returns:
socket address size.

static char* ucc::Socket::getaddress ( struct sockaddr *  address,
char *  buffer,
socklen_t  size 
) [static]

Get the hostname of a socket address.

Parameters:
address to lookup.
buffer to save hostname in.
size of hostname buffer.
Returns:
buffer if found or NULL if not.

int ucc::Socket::getError ( void   )  [inline]

Get socket error code.

Returns:
socket error code.

Definition at line 698 of file socket.h.

static int ucc::Socket::getfamily ( struct sockaddr_internet &  address  )  [inline, static]

Get the address family of an internet socket address object.

Parameters:
address to examine.
Returns:
address family.

Definition at line 1097 of file socket.h.

static int ucc::Socket::getfamily ( struct sockaddr_storage &  address  )  [inline, static]

Get the address family of a socket address object.

Parameters:
address to examine.
Returns:
address family.

Definition at line 1089 of file socket.h.

static int ucc::Socket::getfamily ( socket_t  socket  )  [static]

Get the address family of the socket descriptor.

Returns:
address family.

static struct addrinfo* ucc::Socket::gethint ( socket_t  socket,
struct addrinfo *  hint 
) [static, read]

Create an address info lookup hint based on the family and type properties of a socket descriptor.

Parameters:
socket descriptor.
hint buffer.
Returns:
hint buffer.

static char* ucc::Socket::gethostname ( struct sockaddr *  address,
char *  buffer,
size_t  size 
) [static]

Lookup and return the host name associated with a socket address.

Parameters:
address to lookup.
buffer to save hostname into.
size of buffer to save hostname into.
Returns:
buffer or NULL if lookup fails.

static int ucc::Socket::getinterface ( struct sockaddr *  address,
struct sockaddr *  destination 
) [static]

Get the socket address of the interface needed to reach a destination address.

Parameters:
address of interface found.
destination address.
Returns:
0 on success, -1 on error.

static socklen_t ucc::Socket::getlen ( struct sockaddr *  address  )  [static]

Get the size of a socket address.

Parameters:
address of socket.
Returns:
size to use for this socket address object.

unsigned ucc::Socket::getPending ( void   )  [inline]

Get the number of bytes of data in the socket receive buffer.

Returns:
bytes pending.

Definition at line 651 of file socket.h.

virtual ssize_t ucc::Socket::gets ( char *  data,
size_t  size,
timeout_t  timeout = Timer::inf 
) [virtual]

Read a newline of text data from the socket and save in NULL terminated string.

This uses an optimized I/O method that takes advantage of socket peeking. As such, it has to be rewritten to be used in a ssl layer socket.

Parameters:
data to save input line.
size of input line buffer.
timeout to wait for a complete input line.
Returns:
number of bytes read, 0 if none, -1 if error.

static short ucc::Socket::getservice ( struct sockaddr *  address  )  [static]

Get the service port of a socket.

Parameters:
address of socket to examine.
Returns:
service port number.

int ucc::Socket::gettype ( void   )  [inline]

Get the type of a socket.

Returns:
socket type.

Definition at line 761 of file socket.h.

Here is the call graph for this function:

static int ucc::Socket::gettype ( socket_t  socket  )  [static]

Get the type of a socket.

Parameters:
socket descriptor.
Returns:
socket type.

static short ucc::Socket::inetservice ( struct sockaddr_internet *  address  )  [inline, static]

Get the service port of an inet socket.

Parameters:
address of internet socket to examine.
Returns:
service port number.

Definition at line 1411 of file socket.h.

bool ucc::Socket::isConnected ( void   ) 

Test if socket is connected.

Returns:
true if connected.

static bool ucc::Socket::isNull ( char *  string  )  [static]

Simple function to validate that a given IP address string is a "zero" address.

Such address strings are used for example in SIP to indicate "hold" by re-inviting peers to a null address. Supports IPV4 and IPV6 addresses.

Parameters:
string address to check.
Returns:
true if zero/null address.

static bool ucc::Socket::isNumeric ( char *  string  )  [static]

Simple function to validate that a given IP address string is a numeric address.

This can be used to verify an address is not a "host" name. Supports IPV4 and IPV6 address strings.

Parameters:
string address to check.
Returns:
true if zero/null address.

bool ucc::Socket::isPending ( unsigned  value  ) 

See the number of bytes in the receive queue.

Parameters:
value to test for.
Returns:
true if at least that many bytes waiting in receive queue.

static int ucc::Socket::join ( socket_t  socket,
struct addrinfo *  list 
) [static]

Join socket descriptor to multicast group.

Parameters:
socket descriptor.
list of groups to join.
Returns:
0 on success, -1 on error.

int ucc::Socket::join ( struct addrinfo *  list  )  [inline]

Join socket to multicast group.

Parameters:
list of groups to join.
Returns:
0 on success, -1 on error.

Definition at line 830 of file socket.h.

Here is the call graph for this function:

static int ucc::Socket::keepalive ( socket_t  socket,
bool  enable 
) [static]

Set socket for keepalive packets for socket descriptor.

Parameters:
socket descriptor.
enable keep-alive if true.
Returns:
0 if success, -1 if error.

int ucc::Socket::keepalive ( bool  enable  )  [inline]

Set socket for keepalive packets.

Parameters:
enable keep-alive if true.
Returns:
0 on success, -1 if error.

Definition at line 667 of file socket.h.

Here is the call graph for this function:

static unsigned ucc::Socket::keyhost ( struct sockaddr *  address,
unsigned  size 
) [static]

Convert a socket host address into a hash map index.

Parameters:
address to convert.
size of map index.
Returns:
key index path.

static unsigned ucc::Socket::keyindex ( struct sockaddr *  address,
unsigned  size 
) [static]

Convert a socket address and service into a hash map index.

Parameters:
address to convert.
size of map index.
Returns:
key index path.

static int ucc::Socket::listento ( socket_t  socket,
struct sockaddr *  address,
int  backlog = 5 
) [static]

Bind the socket descriptor to a known interface listen on service port.

Parameters:
socket descriptor to bind.
address of interface to bind to.
backlog for service.
Returns:
0 on success, -1 if error.

static int ucc::Socket::loopback ( socket_t  socket,
bool  enable 
) [static]

Set loopback to read multicast packets socket descriptor broadcasts.

Parameters:
socket descriptor.
enable true to loopback, false to ignore.
Returns:
0 if success, -1 if error.

int ucc::Socket::loopback ( bool  enable  )  [inline]

Set loopback to read multicast packets we broadcast.

Parameters:
enable true to loopback, false to ignore.
Returns:
0 on success, -1 if error.

Definition at line 691 of file socket.h.

Here is the call graph for this function:

static int ucc::Socket::multicast ( socket_t  socket,
unsigned  ttl = 1 
) [static]

Set multicast mode and multicast broadcast range for socket descriptor.

Parameters:
socket descriptor.
ttl to set for multicast socket or 0 to disable multicast.
Returns:
0 if success, -1 if error.

int ucc::Socket::multicast ( unsigned  ttl = 1  )  [inline]

Set multicast mode and multicast broadcast range.

Parameters:
ttl to set for multicast socket or 0 to disable multicast.
Returns:
0 on success, -1 if error.

Definition at line 683 of file socket.h.

Here is the call graph for this function:

FILE* ucc::Socket::open ( bool  mode = false  )  [inline]

Get file handle for reading from a socket object.

Parameters:
mode of access, true for write mode.
Returns:
file handle.

Definition at line 1463 of file socket.h.

Here is the call graph for this function:

static FILE* ucc::Socket::open ( socket_t  socket,
bool  mode = false 
) [static]

Convert socket into FILE handle for reading.

Parameters:
socket descriptor to convert.
mode of access, true for write mode.
Returns:
file handle to use.

ucc::Socket::operator bool (  ) 

Test if socket is valid.

Returns:
true if valid socket.

ucc::Socket::operator socket_t (  )  [inline]

Get the socket descriptor by casting.

Returns:
socket descriptor of object.

Reimplemented in ucc::ListenSocket.

Definition at line 932 of file socket.h.

bool ucc::Socket::operator! (  ) 

Test if socket is invalid.

Returns:
true if socket is invalid.

socket_t ucc::Socket::operator* (  )  [inline]

Get the socket descriptor by pointer reference.

Returns:
socket descriptor of object.

Reimplemented in ucc::ListenSocket.

Definition at line 939 of file socket.h.

Socket& ucc::Socket::operator= ( socket_t  socket  ) 

Assign socket from a socket descriptor.

Release existing socket if one present.

Parameters:
socket descriptor to assign to object.

size_t ucc::Socket::peek ( void *  data,
size_t  number 
)

Peek at data waiting in the socket receive buffer.

Parameters:
data pointer to save data in.
number of bytes to peek.
Returns:
number of bytes actually read, or 0 if no data waiting.

static unsigned ucc::Socket::pending ( socket_t  socket  )  [static]

Get the number of bytes pending in the receive buffer of a socket descriptor.

Parameters:
socket descriptor.
Returns:
number of pending bytes.

static ssize_t ucc::Socket::printf ( socket_t  socket,
char *  format,
  ... 
) [static]

Print formatted string to socket.

Parameters:
socket to write to.
format string.
Returns:
number of bytes sent, -1 if error.

static int ucc::Socket::priority ( socket_t  socket,
int  scheduling 
) [static]

Set packet priority of socket descriptor.

Parameters:
socket descriptor.
scheduling priority for packet scheduling.
Returns:
0 on success, -1 on error.

int ucc::Socket::priority ( int  scheduling  )  [inline]

Set packet priority, 0 to 6 unless privileged.

Should be set before type-of-service.

Parameters:
scheduling priority for packet scheduling.
Returns:
0 on success, -1 on error.

Definition at line 797 of file socket.h.

Here is the call graph for this function:

virtual ssize_t ucc::Socket::put ( void *  data,
size_t  number,
struct sockaddr *  address = ((void *) 0) 
) [virtual]

Write data to the socket send buffer.

This is a virtual so that the ssl layer can override the core put method.

Parameters:
data pointer to write data from.
number of bytes to write.
address of peer to send data to if not connected.
Returns:
number of bytes actually sent, 0 if none, -1 if error.

ssize_t ucc::Socket::puts ( char *  string  ) 

Write a null terminated string to the socket.

Parameters:
string to write.
Returns:
number of bytes sent, 0 if none, -1 if error.

static ssize_t ucc::Socket::readline ( socket_t  socket,
char *  data,
size_t  size,
timeout_t  timeout = Timer::inf 
) [static]

Read a newline of text data from the socket and save in NULL terminated string.

This uses an optimized I/O method that takes advantage of socket peeking. As such, it has to be rewritten to be used in a ssl layer socket.

Parameters:
socket to read from.
data to save input line.
size of input line buffer.
timeout to wait for a complete input line.
Returns:
number of bytes read, 0 if none, -1 if error.

static ssize_t ucc::Socket::recvfrom ( Socket socket,
char *  buffer,
size_t  size,
struct sockaddr_storage *  address 
) [inline, static]

receive from socket object.

Parameters:
socket object to recv from.
buffer to recv.
size of buffer to recv.
address receving from or NULL if connected.
Returns:
number of bytes received, -1 if error.

Definition at line 1245 of file socket.h.

Here is the call graph for this function:

static ssize_t ucc::Socket::recvfrom ( socket_t  socket,
void *  buffer,
size_t  size,
int  flags = 0,
struct sockaddr_storage *  address = ((void *) 0) 
) [static]

Get data waiting in receive queue.

Parameters:
socket to get from.
buffer to save.
size of data buffer to request.
flags for i/o operation (MSG_OOB, MSG_PEEK, etc).
address of source.
Returns:
number of bytes received, -1 if error.

static ssize_t ucc::Socket::recvinet ( socket_t  socket,
void *  buffer,
size_t  size,
int  flags = 0,
struct sockaddr_internet *  address = ((void *) 0) 
) [static]

Get internet data waiting in receive queue.

Parameters:
socket to get from.
buffer to save.
size of data buffer to request.
flags for i/o operation (MSG_OOB, MSG_PEEK, etc).
address of source.
Returns:
number of bytes received, -1 if error.

static int ucc::Socket::recvsize ( socket_t  socket,
unsigned  size 
) [static]

Set the receive size of a socket descriptor.

Parameters:
socket descriptor.
size of receive buffer to set.
Returns:
0 on success, -1 on error.

int ucc::Socket::recvsize ( unsigned  size  )  [inline]

Set the size of the socket receive buffer.

Parameters:
size of recv buffer to set.
Returns:
0 on success, -1 on error.

Definition at line 731 of file socket.h.

Here is the call graph for this function:

static void ucc::Socket::release ( socket_t  socket  )  [static]

Release (close) a socket.

Parameters:
socket to close.

static ssize_t ucc::Socket::replyto ( socket_t  socket,
void *  buffer,
size_t  size,
int  flags,
struct sockaddr_storage *  address 
) [inline, static]

Send reply on socket.

Used to reply to a recvfrom message.

Parameters:
socket to send to.
buffer to send.
size of data buffer to send.
flags for i/o operation (MSG_OOB, MSG_PEEK, etc).
address to reply to.
Returns:
number of bytes sent, -1 if error.

Definition at line 1131 of file socket.h.

unsigned ucc::Socket::segsize ( unsigned  size  )  [inline]

Set segment size and get mtu of a socket.

Parameters:
segment size to set or 0 to leave unchanged.
Returns:
mtu size.

Definition at line 769 of file socket.h.

Here is the call graph for this function:

static unsigned ucc::Socket::segsize ( socket_t  socket,
unsigned  size = 0 
) [static]

Set segment size and get MTU.

Parameters:
socket to modify.
segment size or zero to not set.
Returns:
mtu size of socket.

static ssize_t ucc::Socket::sendinet ( socket_t  socket,
void *  buffer,
size_t  size,
int  flags,
struct sockaddr_internet *  address 
) [inline, static]

Send to internet socket.

Parameters:
socket to send to.
buffer to send.
size of data buffer to send.
flags for i/o operation (MSG_OOB, MSG_PEEK, etc).
address to send to.
Returns:
number of bytes sent, -1 if error.

Definition at line 1143 of file socket.h.

static int ucc::Socket::sendsize ( socket_t  socket,
unsigned  size 
) [static]

Set the send size of a socket descriptor.

Parameters:
socket descriptor.
size of send buffer to set.
Returns:
0 on success, -1 on error.

int ucc::Socket::sendsize ( unsigned  size  )  [inline]

Set the size of the socket send buffer.

Parameters:
size of send buffer to set.
Returns:
0 on success, -1 on error.

Definition at line 714 of file socket.h.

Here is the call graph for this function:

static ssize_t ucc::Socket::sendto ( Socket socket,
char *  buffer,
size_t  size,
struct sockaddr *  address 
) [inline, static]

Send to socket object.

Parameters:
socket object to send thru.
buffer to send.
size of buffer to send.
address to send to or NULL if connected.
Returns:
number of bytes send, -1 if error.

Definition at line 1234 of file socket.h.

Here is the call graph for this function:

static ssize_t ucc::Socket::sendto ( socket_t  socket,
void *  buffer,
size_t  size,
int  flags = 0,
struct sockaddr *  address = ((void *) 0) 
) [static]

Send data on socket.

Parameters:
socket to send to.
buffer to send.
size of data buffer to send.
flags for i/o operation (MSG_OOB, MSG_PEEK, etc).
address of destination, NULL if connected.
Returns:
number of bytes sent, -1 if error.

static int ucc::Socket::sendwait ( socket_t  socket,
unsigned  size 
) [static]

Set the size to wait before sending.

Parameters:
socket descriptor.
size of send wait buffer to set.
Returns:
0 on success, -1 on error.

int ucc::Socket::sendwait ( unsigned  size  )  [inline]

Set the size to wait before sending.

Parameters:
size of send wait buffer to set.
Returns:
0 on success, -1 on error.

Definition at line 722 of file socket.h.

Here is the call graph for this function:

bool ucc::Socket::setccid ( uint8_t  ccid  )  [inline]

Set ccid of dccp socket.

Parameters:
ccid to set.
Returns:
true if success, false if not dccp or not supported ccid used.

Definition at line 777 of file socket.h.

Here is the call graph for this function:

static bool ucc::Socket::setccid ( socket_t  socket,
uint8_t  ccid 
) [static]

Set congestion control id.

Parameters:
socket to modify.
ccid value to set.
Returns:
true if success, false if not dccp or not supported ccid used.

static unsigned ucc::Socket::store ( struct sockaddr_internet *  storage,
struct sockaddr *  address 
) [static]

Store an address into an internet address object.

Parameters:
storage for address.
address to store.
Returns:
number of bytes stored.

static unsigned ucc::Socket::store ( struct sockaddr_storage *  storage,
struct sockaddr *  address 
) [inline, static]

Store an address into an address object.

Parameters:
storage for address.
address to store.
Returns:
number of bytes stored.

Definition at line 1332 of file socket.h.

Here is the call graph for this function:

static bool ucc::Socket::subnet ( struct sockaddr *  address1,
struct sockaddr *  address2 
) [static]

See if both addresses are in the same subnet.

This is only relevent to IPV4 and class domain routing.

Parameters:
address1 to test.
address2 to test.
Returns:
true if in same subnet.

static int ucc::Socket::tos ( socket_t  socket,
int  type 
) [static]

Set type of service of socket descriptor.

Parameters:
socket descriptor.
type of service.
Returns:
0 on success, -1 on error.

int ucc::Socket::tos ( int  type  )  [inline]

Set the type of service field of outgoing packets.

Some useful values include IPTOS_LOWDELAY to minimize delay for interactive traffic, IPTOS_THROUGHPUT to optimize thoughput, OPTOS_RELIABILITY to optimize for reliability, and IPTOS_MINCOST for low speed use.

Parameters:
type of service value.
Returns:
0 on success or -1 on error.

Definition at line 788 of file socket.h.

Here is the call graph for this function:

static int ucc::Socket::ttl ( socket_t  socket,
unsigned char  time 
) [static]

Set the time to live for the socket descriptor.

Parameters:
socket descriptor.
time to live to set.
Returns:
0 on success, -1 on error.

int ucc::Socket::ttl ( unsigned char  time  )  [inline]

Set the time to live before packets expire.

Parameters:
time to live to set.
Returns:
0 on success, -1 on error.

Definition at line 706 of file socket.h.

Here is the call graph for this function:

static void ucc::Socket::v4mapping ( bool  enable  )  [static]

Set the default socket behavior for v6-v4 mapping.

This also effects v6 address lookup as to whether v4 remapped addresses can be used if no v6 address is found.

Parameters:
enable true to set mapping. This is default.

static bool ucc::Socket::wait ( socket_t  socket,
timeout_t  timeout = 0 
) [static]

Test for pending input data.

This function can wait up to a specified timeout for data to appear.

Parameters:
socket to test.
timeout or 0 if none.
Returns:
true if input data waiting.

bool ucc::Socket::waitPending ( timeout_t  timeout = 0  ) 

Test for pending input data.

This function can wait up to a specified timeout for data to appear.

Parameters:
timeout or 0 if none.
Returns:
true if input data waiting.

bool ucc::Socket::waitSending ( timeout_t  timeout = 0  ) 

Test for output data sent.

This function can wait up to a specified timeout for data to appear sent.

Parameters:
timeout or 0 if none.
Returns:
false if cannot send more output/out of buffer space.


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

Generated on Wed May 13 09:13:12 2009 for UCommon by  doxygen 1.5.8