NetBurner 3.3.4
PDF Version
TCP

Modules

 TCP Notify
 
 TCP Socket Options
 
 TCP Socket State
 
 TCP Socket Status
 

Functions

int accept (int listening_socket, IPADDR *address, uint16_t *port, uint16_t timeout)
 Accept an incoming connection from a listening socket. More...
 
int connect (const IPADDR &ipAddress, uint16_t remotePort, uint32_t timeout)
 Make an outgoing TCP connection to a remote host. More...
 
int connectvia (const IPADDR &ipAddress, uint16_t remotePort, uint32_t timeout, const IPADDR &localIpAddress)
 Make an outgoing TCP connection to a remote host using the specified local interface IP address. More...
 
int connectvia (const IPADDR &ipAddress, uint16_t remotePort, uint32_t timeout, int ifnum)
 Make an outgoing TCP connection to a remote host using the specified local interface number. More...
 
int connectwlocal (const IPADDR &ipAddress, uint16_t localPort, uint16_t remotePort, uint32_t timeout, const IPADDR &localIpAddress=IPADDR::NullIP(), int intf=-1)
 Make an outgoing TCP connection to a remote host using the specified local interface number or IP address. More...
 
int listen (const IPADDR &addr, uint16_t port, uint8_t maxpend=5)
 Listen for incoming connections on the specified network interface IP address. More...
 
int listenvia (const IPADDR &addr, uint16_t port, int ifn, uint8_t maxpend=5)
 Listen for incoming connections on the specified network interface IP address. More...
 
int listenvia (const IPADDR &addr, uint16_t port, const IPADDR &localIpAddress, uint8_t maxpend=5)
 Listen for incoming connections on the specified network interface IP address. More...
 
int NoBlockConnect (const IPADDR &ipAddress, uint16_t remotePort)
 Create a file descriptor for a TCP connection and return immediately. This function does not wait for a connection to be established. Before using the file descriptor, the application must verify the connection was successful with TcpGetSocketState(fd). The state will be TCP_STATE_ESTABLISHED when the connection has been successfully established. Note: The connection status can also be obtained with the wireavail() function. More...
 
int NoBlockConnectVia (const IPADDR &ipAddress, uint16_t remotePort, const IPADDR &interfaceIpAddress=IPADDR::NullIP())
 Create a file descriptor for a TCP connection and return immediately. This function does not wait for a connection to be established. Before using the file descriptor, the application must verify the connection was successful with TcpGetSocketState(fd). The state will be TCP_STATE_ESTABLISHED when the connection has been successfully established. Note: The connection status can also be obtained with the wireavail() function. More...
 
int NoBlockConnectVia (const IPADDR &ipAddress, uint16_t remotePort, int ifnum)
 Create a file descriptor for a TCP connection and return immediately. This function does not wait for a connection to be established. Before using the file descriptor, the application must verify the connection was successful with TcpGetSocketState(fd). The state will be TCP_STATE_ESTABLISHED when the connection has been successfully established. Note: The connection status can also be obtained with the wireavail() function. More...
 
int NoBlockConnectwlocal (const IPADDR &ipAddress, uint16_t localPort, uint16_t remotePort, IPADDR interfaceIpAddress=IPADDR::NullIP(), int ifn=-1)
 Create a file descriptor for a TCP connection and return immediately. This function does not wait for a connection to be established. Before using the file descriptor, the application must verify the connection was successful with TcpGetSocketState(fd). The state will be TCP_STATE_ESTABLISHED when the connection has been successfully established. Note: The connection status can also be obtained with the wireavail() function. More...
 
IPADDR GetSocketRemoteAddr (int fd)
 Returns the IP address of the remote host associated with the specified file descriptor. More...
 
IPADDR GetSocketLocalAddr (int fd)
 Returns the IP address of the local interface associated with the connection. More...
 
uint16_t GetSocketRemotePort (int fd)
 Returns the port number of the remote host associated with the connection. More...
 
uint16_t GetSocketLocalPort (int fd)
 Returns the local port number associated with the connection. More...
 
