xvr2::Net::Socket Class Reference

#include <xvr2/Net/Socket.h>

Inheritance diagram for xvr2::Net::Socket:

Inheritance graph
[legend]

List of all members.


Detailed Description

Network sockets main interface class.

Definition at line 31 of file Socket.h.


Public Member Functions

 Socket ()
 Default constructor.
 Socket (const Socket &s)
 Copy constructor.
virtual ~Socket ()
 Virtual destructor.
virtual void close ()
 Closes the socket so it wont send nor receive data.
void bind (const IPv4Address &ip)
 Binds this socket to a specified address.
bool debug (bool enabled)
 Puts or takes out the socket from debug mode.
bool debug ()
 Tells wheter the socket is currently in debug mode or not.
bool reuseAddr (bool enabled)
 Activates port re-usage, use with care.
bool reuseAddr ()
 Tells wheter this socket has a reusable port or not.
bool keepalive (bool enabled)
 Enables connection keepalive if the protocol supports it.
bool keepalive ()
 Tells wheter the socket is using keepalives or not.
bool dontroute (bool enabled)
 Tells the socket to send data directly to the peer interface bypassing any routin facilities.
bool dontroute ()
 Tell wheter this socket is bypassing routing or not.
void linger (bool enabled, int secs=1)
 Controls what to do when the connection is closed and there's still data waiting to sent over the channel.
int linger ()
 Tells wheter this socket is lingering.
bool broadcast (bool enabled)
 Enables transmision broadcast for datagram based sockets.
bool broadcast ()
 Tells wheter broadcasting has been enabled for this socket or not.
bool recvOOBInline (bool enabled)
 Enables the recival of out of band (urgent) data in the same channel we're reading, use with care.
bool recvOOBInline ()
 Tells wheter the receival of out of band data is enabled or not.
int sendBufSize (int newsize)
 Changes the send buffer size value.
int sendBufSize ()
 Tells how big is the send buffer size.
int recvBufSize (int newsize)
 Changes the receive buffer size value.
int recvBufSize ()
 Tells how big is the receive buffer size.
bool isStream ()
 Tells wheter this is a stream socket (a connected socket).
bool isDatagram ()
 Tells wheter this is a datagram socket.
bool isRaw ()
 Tells wheter this is a raw socket.
bool isIPv4 ()
 Tells wheter this socket has been created to be used with ipv4 naming space conventions.
bool isIPv6 ()
 Tells wheter this socket has been created to be used with ipv6 naming space conventions.
virtual const char * getClassName ()
 Returns the name of the current class.
virtual std::string toString ()

Static Public Member Functions

static void debugmsg (Object *obj, const char *msg, int linenumber=__LINE__, const char *srcfile=__FILE__)
 Will print a debug message to the screen.
static void debugmsgln (Object *obj, const char *msg, int linenumber=__LINE__, const char *srcfile=__FILE__)

Protected Member Functions

virtual void create (int protoid=0)=0
 Polymorphic socket creation method.
virtual void getsockopt (int level, int optname, void *optval, socklen_t *optlen)
 Retrieves the value of the specified option at the given level for this socket.
virtual void setsockopt (int level, int optname, const void *optval, socklen_t optlen)
 Sets the value of the specified option at the given level for this socket.

Protected Attributes

int _socket
 This is the socket file descriptor per se.
bool is_ipv4
 Controls wheter this is an ipv4 socket or not, if not, then it is considered to be ipv6.
std::string __cls_name

Friends

std::ostream & operator<< (std::ostream &stream, const Object &s)

Constructor & Destructor Documentation

xvr2::Net::Socket::Socket (  ) 

Default constructor.

xvr2::Net::Socket::Socket ( const Socket s  ) 

Copy constructor.

Builds a new Socket instance from another.

Parameters:
s Source socket object from where we will be intantiating.

virtual xvr2::Net::Socket::~Socket (  )  [virtual]

Virtual destructor.


Member Function Documentation

