Socket function library.
Continua...
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <sys/select.h>
#include <fcntl.h>
#include <unistd.h>
Vai al codice sorgente di questo file.
|
uint8_t | wiicom_socket_initLibSocket () |
| Function that initializes the socket library
Warning! This function should be called before using the socket. Continua...
|
|
void | wiicom_socket_deinitLibSocket () |
| Function that de-initialize the socket library
Warning! This function is called when not used any more a sockets or, in general, before the close of the program. Continua...
|
|
void | wiicom_socket_set_timeout_conn (uint8_t sec) |
| Function that sets the connection timeout of a socket. Continua...
|
|
void | wiicom_socket_set_timeout_reciv (uint8_t sec) |
| Funzione che imposta il timeout della ricezione dati di un socket. Continua...
|
|
uint8_t | wiicom_socket_get_timeout_conn () |
| Function that returns the seconds after which there is a timeout in the connection of a socket. Continua...
|
|
uint8_t | wiicom_socket_get_timeout_reciv () |
| Function that returns the seconds after which you have a timeout when receiving data. Continua...
|
|
uint8_t | wiicom_socket_blocking (int socket_fd, uint8_t b_block) |
| Funzione che imposta il socket come bloccante o non bloccante. Continua...
|
|
void | wiicom_socket_set_address (struct sockaddr_in *socket_address, const char *ip, int port) |
| Function that set a socket address. Continua...
|
|
int | wiicom_socket_create (int domain, int type, int protocol) |
| Function that create a socket. Continua...
|
|
void | wiicom_socket_close (int socket_fd) |
| Function that close a socket. Continua...
|
|
int | wiicom_socket_connect (int socketToConnect, struct sockaddr_in *socketToConnect_addr) |
| Function that make a socket connection with timeout. Continua...
|
|
int | wiicom_socket_sendall (int socket_fd, uint8_t *buf, uint16_t *len) |
| Function that sends a data buffer on socket. Continua...
|
|
ssize_t | wiicom_socket_reciv (int socket_fd, void *buffer, size_t buffer_size) |
| Function that receives the data transmitted to the socket with timeout On error or timeout the socket is closed. Continua...
|
|
ssize_t | wiicom_socket_notimeout_reciv (int socket_fd, void *buffer, size_t buffer_size) |
| Function that receives the data transmitted to the socket without timeout. Continua...
|
|
uint8_t | wiicom_socket_shutdown (int socket_fd) |
| Function that shut down a socket. Continua...
|
|
Socket function library.
Generic library for managing socket
- Autore
- Marco Malano
-
WIICOM s.r.l
- Versione
- 1.0.0
- Data
- 2012
- Copyright
- 2012 - Wiicom - p.iva IT10710600015 - All rights reserved.
- Attenzione
- This library depends on wiicom_libutil
Every function that expects a result, in case of an error, set the Wiicom errno and print to stderr the error occurred.
- Nota
- None.
#define SEC_TIMEOUT_CONNECT_SOCKET 5 |
Number of seconds before a timeout error during the connection phase
#define SEC_TIMEOUT_RECIV_SOCKET 10 |
Number of seconds before a timeout error during data reception
uint8_t wiicom_socket_blocking |
( |
int |
socket_fd, |
|
|
uint8_t |
b_block |
|
) |
| |
Funzione che imposta il socket come bloccante o non bloccante.
- Parametri
-
[in] | socket_fd | a file descriptor for the socket |
[in] | b_block | if TRUE sets the socket as a blocker, if FALSE sets it as non-blocking |
- Restituisce
- On success, TRUE is returned, On error, FALSE is returned
void wiicom_socket_close |
( |
int |
socket_fd | ) |
|
Function that close a socket.
- Parametri
-
[in] | socket_fd | a file descriptor for the socket to close |
- Restituisce
- void
int wiicom_socket_connect |
( |
int |
socketToConnect, |
|
|
struct sockaddr_in * |
socketToConnect_addr |
|
) |
| |
Function that make a socket connection with timeout.
- Parametri
-
[in] | socketToConnect | a file descriptor for the socket on which connect |
[in] | socketToConnect_addr | sockaddr_in |
- Restituisce
- On success, 0 is returned, On error, -1 is returned
int wiicom_socket_create |
( |
int |
domain, |
|
|
int |
type, |
|
|
int |
protocol |
|
) |
| |
Function that create a socket.
- Parametri
-
[in] | domain | communication domain |
[in] | type | specifies the communication semantics |
[in] | protocol | specifies a particular protocol to be used with the socket |
- Restituisce
- on success, a file descriptor for the new socket is returned. On error, -1 is returned
void wiicom_socket_deinitLibSocket |
( |
| ) |
|
Function that de-initialize the socket library
Warning! This function is called when not used any more a sockets or, in general, before the close of the program.
- Restituisce
- void
uint8_t wiicom_socket_get_timeout_conn |
( |
| ) |
|
Function that returns the seconds after which there is a timeout in the connection of a socket.
- Restituisce
- Timeout in seconds
uint8_t wiicom_socket_get_timeout_reciv |
( |
| ) |
|
Function that returns the seconds after which you have a timeout when receiving data.
- Restituisce
- Timeout in seconds
uint8_t wiicom_socket_initLibSocket |
( |
| ) |
|
Function that initializes the socket library
Warning! This function should be called before using the socket.
- Restituisce
- On success, TRUE is returned, On error, FALSE is returned
ssize_t wiicom_socket_notimeout_reciv |
( |
int |
socket_fd, |
|
|
void * |
buffer, |
|
|
size_t |
buffer_size |
|
) |
| |
Function that receives the data transmitted to the socket without timeout.
- Parametri
-
[in] | socket_fd | a file descriptor for the socket where datas are recived |
[out] | buffer | buffer in which datas are loaded |
[in] | buffer_size | size of the buffer containing the data read |
- Restituisce
- On success, number of bytes received. 0 is returned if the socket has been closed. On error, -1 is returned
ssize_t wiicom_socket_reciv |
( |
int |
socket_fd, |
|
|
void * |
buffer, |
|
|
size_t |
buffer_size |
|
) |
| |
Function that receives the data transmitted to the socket with timeout On error or timeout the socket is closed.
- Parametri
-
[in] | socket_fd | a file descriptor for the socket where datas are recived |
[out] | buffer | it contains data to send |
[in] | buffer_size | size of the buffer to send |
- Restituisce
- On success, number of bytes transmitted. 0 is returned if the socket has been closed. On error, -1 is returned
int wiicom_socket_sendall |
( |
int |
socket_fd, |
|
|
uint8_t * |
buf, |
|
|
uint16_t * |
len |
|
) |
| |
Function that sends a data buffer on socket.
- Parametri
-
[in] | socket_fd | a file descriptor for the socket where datas are send |
[in] | buf | a datas to send |
[in,out] | len | number of bytes in the buffer to be sent, after sending it contains the number of bytes sent |
- Restituisce
- On success, 0 is returned. On error, -1 is returned
void wiicom_socket_set_address |
( |
struct sockaddr_in * |
socket_address, |
|
|
const char * |
ip, |
|
|
int |
port |
|
) |
| |
Function that set a socket address.
- Parametri
-
[out] | socket_address | socket_address to set |
[in] | ip | IP address |
[in] | port | Port |
- Restituisce
- void
void wiicom_socket_set_timeout_conn |
( |
uint8_t |
sec | ) |
|
Function that sets the connection timeout of a socket.
- Parametri
-
- Restituisce
- void
void wiicom_socket_set_timeout_reciv |
( |
uint8_t |
sec | ) |
|
Funzione che imposta il timeout della ricezione dati di un socket.
- Parametri
-
- Restituisce
- void
uint8_t wiicom_socket_shutdown |
( |
int |
socket_fd | ) |
|
Function that shut down a socket.
- Parametri
-
[in] | socket_fd | a file descriptor for the socket to close |
- Restituisce
- On success, TRUE is returned, On error, FALSE is returned