uint32_t TcpGetLastRxTime (int fd)
 Returns the value of system Time Ticks when the last packet was received. Used for the TCP Keep Alive feature. More...
 
void TcpSendKeepAlive (int fd)
 Send a TCP keep alive packet to a remote host. More...
 
uint32_t TcpGetLastRxInterval (int fd)
 Returns the number of system Time Ticks since the last packet was received. This is the difference between the current system time and lastRxTime of the socket. More...
 
int GetTcpRtxCount (int fd)
 Returns the number of re-transmits that have occurred on the specified connection. More...
 
uint8_t SetOutOfOrderBuffers (int fd, uint8_t max)
 Set the maximum number of out-of-order TCP buffers for the specified TCP socket. More...
 
int setsockoption (int fd, int option)
 Set TCP socket options. More...
 
int clrsockoption (int fd, int option)
 Clear TCP socket options. More...
 
int getsockoption (int fd)
 Returns the options for the specified TCP socket. More...
 
int SetSocketUnackBuffers (int fd, uint8_t val)
 Set the maximum number of outbound TCP buffers in the transmit un-acknowledged list for the specified TCP socket. More...
 
int SetSocketRxBuffers (int fd, int n)
 Set the number of TCP receive buffers for the specified TCP socket. More...
 
int SetSocketTxBuffers (int fd, int n)
 Set the number of TCP transmit buffers for the specified TCP socket. More...
 
int abortsocket (int fd)
 Execute an abort on the specified TCP socket. More...
 
int SockReadWithTimeout (int fd, char *buf, int nbytes, uint32_t timeout)
 Attempt to read from a TCP socket until the timeout expires. More...
 
char SocketPeek (int fd)
 Returns the next char that would be read, 0 if no data. More...
 
int TcpGetSocketInterface (int fd)
 Return the network interface associated with a TCP socket. More...
 
uint8_t TcpGetSocketState (int fd)
 Return the current state of a TCP socket. More...
 
uint16_t TcpGetRxBufferSpaceUsed (int fd)
 Returns the number of bytes used in a socket's RX buffer. More...
 
uint16_t TcpGetTxBufferAvailSpace (int fd)
 Returns the number of bytes available in a socket's TX buffer. More...
 
BOOL TcpAllDataAcked (int socket)
 Check the data acknowledged state of a socket. More...
 
BOOL WaitForSocketFlush (int fd, uint32_t ticks)
 Wait for a socket flush operation to complete. A socket is flushed if all sent data has been acknowledged. More...
 

Detailed Description

Function Documentation

◆ abortsocket()

int abortsocket ( int  fd)

Execute an abort on the specified TCP socket.

Parameters
fdSocket file descriptor
Returns
TCP Socket Status

◆ accept()

int accept ( int  listening_socket,
IPADDR address,
uint16_t *  port,
uint16_t  timeout 
)

Accept an incoming connection from a listening socket.

A socket must be listening in order to accept a TCP connection, and a connection request must be accepted before it can be used. Each time a connection request is accepted, a slot is freed in the listen pending queue for that socket.

Parameters
listening_socketThe listening socket from which to accept the connection.
*addressPointer to an IPADDR object that can store the source IP address of the connection. Can be NULL.
*portPointer to a variable to store the source port number of the connection. Can be NULL.
timeoutNumber of system Time Ticks to wait. A value of 0 waits forever. For example, TICKS_PER_SECOND * 5 waits five seconds.
Returns
A value greater than 0 on success, representing the socket file descriptor. A value less than 0 on error, TCP Socket Status.
See also
listen(), close()

◆ clrsockoption()

int clrsockoption ( int  fd,
int  option 
)

Clear TCP socket options.

Parameters
fdSocket file descriptor.
optionSocket option to clear: TCP Socket Options.
Returns
A bitmask of the options for the specified socket.
See also
setsockoption(), getsockoption(), SetSocketUnackBuffers(), SetSocketRxBuffers(), SetSocketTxBuffers()

◆ connect()

int connect ( const IPADDR ipAddress,
uint16_t  remotePort,
uint32_t  timeout 
)
inline

Make an outgoing TCP connection to a remote host.

