ESA JPIP server
0.1
|
This class has been designed to work with UNIX sockets in an easy and object oriented way. More...
#include <socket.h>
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 |
Socket & | operator= (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... | |
Socket & | SetBlockingMode (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... | |
This class has been designed to work with UNIX sockets in an easy and object oriented way.
|
inline |
Initializes the socket id with an invalid value.
|
inline |
Initializes the socket id with an integer value.
|
inline |
Copy constructor.
|
inline |
The destructor does not closes the socket!.
|
inline |
If it is a server socket, it accepts a new connection.
from_address | Pointer to store the client address. |
|
inline |
Binds the socket to the specified address.
address | Address to bind. |
true
if successful.
|
inline |
Closes the socket.
|
inline |
Connects the socket to a server.
to_address | Address to connect. |
true
if successful. bool net::Socket::IsBlockingMode | ( | ) |
|
inline |
true
if the identifier has a valid value. bool net::Socket::IsValid | ( | ) |
Returns true
if the sockets is valid, that is, if after a polling regarding error status is not successful.
|
inline |
Configures the socket for listening incoming connections.
address | Address used to listen. |
nstack | Maximum number of clients in listening stack. |
true
if successful.
|
inline |
This method creates a new Internet socket, storing its identifier in the object.
type | Socket type, SOCK_STREAM by default. |
true
if successful.
|
inline |
This method creates a new UNIX socket, storing its identifier in the object.
type | Socket type, SOCK_STREAM by default. |
true
if successful.
|
inline |
This operator allows to work directly with UNIX socket API.
|
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.
buf | Buffer where to store the received bytes. |
len | Length of the buffer. |
prevent_block | true if blocking will be prevented. |
bool net::Socket::ReceiveDescriptor | ( | int * | fd, |
int * | aux = NULL |
||
) |
Receives a descriptor from a socket.
fd | Variable to store the received descriptor. |
aux | Auxiliary information received attached. |
true
if successful. 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.
address | Pointer to store the from address. |
buf | Buffer where to store the received bytes. |
len | Length of the buffer. |
prevent_block | true if blocking will be prevented. |
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.
buf | Buffer with the bytes to sent. |
len | Number of bytes to sent. |
prevent_block | true if blocking will be prevented. |
bool net::Socket::SendDescriptor | ( | const Address & | address, |
int | fd, | ||
int | aux = 0 |
||
) |
Sends a descriptor through the socket.
address | Address of the socket to send the descriptor. |
fd | File descriptor. |
aux | Auxiliary information to send attached. |
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.
address | Address to send the bytes. |
buf | Buffer with the bytes to sent. |
len | Number of bytes to sent. |
prevent_block | true if blocking will be prevented. |
Socket & net::Socket::SetBlockingMode | ( | bool | state = true | ) |
Set the blocking mode of the send/receive operations.
By default, this mode is true.
state | Blocking mode state to set. |
|
inline |
Configures the parameter TCP_NODELAY
of the socket.
val | New value for the parameter (1 by default). |
true
if successful. int net::Socket::WaitForInput | ( | int | time_out = -1 | ) |
Waits until input data is available (POLLIN
).
time_out | Time out (infinite by default). |
poll
function. int net::Socket::WaitForOutput | ( | int | time_out = -1 | ) |
Waits until output data can be sent (POLLOUT
).
time_out | Time out (infinite by default). |
poll
function.
|
protected |
Socket id.