CAEN Utility  2.0.2
Utilities for CAEN projects
Network protocol functions

TCP/IP protocol. More...

Collaboration diagram for Network protocol functions:

Modules

 Safe versions of recv() and send()
 
 Safe versions of recv() and send() with mutex locking
 
 Platform independent wrappers of socket/accept/bind/listen/connect
 
 Simplified client/server functions
 

Functions

int32_t c_socket_init (void)
 
int32_t c_socket_cleanup (void)
 
c_socket_tc_socket_new (void)
 
void c_socket_delete (c_socket_t *socket)
 
void c_socket_reset (c_socket_t *socket)
 
c_socket_tc_tcp_socket (void)
 
c_socket_tc_accept (const c_socket_t *sckt, struct sockaddr *addr, c_socklen_t *addrlen)
 
int c_bind (const c_socket_t *sckt, const struct sockaddr *addr, c_socklen_t addrlen)
 
int c_listen (const c_socket_t *sckt, int backlog)
 
int c_connect (const c_socket_t *sckt, const struct sockaddr *addr, c_socklen_t addrlen)
 

Detailed Description

TCP/IP protocol.

Function Documentation

◆ c_socket_init()

int32_t c_socket_init ( void  )

Wrapper to WSAStartup()

Warning
No need to use it, as called by c_socket_new()
Precondition
No-op on Linux.
Returns
c_Socket_ErrorCode_Success (0) in case of success. Error codes specified in c_Socket_ErrorCode_t.

Definition at line 81 of file CAENSocket.c.

Here is the caller graph for this function:

◆ c_socket_cleanup()

int32_t c_socket_cleanup ( void  )

Wrapper to WSACleanup()

Warning
No need to use it, as called by c_socket_delete()
Precondition
Each call of c_socket_init() must match a call to c_socket_cleanup(). No-op on Linux.
Returns
c_Socket_ErrorCode_Success (0) in case of success. Error codes specified in c_Socket_ErrorCode_t.

Definition at line 104 of file CAENSocket.c.

Here is the caller graph for this function:

◆ c_socket_new()

c_socket_t* c_socket_new ( void  )

Call c_socket_init() and create a new c_socket_t structure. c_socket_t::socket left uninitialized

Returns
a pointer to a new c_socket_t to be deleted with c_socket_delete(). NULL in case of error.

WSAStartup

Definition at line 124 of file CAENSocket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ c_socket_delete()

void c_socket_delete ( c_socket_t socket)

Call c_socket_reset(), c_socket_cleanup() and free memory

Parameters
[in]socketthe socket to clean

Definition at line 134 of file CAENSocket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ c_socket_reset()

void c_socket_reset ( c_socket_t socket)

Close the socket and set socket->socket to c_socket_invalid

Parameters
[in]socketthe socket to reset

Definition at line 143 of file CAENSocket.c.

Here is the caller graph for this function:

◆ c_tcp_socket()

c_socket_t* c_tcp_socket ( void  )

Create a new c_socket_t where the socket has been initialized to socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)

Returns
a pointer to a new c_socket_t to be deleted with c_socket_delete(). NULL in case of error.

Definition at line 284 of file CAENSocket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ c_accept()

c_socket_t* c_accept ( const c_socket_t sckt,
struct sockaddr *  addr,
c_socklen_t addrlen 
)

Create a new c_socket_t where the socket has been initialized to accept(socket, addr, addrlen)

Parameters
[in]sckta socket created with c_tcp_socket(), bound to a local address with c_bind(), and is listening for connections after a c_listen().
[out]addra pointer to a sockaddr structure, filled in with the address of the peer socket
[out]addrlenthe actual size of the peer address
Returns
a pointer to a new c_socket_t to be deleted with c_socket_delete(). NULL in case of error.

Definition at line 302 of file CAENSocket.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ c_bind()

int c_bind ( const c_socket_t sckt,
const struct sockaddr *  addr,
c_socklen_t  addrlen 
)

Bind a name to a socket

Parameters
[in]sckta socket created with c_tcp_socket()
[in]addrthe address to be assigned
[in]addrlenthe size, in bytes, of the address structure pointed to by addr
Returns
on success, zero is returned. On error, -1 is returned, and c_socket_errno is set appropriately.

Definition at line 294 of file CAENSocket.c.

Here is the caller graph for this function:

◆ c_listen()

int c_listen ( const c_socket_t sckt,
int  backlog 
)

Marks the socket referred to by sckt as a passive socket

Parameters
[in]sckta socket created with c_tcp_socket()
[in]backlogthe maximum length to which the queue of pending connections for sckt may grow
Returns
on success, zero is returned. On error, -1 is returned, and c_socket_errno is set appropriately.

Definition at line 298 of file CAENSocket.c.

Here is the caller graph for this function:

◆ c_connect()

int c_connect ( const c_socket_t sckt,
const struct sockaddr *  addr,
c_socklen_t  addrlen 
)

Initiate a connection on a socket

Parameters
[in]sckta socket created with c_tcp_socket()
[in]addrthe address to which connect to
[in]addrlenthe size, in bytes, of the address structure pointed to by addr
Returns
on success, zero is returned. On error, -1 is returned, and c_socket_errno is set appropriately.

Definition at line 312 of file CAENSocket.c.

Here is the caller graph for this function: