ESA JPIP server  0.1
net::Socket Class Reference

This class has been designed to work with UNIX sockets in an easy and object oriented way. More...

#include <socket.h>

Collaboration diagram for net::Socket:

Public Member Functions

 Socket ()
 Initializes the socket id with an invalid value. More...
 
 Socket (int s)
 Initializes the socket id with an integer value. More...
 
 Socket (const Socket &xs)
 Copy constructor. More...
 
 operator int () const
 This operator allows to work directly with UNIX socket API. More...
 
bool IsValid () const
 
Socketoperator= (int nsid)
 Copy asignment. More...
 
bool OpenInet (int type=SOCK_STREAM)
 This method creates a new Internet socket, storing its identifier in the object. More...
 
bool OpenUnix (int type=SOCK_STREAM)
 This method creates a new UNIX socket, storing its identifier in the object. More...
 
bool ListenAt (const Address &address, int nstack=10)
 Configures the socket for listening incoming connections. More...
 
bool ConnectTo (const Address &to_address)
 Connects the socket to a server. More...
 
bool BindTo (const Address &address)
 Binds the socket to the specified address. More...
 
int Accept (Address *from_address)
 If it is a server socket, it accepts a new connection. More...
 
SocketSetBlockingMode (bool state=true)
 Set the blocking mode of the send/receive operations. More...
 
bool IsBlockingMode ()
 
int Receive (void *buf, int len, bool prevent_block=false)
 Receives a number of bytes. More...
 
int ReceiveFrom (Address *address, void *buf, int len, bool prevent_block=false)
 Receives a number of bytes. More...
 
int Send (void *buf, int len, bool prevent_block=false)
 Sends a number of bytes. More...
 
int SendTo (const Address &address, void *buf, int len, bool prevent_block=false)
 Sends a number of bytes to a specific address. More...
 
bool SendDescriptor (const Address &address, int fd, int aux=0)
 Sends a descriptor through the socket. More...
 
bool IsValid ()
 Returns true if the sockets is valid, that is, if after a polling regarding error status is not successful. More...
 
int WaitForInput (int time_out=-1)
 Waits until input data is available (POLLIN). More...
 
int WaitForOutput (int time_out=-1)
 Waits until output data can be sent (POLLOUT). More...
 
bool SetNoDelay (int val=1)
 Configures the parameter TCP_NODELAY of the socket. More...
 
bool ReceiveDescriptor (int *fd, int *aux=NULL)
 Receives a descriptor from a socket. More...
 
void Close ()
 Closes the socket. More...
 
 ~Socket ()
 The destructor does not closes the socket!. More...
 

Protected Attributes

int sid
 Socket id. More...
 

Detailed Description

This class has been designed to work with UNIX sockets in an easy and object oriented way.

Constructor & Destructor Documentation

net::Socket::Socket ( )
inline

Initializes the socket id with an invalid value.

net::Socket::Socket ( int  s)
inline

Initializes the socket id with an integer value.

net::Socket::Socket ( const Socket xs)
inline

Copy constructor.

net::Socket::~Socket ( )
inline

The destructor does not closes the socket!.

Member Function Documentation

int net::Socket::Accept ( Address from_address)
inline

If it is a server socket, it accepts a new connection.

Parameters
from_addressPointer to store the client address.
Returns
The integer identifier (file descriptor) of the new socket.

Here is the call graph for this function:

Here is the caller graph for this function:

bool net::Socket::BindTo ( const Address address)
inline

Binds the socket to the specified address.

Parameters
addressAddress to bind.
Returns
true if successful.

Here is the call graph for this function:

Here is the caller graph for this function:

void net::Socket::Close ( )
inline

Closes the socket.

Here is the caller graph for this function:

bool net::Socket::ConnectTo ( const Address to_address)
inline

Connects the socket to a server.

Parameters
to_addressAddress to connect.
Returns
true if successful.

Here is the call graph for this function:

bool net::Socket::IsBlockingMode ( )
Returns
The blocking mode of the send/receive operations.
bool net::Socket::IsValid ( ) const
inline
Returns
true if the identifier has a valid value.

Here is the caller graph for this function:

bool net::Socket::IsValid ( )

Returns true if the sockets is valid, that is, if after a polling regarding error status is not successful.