Parameters
ipAddressRemote IP address.
remotePortRemote port number.
timeoutTimeout in system time ticks (use TICKS_PER_SECOND macro).
Returns
A value greater than 0 on success, representing the socket file descriptor. A value less than 0 on error, TCP Socket Status.
See also
connectvia(), connectwlocal()

◆ connectvia() [1/2]

int connectvia ( const IPADDR ipAddress,
uint16_t  remotePort,
uint32_t  timeout,
const IPADDR localIpAddress 
)
inline

Make an outgoing TCP connection to a remote host using the specified local interface IP address.

The connect() function automatically uses the default network interface. The connectvia() function enables the application to specify a particular local network interface.

Parameters
ipAddressRemote IP address .
remotePortRemote port number.
timeoutTimeout in system time ticks (use TICKS_PER_SECOND macro).
localIpAddressIP address of the local interface. If a value of IPADDR::NULL() is used, it will attempt to use the local interface associated with the remote IP address.
Returns
A value greater than 0 on success, representing the socket file descriptor. A value less than 0 on error, TCP Socket Status.
See also
connect(), connectwlocal()

◆ connectvia() [2/2]

int connectvia ( const IPADDR ipAddress,
uint16_t  remotePort,
uint32_t  timeout,
int  ifnum 
)
inline

Make an outgoing TCP connection to a remote host using the specified local interface number.

The connect() function automatically uses the default network interface. The connectvia() function enables the application to specify a particular local network interface.

Parameters
ipAddressRemote IP address.
remotePortRemote port number.
timeoutTimeout in system time ticks (use TICKS_PER_SECOND macro).
ifnumThe local interface number. The interface number will override all routing based on the source and destination IP address.
Returns
A value greater than 0 on success, representing the socket file descriptor. A value less than 0 on error, TCP Socket Status.
See also
connect(), connectwlocal()

◆ connectwlocal()

int connectwlocal ( const IPADDR ipAddress,
uint16_t  localPort,
uint16_t  remotePort,
uint32_t  timeout,
const IPADDR localIpAddress = IPADDR::NullIP(),
int  intf = -1 
)
inline

Make an outgoing TCP connection to a remote host using the specified local interface number or IP address.

Warning
Although this function that allows a local port number parameter for extreme edge cases, local port numbers should be avoided. Local port numbers create connectivity failures when a remote host has a half open socket condition.
Parameters
ipAddressRemote IP address.
localPortOptional parameter to specify a Local port number. Recommend this always be set to a value of 0 so a random local port number is used. Warning! Specifying a local port number will create connectivity failures if the remote host has a half open socket condition.
remotePortRemote port number.
timeoutTimeout in system time ticks (use TICKS_PER_SECOND macro).
localIpAddressOptional IP address of local interface to use for connection. If not used, such as when specifying the intf parameter, set to IPADDR::NullIP().
intfOptional local interface number to use for connection. Do not specify if the interfaceIpAddress parameter is used.
Returns
A value greater than 0 on success, representing the socket file descriptor. A value less than 0 on error, TCP Socket Status.
See also
connect(), connectvia()

◆ GetSocketLocalAddr()

IPADDR GetSocketLocalAddr ( int  fd)
inline

Returns the IP address of the local interface associated with the connection.

Parameters
fdThe socket file descriptor.
Returns
The IP address of the remote host.
See also
GetSocketRemoteAddr()

◆ GetSocketLocalPort()

uint16_t GetSocketLocalPort ( int  fd)

Returns the local port number associated with the connection.

Parameters
fdThe socket file descriptor.
Returns
The local port number for the connection.
See also
GetSocketRemotePort()

◆ GetSocketRemoteAddr()

IPADDR GetSocketRemoteAddr ( int  fd)
inline

Returns the IP address of the remote host associated with the specified file descriptor.

Parameters
fdThe socket file descriptor.
Returns
The IP address of the remote host.
See also
GetSocketLocalAddr()

◆ GetSocketRemotePort()

uint16_t GetSocketRemotePort ( int  fd)

Returns the port number of the remote host associated with the connection.

Parameters
fdThe socket file descriptor.
Returns
The remote host port number.
See also
GetSocketLocalPort()

