IBR-DTNSuite  0.10
ibrcommon::basesocket Class Referenceabstract

#include <socket.h>

Inheritance diagram for ibrcommon::basesocket:
Inheritance graph
Collaboration diagram for ibrcommon::basesocket:
Collaboration graph

Public Member Functions

virtual ~basesocket ()=0
 
virtual void up ()=0 throw (socket_exception)
 
virtual void down ()=0 throw (socket_exception)
 
virtual int fd () const throw (socket_exception)
 
virtual int release () throw (socket_exception)
 
void close () throw (socket_exception)
 
void shutdown (int how) throw (socket_exception)
 
bool ready () const
 
sa_family_t get_family () const throw (socket_exception)
 

Static Public Member Functions

static sa_family_t get_family (int fd) throw (socket_exception)
 
static bool hasSupport (const sa_family_t family, const int type=SOCK_DGRAM, const int protocol=0) throw ()
 

Static Public Attributes

static int DEFAULT_SOCKET_FAMILY = AF_INET6
 
static int DEFAULT_SOCKET_FAMILY_ALTERNATIVE = AF_INET
 

Protected Types

enum  socketstate { SOCKET_DOWN, SOCKET_UP, SOCKET_UNMANAGED, SOCKET_DESTROYED }
 

Protected Member Functions

 basesocket ()
 
 basesocket (int fd)
 
void check_socket_error (const int err) const throw (socket_exception)
 
void check_bind_error (const int err, const std::string &msg="") const throw (socket_exception)
 
void set_blocking_mode (bool val, int fd=-1) const throw (socket_exception)
 
void set_keepalive (bool val, int fd=-1) const throw (socket_exception)
 
void set_linger (bool val, int l=1, int fd=-1) const throw (socket_exception)
 
void set_reuseaddr (bool val, int fd=-1) const throw (socket_exception)
 
void set_nodelay (bool val, int fd=-1) const throw (socket_exception)
 
void init_socket (const vaddress &addr, int type, int protocol) throw (socket_exception)
 
void init_socket (int domain, int type, int protocol) throw (socket_exception)
 
void bind (int fd, struct sockaddr *addr, socklen_t len) throw (socket_exception)
 

Protected Attributes

socketstate _state
 
int _fd
 
sa_family_t _family
 

Detailed Description

The basesocket is an interface for all kinds of sockets. The methods allows to bring the socket up or down.

Definition at line 103 of file socket.h.

Member Enumeration Documentation

The socket state determine if the socket file descriptor is usable or not.

Enumerator
SOCKET_DOWN 

SOCKET_DOWN.

SOCKET_UP 

SOCKET_UP.

SOCKET_UNMANAGED 

SOCKET_UNMANAGED.

SOCKET_DESTROYED 

SOCKET_DESTROYED.

Definition at line 166 of file socket.h.

Constructor & Destructor Documentation

ibrcommon::basesocket::~basesocket ( )
pure virtual

Definition at line 61 of file socket.cpp.

References _fd, _state, SOCKET_DESTROYED, and SOCKET_DOWN.

ibrcommon::basesocket::basesocket ( )
protected

This is a protected constructor to prevent any direct instantiation.

Parameters
fdAn existing file descriptor to use.

Definition at line 51 of file socket.cpp.

ibrcommon::basesocket::basesocket ( int  fd)
protected

Definition at line 56 of file socket.cpp.

Member Function Documentation

void ibrcommon::basesocket::bind ( int  fd,
struct sockaddr *  addr,
socklen_t  len 
) throw (socket_exception)
protected

Definition at line 240 of file socket.cpp.

References ibrcommon::vaddress::toString().

Referenced by ibrcommon::tcpserversocket::bind(), ibrcommon::udpsocket::bind(), and ibrcommon::lowpansocket::up().

Here is the call graph for this function:

void ibrcommon::basesocket::check_bind_error ( const int  err,
const std::string &  msg = "" 
) const throw (socket_exception)
protected

Definition at line 1279 of file socket.cpp.

void ibrcommon::basesocket::check_socket_error ( const int  err) const throw (socket_exception)
protected

Error check methods

Definition at line 1248 of file socket.cpp.