bool net::Socket::ListenAt ( const Address address,
int  nstack = 10 
)
inline

Configures the socket for listening incoming connections.

Parameters
addressAddress used to listen.
nstackMaximum number of clients in listening stack.
Returns
true if successful.

Here is the call graph for this function:

Here is the caller graph for this function:

bool net::Socket::OpenInet ( int  type = SOCK_STREAM)
inline

This method creates a new Internet socket, storing its identifier in the object.

Parameters
typeSocket type, SOCK_STREAM by default.
Returns
true if successful.

Here is the caller graph for this function:

bool net::Socket::OpenUnix ( int  type = SOCK_STREAM)
inline

This method creates a new UNIX socket, storing its identifier in the object.

Parameters
typeSocket type, SOCK_STREAM by default.
Returns
true if successful.

Here is the caller graph for this function:

net::Socket::operator int ( ) const
inline

This operator allows to work directly with UNIX socket API.

Socket& net::Socket::operator= ( int  nsid)
inline

Copy asignment.

int net::Socket::Receive ( void *  buf,
int  len,
bool  prevent_block = false 
)

Receives a number of bytes.

This methods allows to prevent blocking, without having into account the default blocking mode stablished.

Parameters
bufBuffer where to store the received bytes.
lenLength of the buffer.
prevent_blocktrue if blocking will be prevented.
Returns
The number of received bytes.

Here is the caller graph for this function:

bool net::Socket::ReceiveDescriptor ( int *  fd,
int *  aux = NULL 
)

Receives a descriptor from a socket.

Parameters
fdVariable to store the received descriptor.
auxAuxiliary information received attached.
Returns
true if successful.

Here is the caller graph for this function:

int net::Socket::ReceiveFrom ( Address address,
void *  buf,
int  len,
bool  prevent_block = false 
)

Receives a number of bytes.

This methods allows to prevent blocking, without having into account the default blocking mode stablished.

Parameters
addressPointer to store the from address.
bufBuffer where to store the received bytes.
lenLength of the buffer.
prevent_blocktrue if blocking will be prevented.
Returns
The number of received bytes.

Here is the call graph for this function:

int net::Socket::Send ( void *  buf,
int  len,
bool  prevent_block = false 
)

Sends a number of bytes.

This methods allows to prevent blocking, without having into account the default blocking mode stablished.

Parameters
bufBuffer with the bytes to sent.
lenNumber of bytes to sent.
prevent_blocktrue if blocking will be prevented.
Returns
The number of sent bytes.

Here is the caller graph for this function:

bool net::Socket::SendDescriptor ( const Address address,
int  fd,
int  aux = 0 
)

Sends a descriptor through the socket.

Parameters
addressAddress of the socket to send the descriptor.
fdFile descriptor.
auxAuxiliary information to send attached.
Returns
true if successful.

Here is the call graph for this function:

Here is the caller graph for this function:

int net::Socket::SendTo ( const Address address,
void *  buf,
int  len,
bool  prevent_block = false 
)

Sends a number of bytes to a specific address.

This methods allows to prevent blocking, without having into account the default blocking mode established.

Parameters
addressAddress to send the bytes.
bufBuffer with the bytes to sent.
lenNumber of bytes to sent.
prevent_blocktrue if blocking will be prevented.
Returns
The number of sent bytes.

Here is the call graph for this function:

Here is the caller graph for this function:

Socket & net::Socket::SetBlockingMode ( bool  state = true)

Set the blocking mode of the send/receive operations.

By default, this mode is true.

Parameters
stateBlocking mode state to set.
Returns
A reference of the same object.
bool net::Socket::SetNoDelay ( int  val = 1)
inline

Configures the parameter TCP_NODELAY of the socket.

Parameters
valNew value for the parameter (1 by default).
Returns
true if successful.
int net::Socket::WaitForInput ( int  time_out = -1)

Waits until input data is available (POLLIN).

Parameters
time_outTime out (infinite by default).
Returns
The value returned by the poll function.
int net::Socket::WaitForOutput ( int  time_out = -1)

Waits until output data can be sent (POLLOUT).

Parameters
time_outTime out (infinite by default).
Returns
The value returned by the poll function.

Member Data Documentation

int net::Socket::sid
protected

Socket id.


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