◆ getsockoption()

int getsockoption ( int  fd)

Returns the options for the specified TCP socket.

Parameters
fdSocket file descriptor.
Returns
A bitmask of the options for the specified socket.
See also
setsockoption(), clrsockoption(), SetSocketUnackBuffers(), SetSocketRxBuffers(), SetSocketTxBuffers()

◆ GetTcpRtxCount()

int GetTcpRtxCount ( int  fd)

Returns the number of re-transmits that have occurred on the specified connection.

Parameters
fdThe socket file descriptor.
Returns
The number of system Time Ticks since the last packet was received on the connection.

◆ listen()

int listen ( const IPADDR addr,
uint16_t  port,
uint8_t  maxpend = 5 
)
inline

Listen for incoming connections on the specified network interface IP address.

Begin listening for incoming connections. A connection must be accepted with the accept() function before they can be used. Each time a connection request is accepted is frees up another slot in the pending queue.

Parameters
addrThe address from which to accept connections. INADDR_ANY will accept all connections.
portThe network port number to listen on.
maxpendThe maximum number of pending connection requests allowed for the listen socket.
Returns
A value greater than 0 on success, representing the socket file descriptor. A value less than 0 on error, TCP Socket Status.
int32_t fdListen = listen(INADDR_ANY, 1234);
int listen(const IPADDR &addr, uint16_t port, uint8_t maxpend=5)
Listen for incoming connections on the specified network interface IP address.
Definition: tcp.h:226
See also
accept(), listenvia(), close()

◆ listenvia() [1/2]

int listenvia ( const IPADDR addr,
uint16_t  port,
const IPADDR localIpAddress,
uint8_t  maxpend = 5 
)
inline

Listen for incoming connections on the specified network interface IP address.

Begin listening for incoming connections. A connection must be accepted with the accept() function before they can be used. Each time a connection request is accepted is frees up another slot in the pending queue.

Parameters
addrThe address from which to accept connections. INADDR_ANY will accept all connections.
portThe network port number to listen on.
maxpendThe maximum number of pending connection requests allowed for the listen socket.
localIpAddressThe IP address of the network interface to listen on. If two interfaces have the same address, the lower numbered interface will be used.
Returns
A value greater than 0 on success, representing the socket file descriptor. A value less than 0 on error, TCP Socket Status.
See also
accept(), listen(), close()

◆ listenvia() [2/2]

int listenvia ( const IPADDR addr,
uint16_t  port,
int  ifn,
uint8_t  maxpend = 5 
)
inline

Listen for incoming connections on the specified network interface IP address.

Begin listening for incoming connections. A connection must be accepted with the accept() function before they can be used. Each time a connection request is accepted is frees up another slot in the pending queue.

Parameters
addrThe address from which to accept connections. INADDR_ANY will accept all connections.
portThe network port number to listen on.
maxpendThe maximum number of pending connection requests allowed for the listen socket.
ifnInterface Number of the network Interface to be used.
Returns
A value greater than 0 on success, representing the socket file descriptor. A value less than 0 on error, TCP Socket Status.
See also
accept(), listen(), close()

◆ NoBlockConnect()

int NoBlockConnect ( const IPADDR ipAddress,
uint16_t  remotePort 
)
inline

Create a file descriptor for a TCP connection and return immediately. This function does not wait for a connection to be established. Before using the file descriptor, the application must verify the connection was successful with TcpGetSocketState(fd). The state will be TCP_STATE_ESTABLISHED when the connection has been successfully established. Note: The connection status can also be obtained with the wireavail() function.

Warning
To free system resources a close() must be called, even if the current state is TCP_STATE_CLOSING. Otherwise a resource leak will occur.
Parameters
ipAddressRemote IP address.
remotePortRemote port number.
Returns
A value greater than 0 on success, representing the socket file descriptor. A value less than 0 on error, TCP Socket Status.
See also
NoBlockConnectVia(), TcpGetSocketState(), writeavail(), connect(), connectvia(), connectwlocal()

◆ NoBlockConnectVia() [1/2]

int NoBlockConnectVia ( const IPADDR ipAddress,
uint16_t  remotePort,
const IPADDR interfaceIpAddress = IPADDR::NullIP() 
)
inline

