xvr2::Net::TCPSocket Class Reference

#include <xvr2/Net/TCPSocket.h>

Inheritance diagram for xvr2::Net::TCPSocket:

Inheritance graph
[legend]

List of all members.


Detailed Description

TCP client socket class.

By working with objects of type TCPSocket you'll be able to connect to remote peers via the TCP/IP protocol using the a variety of ip address namings, like IPv4 and IPv6.

Definition at line 29 of file TCPSocket.h.


Public Member Functions

 TCPSocket ()
 Default constructor.
 TCPSocket (const IPv4Address &addr, int port)
 Instantiates a TCP socket and connects it to the specified internet address and port.
 TCPSocket (const TCPSocket &s)
 Copy constructor.
 TCPSocket (int fd)
 Instatiates a socket from the given file descriptor id.
 ~TCPSocket ()
 Mandatory destructor.
void connect (const IPv4Address &addr, int port)
 Connects the specified TCPSocket to the given address.
RawSocketOutputStreaminputStream ()
 Returns the associated input address for writing operations.
RawSocketInputStreamoutputStream ()
 Returns the associated output address for reading operations.
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

void create (int protoid=0)
 Initializes the socket itself, and ensures it will be created for use in the internet namespace.
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

RawSocketInputStream out
 Output stream object.
RawSocketOutputStream in
 Input stream object.
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::TCPSocket::TCPSocket (  ) 

Default constructor.

Initializes the socket but does not connect to anything, since a destinarion address and port has not been specified.

xvr2::Net::TCPSocket::TCPSocket ( const IPv4Address addr,
int  port 
)

Instantiates a TCP socket and connects it to the specified internet address and port.

Parameters:
addr IPv4 destination address.
port destination port number.

xvr2::Net::TCPSocket::TCPSocket ( const TCPSocket s  ) 

Copy constructor.

Instantiates this object from the properties of another TCPSocket, the result will be an exact copy, this new copy will even share the connection state of the socket it was copied from.

xvr2::Net::TCPSocket::TCPSocket ( int  fd  ) 

Instatiates a socket from the given file descriptor id.

xvr2::Net::TCPSocket::~TCPSocket (  ) 

Mandatory destructor.


Member Function Documentation

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

Initializes the socket itself, and ensures it will be created for use in the internet namespace.

Implements xvr2::Net::Socket.

void xvr2::Net::TCPSocket::connect ( const IPv4Address addr,
int  port 
) [virtual]

Connects the specified TCPSocket to the given address.

Parameters:
addr IPv4 destination address.
port destination port number.

Implements xvr2::Net::ClientSocket.

RawSocketOutputStream& xvr2::Net::ClientSocket::inputStream (  )  [inherited]

Returns the associated input address for writing operations.

Returns:
a stream from where you can send data through this socket.

RawSocketInputStream& xvr2::Net::ClientSocket::outputStream (  )  [inherited]

Returns the associated output address for reading operations.

Returns:
a stream from where you can receive data through this socket.

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

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, inherited]

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, inherited]

Closes the socket so it wont send nor receive data.

void xvr2::Net::Socket::bind ( const IPv4Address ip  )  [inherited]

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  )  [inherited]

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 (  )  [inherited]

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  )  [inherited]

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 (  )  [inherited]

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  )  [inherited]

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 (  )  [inherited]

Tells wheter the socket is using keepalives or not.

Returns:
true if keepalives are active, false otherwise.

bool xvr2::Net::Socket::dontroute ( bool  enabled  )  [inherited]

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 (  )  [inherited]

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 
) [inherited]

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 (  )  [inherited]

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  )  [inherited]

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 (  )  [inherited]

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  )  [inherited]

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 (  )  [inherited]

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  )  [inherited]

Changes the send buffer size value.

Returns:
the previous value.

int xvr2::Net::Socket::sendBufSize (  )  [inherited]

Tells how big is the send buffer size.

Returns:
send buffer size in bytes.

int xvr2::Net::Socket::recvBufSize ( int  newsize  )  [inherited]

Changes the receive buffer size value.

Returns:
the previous value.

int xvr2::Net::Socket::recvBufSize (  )  [inherited]

Tells how big is the receive buffer size.

Returns:
send buffer size in bytes.

bool xvr2::Net::Socket::isStream (  )  [inherited]

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 (  )  [inherited]

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 (  )  [inherited]

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 (  )  [inherited]

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

bool xvr2::Net::Socket::isIPv6 (  )  [inherited]

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

Output stream object.

Definition at line 33 of file ClientSocket.h.

Input stream object.

Definition at line 35 of file ClientSocket.h.

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

This is the socket file descriptor per se.

Definition at line 35 of file Socket.h.

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

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