Data Structures | |
struct | tcp_socket |
TCP socket information structure. More... | |
Defines | |
#define | SO_ACK 0x10 |
Socket transmit flag. Send ACK. | |
#define | SO_FIN 0x01 |
Socket transmit flag. Send FIN after all data has been transmitted. | |
#define | SO_FORCE 0x08 |
Socket transmit flag. Force sending ACK. | |
#define | SO_SYN 0x02 |
Socket transmit flag. Send SYN first. | |
Typedefs | |
typedef tcp_socket | TCPSOCKET |
TCP socket type. | |
Functions | |
int | NutTcpAccept (TCPSOCKET *sock, u_short port) |
Wait for incoming connect from a remote socket. | |
int | NutTcpCloseSocket (TCPSOCKET *sock) |
Close TCP socket. | |
int | NutTcpConnect (TCPSOCKET *sock, u_long addr, u_short port) |
Connect to a remote socket. | |
TCPSOCKET * | NutTcpCreateSocket (void) |
Create a TCP socket. | |
void | NutTcpDestroySocket (TCPSOCKET *sock) |
Destroy a previously allocated socket. | |
int | NutTcpDeviceIOCtl (TCPSOCKET *sock, int cmd, void *param) |
Write to device.Driver control function. | |
int | NutTcpDeviceRead (TCPSOCKET *sock, void *buffer, int size) |
Read from virtual socket device. | |
int | NutTcpDeviceWrite (TCPSOCKET *sock, CONST void *buf, int size) |
Write to a socket. | |
void | NutTcpDiscardBuffers (TCPSOCKET *sock) |
int | NutTcpError (TCPSOCKET *sock) |
Return specific code of the last error. | |
TCPSOCKET * | NutTcpFindSocket (u_short lport, u_short rport, u_long raddr) |
Find a matching socket. | |
int | NutTcpGetSockOpt (TCPSOCKET *sock, int optname, void *optval, int optlen) |
Get a TCP socket option value. | |
int | NutTcpReceive (TCPSOCKET *sock, void *data, u_short size) |
Receive data on a connected TCP socket. | |
int | NutTcpSend (TCPSOCKET *sock, CONST void *data, u_short len) |
Send data on a connected TCP socket. | |
int | NutTcpSetSockOpt (TCPSOCKET *sock, int optname, CONST void *optval, int optlen) |
Set value of a TCP socket option. | |
Variables | |
TCPSOCKET * | tcpSocketList = 0 |
Wait for incoming connect from a remote socket.
The calling thread will be suspended until until an incoming connection request is received.
This function is typically used by TCP server applications.
sock | Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). | |
port | Port number to listen to (host byte order). |
int NutTcpCloseSocket | ( | TCPSOCKET * | sock | ) |
Close TCP socket.
Note, that the socket may not be immediately destroyed after calling this function. However, the application must not use the socket after this call.
sock | Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). |
Connect to a remote socket.
This function tries to establish a connection to the specified remote port of the specified remote server. The calling thread will be suspended until a connection is successfully established or an error occurs.
This function is typically used by TCP client applications.
sock | Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). | |
addr | IP address of the host to connect (network byte order). | |
port | Port number to connect (host byte order). |
TCPSOCKET* NutTcpCreateSocket | ( | void | ) |
Create a TCP socket.
Allocates a TCPSOCKET structure from heap memory, initializes it and returns a pointer to that structure.
The very first call will also start the TCP state machine, which is running in a separate thread.
void NutTcpDestroySocket | ( | TCPSOCKET * | sock | ) |
Destroy a previously allocated socket.
Remove socket from the socket list and release occupied memory.
Applications must not call this function. It is automatically called by a timer after the socket has been closed by NutTcpCloseSocket().
sock | Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). |
int NutTcpDeviceIOCtl | ( | TCPSOCKET * | sock, | |
int | cmd, | |||
void * | param | |||
) |
Write to device.Driver control function.
Used by the virtual device driver to modify or query device specific settings.
sock | Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). | |
cmd | Requested control function. May be set to one of the following constants: | |
param | Points to a buffer that contains any data required for the given control function or receives data from that function. |
int NutTcpDeviceRead | ( | TCPSOCKET * | sock, | |
void * | buffer, | |||
int | size | |||
) |
Read from virtual socket device.
TCP sockets can be used like other Nut/OS devices. This routine is part of the virtual socket device driver.
This function is called by the low level input routines of the C runtime library, using the _NUTDEVICE::dev_read entry.
sock | Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). | |
buffer | Pointer to the buffer that receives the data. | |
size | Maximum number of bytes to read. |
int NutTcpDeviceWrite | ( | TCPSOCKET * | sock, | |
CONST void * | buf, | |||
int | size | |||
) |
Write to a socket.
TCP sockets can be used like other Nut/OS devices. This routine is part of the virtual socket device driver.
This function is called by the low level output routines of the C runtime library, using the _NUTDEVICE::dev_write entry.
In contrast to NutTcpSend() this routine provides some buffering.
sock | Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). | |
buf | Pointer to the data to be written. | |
size | Number of bytes to write. If zero, then the output buffer will be flushed. |
int NutTcpError | ( | TCPSOCKET * | sock | ) |
Return specific code of the last error.
Possible error codes (net/errno.h) are:
sock | Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). |
Find a matching socket.
Loop through all sockets and find a matching connection (prefered) or a listening socket.
Applications typically do not call this function.
lport | Local port number. | |
rport | Remote port number. | |
raddr | Remote IP address in network byte order. |
int NutTcpGetSockOpt | ( | TCPSOCKET * | sock, | |
int | optname, | |||
void * | optval, | |||
int | optlen | |||
) |
Get a TCP socket option value.
The following values can be set:
sock | Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). | |
optname | Option to get. | |
optval | Points to a buffer receiving the value. | |
optlen | Length of the value buffer. |
Receive data on a connected TCP socket.
sock | Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). In addition a connection must have been established by calling NutTcpConnect or NutTcpAccept. | |
data | Pointer to the buffer that receives the data. | |
size | Size of the buffer. |
Send data on a connected TCP socket.
sock | Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). In addition a connection must have been established by calling NutTcpConnect or NutTcpAccept. | |
data | Pointer to a buffer containing the data to send. | |
len | Number of bytes to be sent. |
int NutTcpSetSockOpt | ( | TCPSOCKET * | sock, | |
int | optname, | |||
CONST void * | optval, | |||
int | optlen | |||
) |
Set value of a TCP socket option.
The following values can be set:
sock | Socket descriptor. This pointer must have been retrieved by calling NutTcpCreateSocket(). | |
optname | Option to set. | |
optval | Pointer to the value. | |
optlen | Length of the value. |
TCPSOCKET* tcpSocketList = 0 |
Global linked list of all TCP sockets.