Create a file descriptor for a TCP connection and return immediately. This function does not wait for a connection to be established. Before using the file descriptor, the application must verify the connection was successful with TcpGetSocketState(fd). The state will be TCP_STATE_ESTABLISHED when the connection has been successfully established. Note: The connection status can also be obtained with the wireavail() function.

This function is the similar to NoBlockConnect(), with the additional capability of specifying the local interface IP address to use the for connection.

Warning
To free system resources a close() must be called, even if the current state is TCP_STATE_CLOSING. Otherwise a resource leak will occur.
Parameters
ipAddressRemote IP address
remotePortRemote port of socket
interfaceIpAddressOptional parameter to specify which local network interface to use for the connection. The default is IPADDR::NullIP(), which will use the default local interface.
Returns
A value greater than 0 on success, representing the socket file descriptor. A value less than 0 on error, TCP Socket Status.
See also
NoBlockConnect(), TcpGetSocketState(), writeavail(), connect(), connectvia(), connectwlocal()

◆ NoBlockConnectVia() [2/2]

int NoBlockConnectVia ( const IPADDR ipAddress,
uint16_t  remotePort,
int  ifnum 
)
inline

Create a file descriptor for a TCP connection and return immediately. This function does not wait for a connection to be established. Before using the file descriptor, the application must verify the connection was successful with TcpGetSocketState(fd). The state will be TCP_STATE_ESTABLISHED when the connection has been successfully established. Note: The connection status can also be obtained with the wireavail() function.

This function is the similar to NoBlockConnect(), with the additional capability of specifying the local interface number to use the for connection.

Warning
To free system resources a close() must be called, even if the current state is TCP_STATE_CLOSING. Otherwise a resource leak will occur.
Parameters
ipAddressRemote IP address.
remotePortRemote port number.
ifnumOptional parameter to specify which local network interface to use for the connection by Interface Number. Will override any routing based on destination.
Returns
A value greater than 0 on success, representing the socket file descriptor. A value less than 0 on error, TCP Socket Status.
See also
NoBlockConnect(), TcpGetSocketState(), writeavail(), connect(), connectvia(), connectwlocal()

◆ NoBlockConnectwlocal()

int NoBlockConnectwlocal ( const IPADDR ipAddress,
uint16_t  localPort,
uint16_t  remotePort,
IPADDR  interfaceIpAddress = IPADDR::NullIP(),
int  ifn = -1 
)
inline

Create a file descriptor for a TCP connection and return immediately. This function does not wait for a connection to be established. Before using the file descriptor, the application must verify the connection was successful with TcpGetSocketState(fd). The state will be TCP_STATE_ESTABLISHED when the connection has been successfully established. Note: The connection status can also be obtained with the wireavail() function.

This function is the similar to NoBlockConnect(), with the additional capability of specifying the local interface number or IP address to use the for connection. If not specified, it will the default local interface.

Warning
To free system resources a close() must be called, even if the current state is TCP_STATE_CLOSING. Otherwise a resource leak will occur.
Although this function that allows a local port number parameter for extreme edge cases, local port numbers should be avoided. Local port numbers create connectivity failures when a remote host has a half open socket condition.
Parameters
ipAddressIP address of the remote host.
localPortOptional parameter to specify a Local port number. Recommend this always be set to a value of 0 so a random local port number is used. Warning! Specifying a local port number will create connectivity failures if the remote host has a half open socket condition.
remotePortRemote port number.
interfaceIpAddressOptional IP address of local interface to use for connection. If not used, such as when specifying the ifn parameter, set to IPADDR::NullIP().
ifnOptional parameter to specify which local network interface to use for the connection by Interface Number. Will override any routing based on destination or interface IP address.
Returns
A value greater than 0 on success, representing the socket file descriptor. A value less than 0 on error, TCP Socket Status.
See also
TcpGetSocketState(), NoBlockConnect(), NoBlockConnectVia()

◆ SetOutOfOrderBuffers()

uint8_t SetOutOfOrderBuffers ( int  fd,
uint8_t  max 
)
inline

