DDraceNetwork Docs
Network-TCP
Collaboration diagram for Network-TCP:

Functions

NETSOCKET net_tcp_create (NETADDR bindaddr)
 
int net_tcp_listen (NETSOCKET sock, int backlog)
 
int net_tcp_accept (NETSOCKET sock, NETSOCKET *new_sock, NETADDR *addr)
 
int net_tcp_connect (NETSOCKET sock, const NETADDR *addr)
 
int net_tcp_send (NETSOCKET sock, const void *data, int size)
 
int net_tcp_recv (NETSOCKET sock, void *data, int maxsize)
 
int net_tcp_close (NETSOCKET sock)
 

Detailed Description

Function Documentation

◆ net_tcp_accept()

int net_tcp_accept ( NETSOCKET  sock,
NETSOCKET new_sock,
NETADDR addr 
)

Polls a listning socket for a new connection.

Parameters
sock- Listning socket to poll.
new_sock- Pointer to a socket to fill in with the new socket.
addr- Pointer to an address that will be filled in the remote address (optional, can be NULL).
Returns
A non-negative integer on success. Negative integer on failure.

◆ net_tcp_close()

int net_tcp_close ( NETSOCKET  sock)

Closes a TCP socket.

Parameters
sockSocket to close.
Returns
0 on success. Negative value on failure.

◆ net_tcp_connect()

int net_tcp_connect ( NETSOCKET  sock,
const NETADDR addr 
)

Connects one socket to another.

Parameters
sockSocket to connect.
addrAddress to connect to.
Returns
0 on success.

◆ net_tcp_create()

NETSOCKET net_tcp_create ( NETADDR  bindaddr)

Creates a TCP socket.

Parameters
bindaddrAddress to bind the socket to.
Returns
On success it returns an handle to the socket. On failure it returns NETSOCKET_INVALID.

◆ net_tcp_listen()

int net_tcp_listen ( NETSOCKET  sock,
int  backlog 
)

Makes the socket start listening for new connections.

Parameters
sockSocket to start listen to.
backlogSize of the queue of incoming connections to keep.
Returns
0 on success.

◆ net_tcp_recv()

int net_tcp_recv ( NETSOCKET  sock,
void *  data,
int  maxsize 
)

Recvives data from a TCP stream.

Parameters
sockSocket to recvive data from.
dataPointer to a buffer to write the data to
max_sizeMaximum of data to write to the buffer.
Returns
Number of bytes recvived. Negative value on failure. When in non-blocking mode, it returns 0 when there is no more data to be fetched.

◆ net_tcp_send()

int net_tcp_send ( NETSOCKET  sock,
const void *  data,
int  size 
)

Sends data to a TCP stream.

Parameters
sockSocket to send data to.
dataPointer to the data to send.
sizeSize of the data to send.
Returns
Number of bytes sent. Negative value on failure.