virtual void ibrcommon::basesocket::down ( ) throw (socket_exception)
pure virtual
int ibrcommon::basesocket::fd ( ) const throw (socket_exception)
virtual

Return the file descriptor for this socket.

Exceptions
socket_exceptionif no file descriptor is available

Definition at line 69 of file socket.cpp.

References _fd, _state, SOCKET_DESTROYED, and SOCKET_DOWN.

Referenced by close(), dtn::net::inotifysocket::down(), release(), ibrcommon::vsocket::select(), and ibrcommon::tcpsocket::up().

sa_family_t ibrcommon::basesocket::get_family ( ) const throw (socket_exception)

return the family of a socket

Returns

Definition at line 176 of file socket.cpp.

References _family.

Referenced by ibrcommon::multicastsocket::down(), and ibrcommon::multicastsocket::up().

sa_family_t ibrcommon::basesocket::get_family ( int  fd) throw (socket_exception)
static

Definition at line 181 of file socket.cpp.

bool ibrcommon::basesocket::hasSupport ( const sa_family_t  family,
const int  type = SOCK_DGRAM,
const int  protocol = 0 
) throw ()
static

Checks if the given network protocol is supported

Definition at line 196 of file socket.cpp.

Referenced by dtn::api::ApiServer::ApiServer().

void ibrcommon::basesocket::init_socket ( const vaddress addr,
int  type,
int  protocol 
) throw (socket_exception)
protected
void ibrcommon::basesocket::init_socket ( int  domain,
int  type,
int  protocol 
) throw (socket_exception)
protected

Definition at line 232 of file socket.cpp.

bool ibrcommon::basesocket::ready ( ) const
Returns
True, if this socket is up and ready.

Definition at line 115 of file socket.cpp.

References _state, SOCKET_UNMANAGED, and SOCKET_UP.

Referenced by ibrcommon::vsocket::select().

int ibrcommon::basesocket::release ( ) throw (socket_exception)
virtual

Return the file descriptor and bring the socket into the down state to keep the file descriptor alive even if the socket object gets destroyed.

Returns
The file descriptor of this socket.

Definition at line 75 of file socket.cpp.

References _fd, _state, fd(), SOCKET_DESTROYED, SOCKET_DOWN, and SOCKET_UP.

Referenced by ibrcommon::tcpsocket::up().

Here is the call graph for this function:

void ibrcommon::basesocket::set_blocking_mode ( bool  val,
int  fd = -1 
) const throw (socket_exception)
protected

Definition at line 120 of file socket.cpp.

Referenced by ibrcommon::serversocket::set(), and ibrcommon::tcpsocket::up().

void ibrcommon::basesocket::set_keepalive ( bool  val,
int  fd = -1 
) const throw (socket_exception)
protected

Definition at line 138 of file socket.cpp.

void ibrcommon::basesocket::set_linger ( bool  val,
int  l = 1,
int  fd = -1 
) const throw (socket_exception)
protected

Definition at line 147 of file socket.cpp.

void ibrcommon::basesocket::set_nodelay ( bool  val,
int  fd = -1 
) const throw (socket_exception)
protected

Definition at line 168 of file socket.cpp.

void ibrcommon::basesocket::set_reuseaddr ( bool  val,
int  fd = -1 
) const throw (socket_exception)
protected

Definition at line 159 of file socket.cpp.

Referenced by ibrcommon::tcpserversocket::up(), and ibrcommon::udpsocket::up().

void ibrcommon::basesocket::shutdown ( int  how) throw (socket_exception)

Definition at line 103 of file socket.cpp.

virtual void ibrcommon::basesocket::up ( ) throw (socket_exception)
pure virtual

Member Data Documentation

sa_family_t ibrcommon::basesocket::_family
protected

Definition at line 205 of file socket.h.

Referenced by get_family().

int ibrcommon::basesocket::DEFAULT_SOCKET_FAMILY = AF_INET6
static

Definition at line 105 of file socket.h.

int ibrcommon::basesocket::DEFAULT_SOCKET_FAMILY_ALTERNATIVE = AF_INET
static

Definition at line 106 of file socket.h.


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