Set the maximum number of out-of-order TCP buffers for the specified TCP socket.

There are three types of buffers assigned to a TCP socket: receive, transmit and out of order. TCP packets may be received in sequence, or out of order. If out of order, they must be either stored for use later, or retransmitted by the sending host. The default value is 5 buffer of approximately 1500 bytes each. The maximum number is 43. A higher number of buffers can increase bulk data throughput, but will increase TCP latency if there is a problem with the connection, such as a reset.

Parameters
fdSocket file descriptor
maxMaximum number of buffers
Returns
TCP Socket Status
See also
setsockoption(), getsockoption(), clrsockoption(), SetSocketRxBuffers(), SetSocketTxBuffers()

◆ SetSocketRxBuffers()

int SetSocketRxBuffers ( int  fd,
int  n 
)

Set the number of TCP receive buffers for the specified TCP socket.

Sets the number of TCP buffers that can be accumulated on the receive socket receive buffer. Each buffer is 1548 bytes. The amount of free space in the receive buffer sets the TCP window size, controlling how much data the other side of the TCP connection is allowed to send.

When data is read from a socket, it frees up space in a buffer, allowing the other side of the TCP connection to send more data. Since the maximum window size is 65536, raising this value beyond 43 buffers has no benefit. The system default value is defined in constants.h with a value of 5 to conserve network buffers. Unless you are transferring large amounts of bulk data into your NetBurner device, the default provides more than enough space.

Parameters
fdSocket file descriptor
nNumber of buffers
Returns
TCP Socket Status
See also
setsockoption(), getsockoption(), clrsockoption(), SetSocketUnackBuffers(), SetSocketTxBuffers()

◆ SetSocketTxBuffers()

int SetSocketTxBuffers ( int  fd,
int  n 
)

Set the number of TCP transmit buffers for the specified TCP socket.

Sets the number of buffers that can be put in the transmit queue. Each buffer is 1548 bytes. The transmit queue accumulates data up to this limit regardless of the state of acknowledged buffers, or window size, from the other side of the TCP connection. This value sets the maximum size for a TCP write operation. Note: you must always check the return value of any write function to determine how many bytes were written.

Parameters
fdSocket file descriptor
nNumber of buffers
Returns
TCP Socket Status
See also
setsockoption(), getsockoption(), clrsockoption(), SetSocketRxBuffers(), SetSocketUnackBuffers(), write(), writeall()

◆ SetSocketUnackBuffers()

int SetSocketUnackBuffers ( int  fd,
uint8_t  val 
)
inline

Set the maximum number of outbound TCP buffers in the transmit un-acknowledged list for the specified TCP socket.

Sets the number of outbound TCP buffers allowed as un-acknowledged on a TCP socket. When transmitting, data moves from the TCP transmit queue to the list of un-acknowledged TCP packets once it is sent. When the other side of the TCP connection acknowledges the packet, it is removed from the un-acknowledged list. TCP can only send as many un-acknowledged buffers as the other side's TCP window size will allow.

Increasng this value will increase bulk data throughput on a fast network. Increasing the value could decreate performance on a lossy network without selective acknowledgement. Note: most PC's have selective acknowledgement enabled, many NAT routers do not.

Parameters
fdSocket file descriptor
valNumber of buffers
Returns
TCP Socket Status
See also
setsockoption(), getsockoption(), clrsockoption(), SetSocketRxBuffers(), SetSocketTxBuffers()

◆ setsockoption()

int setsockoption ( int  fd,
int  option 
)

Set TCP socket options.

Parameters
fdSocket file descriptor.
optionSocket option to set: TCP Socket Options.
Returns
A bitmask of the options for the specified socket.
See also
clrsockoption(), getsockoption(), SetSocketUnackBuffers(), SetSocketRxBuffers(), SetSocketTxBuffers()

◆ SocketPeek()

char SocketPeek ( int  fd)

Returns the next char that would be read, 0 if no data.

Parameters
fdSocket file descriptor
Returns
The next char that would be read.

◆ SockReadWithTimeout()

int SockReadWithTimeout ( int  fd,
char *  buf,
int  nbytes,
uint32_t  timeout 
)