virtual void xvr2::Net::Socket::create ( int  protoid = 0  )  [protected, pure virtual]

Polymorphic socket creation method.

Each Socket subclass must provide its own socket creation method according to the protocol their handling. Internally this method only takes care of creating the socket file destriptor and setting some basic options depending on the protocol to be used.

Implemented in xvr2::Net::TCPSocket.

virtual void xvr2::Net::Socket::getsockopt ( int  level,
int  optname,
void *  optval,
socklen_t *  optlen 
) [protected, virtual]

Retrieves the value of the specified option at the given level for this socket.

Parameters:
level Option level, OS-dependent.
optname Option name to be changed.
optval Holds the buffer where value will be saved.
optlen Is the output buffer size.
Exceptions:
xvr2::Net::SocketOptionException 
xvr2::Net::SocketOptionParamFailure 
xvr2::Net::SocketOptionIsInvalid 

virtual void xvr2::Net::Socket::setsockopt ( int  level,
int  optname,
const void *  optval,
socklen_t  optlen 
) [protected, virtual]

Sets the value of the specified option at the given level for this socket.

Parameters:
level Option level, OS-dependent.
optname Option name to be changed.
optval Value to set the option.
optlen Holds the optval datasize.
Exceptions:
xvr2::Net::SocketOptionException 
xvr2::Net::SocketOptionParamFailure 
xvr2::Net::SocketOptionIsInvalid 

virtual void xvr2::Net::Socket::close (  )  [virtual]

Closes the socket so it wont send nor receive data.

void xvr2::Net::Socket::bind ( const IPv4Address ip  ) 

Binds this socket to a specified address.

Binding will let you configure this socket to listen or send data from a specific local address, very useful for server applications on machines with multiple interfaces since sometimes you just want to send/receive data to/from a specific interface, however the same can be done with client apps.

Parameters:
ip IP address assigned to the local interface to be binded from.

bool xvr2::Net::Socket::debug ( bool  enabled  ) 

Puts or takes out the socket from debug mode.

This method will activate the recording of debug information based on the used protocol, use this method carefully it is very OS dependent.

Parameters:
[in] enabled If true it will enable debug mode for the socket, if false it will disable debug mode.
Returns:
The previous debug mode state.

bool xvr2::Net::Socket::debug (  ) 

Tells wheter the socket is currently in debug mode or not.

Returns:
true if the socket is in debug mode, false otherwise

bool xvr2::Net::Socket::reuseAddr ( bool  enabled  ) 

Activates port re-usage, use with care.

This method will allow a port to be re-used even if the socket has already been binded, as a result you can have multiple sockets binded to the same port.

Parameters:
enabled If true enables port reuse.
Returns:
The previous value.

bool xvr2::Net::Socket::reuseAddr (  ) 

Tells wheter this socket has a reusable port or not.

Returns:
true if it is reusable, false if not.

bool xvr2::Net::Socket::keepalive ( bool  enabled  ) 

Enables connection keepalive if the protocol supports it.

This option activates/deactivates sending keepalives to the remote peer, this keepalives are messages sent peridically in order to determine if the connection has benn broken or not, if a response to the message is not recieved, then the connection is considered broken.

Parameters:
enabled If true, the keepalive function will be enabled, if false then it will be disabled.
Returns:
The previous value.

bool xvr2::Net::Socket::keepalive (  ) 

Tells wheter the socket is using keepalives or not.

Returns:
true if keepalives are active, false otherwise.

bool xvr2::Net::Socket::dontroute ( bool  enabled  ) 

Tells the socket to send data directly to the peer interface bypassing any routin facilities.

Parameters:
enabled If true, the messages will be sent directly to the peer interface, if false outgoing messages won't bypass routing.
Returns:
The previous value.

bool xvr2::Net::Socket::dontroute (  ) 

Tell wheter this socket is bypassing routing or not.

Returns:
true if it is bypassing routing, false if not .

void xvr2::Net::Socket::linger ( bool  enabled,
int  secs = 1 
)