Attempt to read from a TCP socket until the timeout expires.

The number of bytes parameter is the maximum to read. The function will return when at least 1 byte is available, so the return value must always be checked.

Parameters
fdSocket file descriptor
bufPoint to buffer to store received data
nbytesMaximum number of bytes to read
timeoutTime out in ticks per second. Recommended use is the TICKS_PER_SECOND macro. For example: TICKS_PER_SECOND * 5 for a 5 second delay.
Returns
Number of bytes read, or error TCP Socket Status

◆ TcpAllDataAcked()

BOOL TcpAllDataAcked ( int  socket)

Check the data acknowledged state of a socket.

Parameters
socketSocket file descriptor.
Returns
True if all the sent data has been acknowledged by the other side of TCP connection.
See also
WaitForSocketFlush

◆ TcpGetLastRxInterval()

uint32_t TcpGetLastRxInterval ( int  fd)

Returns the number of system Time Ticks since the last packet was received. This is the difference between the current system time and lastRxTime of the socket.

Parameters
fdThe socket file descriptor.
Returns
The number of system Time Ticks since the last packet was received on the connection.
See also
TcpGetLastRxTime()

◆ TcpGetLastRxTime()

uint32_t TcpGetLastRxTime ( int  fd)

Returns the value of system Time Ticks when the last packet was received. Used for the TCP Keep Alive feature.

Each TCP connection has a corresponding Socket_struct. One of the elements of this struct is a variable called lastRxTime, which stores the current system time tick every time a packet is received. This function enables you to find out when the last packet was received by returning LastRxTime.

This function is used in conjunction with TcpSendKeepAlive() to implement the TCP keepalive feature.

  • If lastRxTime is the same before and after a keepalive packet is sent, the client has not responded to the keepalive packet and it can be assumed that connection is lost.
  • Make sure to allow enough time for the client to respond to the keep alive packet before checking the time.
  • Do not call TcpGetLastRxTime() more often than once every second.
Parameters
fdThe socket file descriptor.
Returns
The value of system Time Ticks when the last packet was received on the connection.
See also
TcpSendKeepAlive()

◆ TcpGetRxBufferSpaceUsed()

uint16_t TcpGetRxBufferSpaceUsed ( int  fd)

Returns the number of bytes used in a socket's RX buffer.

Parameters
fdSocket file descriptor.
Returns
The number of bytes used
See also
TcpGetTxBufferAvailSpace

◆ TcpGetSocketInterface()

int TcpGetSocketInterface ( int  fd)

Return the network interface associated with a TCP socket.

Parameters
fdSocket file descriptor
Returns
The network interface number (undefined for listening sockets)

◆ TcpGetSocketState()

uint8_t TcpGetSocketState ( int  fd)

Return the current state of a TCP socket.

Parameters
fdSocket file descriptor.
Returns
The current state of the socket: TCP Socket State

◆ TcpGetTxBufferAvailSpace()

uint16_t TcpGetTxBufferAvailSpace ( int  fd)

Returns the number of bytes available in a socket's TX buffer.

Parameters
fdSocket file descriptor.
Returns
The number of bytes available
See also
TcpGetRxBufferSpaceUsed

◆ TcpSendKeepAlive()

void TcpSendKeepAlive ( int  fd)

Send a TCP keep alive packet to a remote host.

Sends an empty packet with a decremented sequence number to a remote host. The sequence number will be one less than the last time a packet was sent. The remote host will respond with a TCP acknowledgment (ACK). This function is used in conjunction with TcpGetLastRxTime() to implement the TCP keepalive feature.

Parameters
fdThe socket file descriptor
See also
TcpGetLastRxTime()

◆ WaitForSocketFlush()

BOOL WaitForSocketFlush ( int  fd,
uint32_t  ticks 
)

Wait for a socket flush operation to complete. A socket is flushed if all sent data has been acknowledged.

Parameters
fdSocket file descriptor.
ticksThe maximum number of system time ticks to wait.
Return values
trueAll the sent data has been acknowledged by the other side of TCP connection.
falseA timeout occurred.
See also
TcpAllDataAcked