Controls what to do when the connection is closed and there's still data waiting to sent over the channel.

Parameters:
enabled if true the close() method will get blocked until all data has benn transmited to the other side, if false then a call close will return inmediately or until the secs period has expired.
secs timeout before effectively closing the socket in case it still has messages to send.

int xvr2::Net::Socket::linger (  ) 

Tells wheter this socket is lingering.

Returns:
0 if it is not lingering, otherwise the number of seconds used as timeout before effectively closing the channel.

bool xvr2::Net::Socket::broadcast ( bool  enabled  ) 

Enables transmision broadcast for datagram based sockets.

Parameters:
enabled If true, datagram broadcasting is enabled, if false then it will be disabled.
Returns:
The previous value.

bool xvr2::Net::Socket::broadcast (  ) 

Tells wheter broadcasting has been enabled for this socket or not.

Returns:
true if bradcasts are enabled, false otherwise.

bool xvr2::Net::Socket::recvOOBInline ( bool  enabled  ) 

Enables the recival of out of band (urgent) data in the same channel we're reading, use with care.

Parameters:
enabled if true enables inline out of band receiving, if false disables it.

bool xvr2::Net::Socket::recvOOBInline (  ) 

Tells wheter the receival of out of band data is enabled or not.

Returns:
true if is enabled, false otherwise.

int xvr2::Net::Socket::sendBufSize ( int  newsize  ) 

Changes the send buffer size value.

Returns:
the previous value.

int xvr2::Net::Socket::sendBufSize (  ) 

Tells how big is the send buffer size.

Returns:
send buffer size in bytes.

int xvr2::Net::Socket::recvBufSize ( int  newsize  ) 

Changes the receive buffer size value.

Returns:
the previous value.

int xvr2::Net::Socket::recvBufSize (  ) 

Tells how big is the receive buffer size.

Returns:
send buffer size in bytes.

bool xvr2::Net::Socket::isStream (  ) 

Tells wheter this is a stream socket (a connected socket).

Returns:
true if it is a stream socket, false if not.

bool xvr2::Net::Socket::isDatagram (  ) 

Tells wheter this is a datagram socket.

A datagram is a communication style whose purpose is to send individually addressed packets unreliably (much like UDP).

Returns:
true if this is a datagram socket, false if not.

bool xvr2::Net::Socket::isRaw (  ) 

Tells wheter this is a raw socket.

Raw sockets are used to access low-level features of communication protocols, sniffer and other type of applications use this type of communication.

Returns:
true if it is a raw socket, false if not.

bool xvr2::Net::Socket::isIPv4 (  ) 

Tells wheter this socket has been created to be used with ipv4 naming space conventions.

bool xvr2::Net::Socket::isIPv6 (  ) 

Tells wheter this socket has been created to be used with ipv6 naming space conventions.

virtual const char* xvr2::Object::getClassName (  )  [virtual, inherited]

Returns the name of the current class.

static void xvr2::Object::debugmsg ( Object obj,
const char *  msg,
int  linenumber = __LINE__,
const char *  srcfile = __FILE__ 
) [static, inherited]

Will print a debug message to the screen.

static void xvr2::Object::debugmsgln ( Object obj,
const char *  msg,
int  linenumber = __LINE__,
const char *  srcfile = __FILE__ 
) [static, inherited]

virtual std::string xvr2::Object::toString (  )  [virtual, inherited]


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  stream,
const Object s 
) [friend, inherited]


Member Data Documentation

int xvr2::Net::Socket::_socket [protected]

This is the socket file descriptor per se.

Definition at line 35 of file Socket.h.

bool xvr2::Net::Socket::is_ipv4 [protected]

Controls wheter this is an ipv4 socket or not, if not, then it is considered to be ipv6.

Definition at line 38 of file Socket.h.

std::string xvr2::Object::__cls_name [protected, inherited]

Definition at line 30 of file Object.h.


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

Generated on Fri Jun 20 22:56:03 2008 for X-VR2 SDK by  doxygen 1.5.5