NetBurner 3.5.0
PDF Version |
|
Topics | |
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. | |
int | accept (int listening_socket, IPADDR *address, uint16_t *port, TickTimeout &timeout) |
Accept an incoming connection from a listening socket. | |
int | connect (const IPADDR &ipAddress, uint16_t remotePort, uint32_t timeout) |
Make an outgoing TCP connection to a remote host. | |
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. | |
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. | |
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. | |
int | listen (const IPADDR &addr, uint16_t port, uint8_t maxpend=5) |
Listen for incoming connections on the specified network interface IP address. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
IPADDR | GetSocketRemoteAddr (int fd) |
Returns the IP address of the remote host associated with the specified file descriptor. | |
IPADDR | GetSocketLocalAddr (int fd) |
Returns the IP address of the local interface associated with the connection. | |
uint16_t | GetSocketRemotePort (int fd) |
Returns the port number of the remote host associated with the connection. | |
uint16_t | GetSocketLocalPort (int fd) |
Returns the local port number associated with the connection. | |
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. | |
void | TcpSendKeepAlive (int fd) |
Send a TCP keep alive packet to a remote host. | |
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. | |
int | GetTcpRtxCount (int fd) |
Returns the number of re-transmits that have occurred on the specified connection. | |
uint8_t | SetOutOfOrderBuffers (int fd, uint8_t max) |
Set the maximum number of out-of-order TCP buffers for the specified TCP socket. | |
int | setsockoption (int fd, int option) |
Set TCP socket options. | |
int | clrsockoption (int fd, int option) |
Clear TCP socket options. | |
int | getsockoption (int fd) |
Returns the options for the specified TCP socket. | |
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. | |
int | SetSocketRxBuffers (int fd, int n) |
Set the number of TCP receive buffers for the specified TCP socket. | |
int | SetSocketTxBuffers (int fd, int n) |
Set the number of TCP transmit buffers for the specified TCP socket. | |
int | abortsocket (int fd) |
Execute an abort on the specified TCP socket. | |
int | SockReadWithTimeout (int fd, char *buf, int nbytes, uint32_t timeout) |
Attempt to read from a TCP socket until the timeout expires. | |
char | SocketPeek (int fd) |
Returns the next char that would be read, 0 if no data. | |
int | TcpGetSocketInterface (int fd) |
Return the network interface associated with a TCP socket. | |
uint8_t | TcpGetSocketState (int fd) |
Return the current state of a TCP socket. | |
uint16_t | TcpGetRxBufferSpaceUsed (int fd) |
Returns the number of bytes used in a socket's RX buffer. | |
uint16_t | TcpGetTxBufferAvailSpace (int fd) |
Returns the number of bytes available in a socket's TX buffer. | |
uint16_t | TcpGetTxDataWaiting (int fd) |
Returns the number of bytes waiting to be sent in a socket's TX Buffer. | |
BOOL | TcpAllDataAcked (int socket) |
Check the data acknowledged state of a socket. | |
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. | |
#include< tcp.h >
int abortsocket | ( | int | fd | ) |
#include <tcp.h>
Execute an abort on the specified TCP socket.
fd | Socket file descriptor |
int accept | ( | int | listening_socket, |
IPADDR * | address, | ||
uint16_t * | port, | ||
TickTimeout & | timeout ) |
#include <tcp.h>
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.
listening_socket | The listening socket from which to accept the connection. |
*address | Pointer to an IPADDR object that can store the source IP address of the connection. Can be NULL. |
*port | Pointer to a variable to store the source port number of the connection. Can be NULL. |
timeout | TickTimeout indicating how long the call should wait, before returning failure |
int accept | ( | int | listening_socket, |
IPADDR * | address, | ||
uint16_t * | port, | ||
uint16_t | timeout ) |
#include <tcp.h>
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.
listening_socket | The listening socket from which to accept the connection. |
*address | Pointer to an IPADDR object that can store the source IP address of the connection. Can be NULL. |
*port | Pointer to a variable to store the source port number of the connection. Can be NULL. |
timeout | Number of system Time Ticks to wait. A value of 0 waits forever. For example, TICKS_PER_SECOND * 5 waits five seconds. |
int clrsockoption | ( | int | fd, |
int | option ) |
#include <tcp.h>
Clear TCP socket options.
fd | Socket file descriptor. |
option | Socket option to clear: TCP Socket Options. |
|
inline |
#include <tcp.h>
Make an outgoing TCP connection to a remote host.
ipAddress | Remote IP address. |
remotePort | Remote port number. |
timeout | Timeout in system time ticks (use TICKS_PER_SECOND macro). |
|
inline |
#include <tcp.h>
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.
ipAddress | Remote IP address . |
remotePort | Remote port number. |
timeout | Timeout in system time ticks (use TICKS_PER_SECOND macro). |
localIpAddress | IP 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. |
|
inline |
#include <tcp.h>
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.
ipAddress | Remote IP address. |
remotePort | Remote port number. |
timeout | Timeout in system time ticks (use TICKS_PER_SECOND macro). |
ifnum | The local interface number. The interface number will override all routing based on the source and destination IP address. |
|
inline |
#include <tcp.h>
Make an outgoing TCP connection to a remote host using the specified local interface number or IP address.
ipAddress | Remote IP address. |
localPort | Optional 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. |
remotePort | Remote port number. |
timeout | Timeout in system time ticks (use TICKS_PER_SECOND macro). |
localIpAddress | Optional IP address of local interface to use for connection. If not used, such as when specifying the intf parameter, set to IPADDR::NullIP(). |
intf | Optional local interface number to use for connection. Do not specify if the interfaceIpAddress parameter is used. |
|
inline |
#include <tcp.h>
Returns the IP address of the local interface associated with the connection.
fd | The socket file descriptor. |
uint16_t GetSocketLocalPort | ( | int | fd | ) |
#include <tcp.h>
Returns the local port number associated with the connection.
fd | The socket file descriptor. |
|
inline |
#include <tcp.h>
Returns the IP address of the remote host associated with the specified file descriptor.
fd | The socket file descriptor. |
uint16_t GetSocketRemotePort | ( | int | fd | ) |
#include <tcp.h>
Returns the port number of the remote host associated with the connection.
fd | The socket file descriptor. |
int getsockoption | ( | int | fd | ) |
#include <tcp.h>
Returns the options for the specified TCP socket.
fd | Socket file descriptor. |
int GetTcpRtxCount | ( | int | fd | ) |
#include <tcp.h>
Returns the number of re-transmits that have occurred on the specified connection.
fd | The socket file descriptor. |
|
inline |
#include <tcp.h>
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.
addr | The address from which to accept connections. INADDR_ANY will accept all connections. |
port | The network port number to listen on. |
maxpend | The maximum number of pending connection requests allowed for the listen socket. |
|
inline |
#include <tcp.h>
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.
addr | The address from which to accept connections. INADDR_ANY will accept all connections. |
port | The network port number to listen on. |
maxpend | The maximum number of pending connection requests allowed for the listen socket. |
localIpAddress | The IP address of the network interface to listen on. If two interfaces have the same address, the lower numbered interface will be used. |
|
inline |
#include <tcp.h>
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.
addr | The address from which to accept connections. INADDR_ANY will accept all connections. |
port | The network port number to listen on. |
maxpend | The maximum number of pending connection requests allowed for the listen socket. |
ifn | Interface Number of the network Interface to be used. |
|
inline |
#include <tcp.h>
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.
ipAddress | Remote IP address. |
remotePort | Remote port number. |
|
inline |
#include <tcp.h>
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.
ipAddress | Remote IP address |
remotePort | Remote port of socket |
interfaceIpAddress | Optional parameter to specify which local network interface to use for the connection. The default is IPADDR::NullIP(), which will use the default local interface. |
|
inline |
#include <tcp.h>
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.
ipAddress | Remote IP address. |
remotePort | Remote port number. |
ifnum | Optional parameter to specify which local network interface to use for the connection by Interface Number. Will override any routing based on destination. |
|
inline |
#include <tcp.h>
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.
ipAddress | IP address of the remote host. |
localPort | Optional 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. |
remotePort | Remote port number. |
interfaceIpAddress | Optional IP address of local interface to use for connection. If not used, such as when specifying the ifn parameter, set to IPADDR::NullIP(). |
ifn | Optional 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. |
|
inline |
#include <tcp.h>
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.
fd | Socket file descriptor |
max | Maximum number of buffers |
int SetSocketRxBuffers | ( | int | fd, |
int | n ) |
#include <tcp.h>
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.
fd | Socket file descriptor |
n | Number of buffers |
int SetSocketTxBuffers | ( | int | fd, |
int | n ) |
#include <tcp.h>
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.
fd | Socket file descriptor |
n | Number of buffers |
|
inline |
#include <tcp.h>
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.
fd | Socket file descriptor |
val | Number of buffers |
int setsockoption | ( | int | fd, |
int | option ) |
#include <tcp.h>
Set TCP socket options.
fd | Socket file descriptor. |
option | Socket option to set: TCP Socket Options. |
char SocketPeek | ( | int | fd | ) |
#include <tcp.h>
Returns the next char that would be read, 0 if no data.
fd | Socket file descriptor |
int SockReadWithTimeout | ( | int | fd, |
char * | buf, | ||
int | nbytes, | ||
uint32_t | timeout ) |
#include <tcp.h>
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.
fd | Socket file descriptor |
buf | Point to buffer to store received data |
nbytes | Maximum number of bytes to read |
timeout | Time out in ticks per second. Recommended use is the TICKS_PER_SECOND macro. For example: TICKS_PER_SECOND * 5 for a 5 second delay. |
BOOL TcpAllDataAcked | ( | int | socket | ) |
#include <tcp.h>
Check the data acknowledged state of a socket.
socket | Socket file descriptor. |
uint32_t TcpGetLastRxInterval | ( | int | fd | ) |
#include <tcp.h>
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.
fd | The socket file descriptor. |
uint32_t TcpGetLastRxTime | ( | int | fd | ) |
#include <tcp.h>
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.
fd | The socket file descriptor. |
uint16_t TcpGetRxBufferSpaceUsed | ( | int | fd | ) |
#include <tcp.h>
Returns the number of bytes used in a socket's RX buffer.
fd | Socket file descriptor. |
int TcpGetSocketInterface | ( | int | fd | ) |
#include <tcp.h>
Return the network interface associated with a TCP socket.
fd | Socket file descriptor |
uint8_t TcpGetSocketState | ( | int | fd | ) |
#include <tcp.h>
Return the current state of a TCP socket.
fd | Socket file descriptor. |
uint16_t TcpGetTxBufferAvailSpace | ( | int | fd | ) |
#include <tcp.h>
Returns the number of bytes available in a socket's TX buffer.
fd | Socket file descriptor. |
uint16_t TcpGetTxDataWaiting | ( | int | fd | ) |
#include <tcp.h>
Returns the number of bytes waiting to be sent in a socket's TX Buffer.
fd | Socket file descriptor. |
void TcpSendKeepAlive | ( | int | fd | ) |
#include <tcp.h>
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.
fd | The socket file descriptor |
BOOL WaitForSocketFlush | ( | int | fd, |
uint32_t | ticks ) |
#include <tcp.h>
Wait for a socket flush operation to complete. A socket is flushed if all sent data has been acknowledged.
fd | Socket file descriptor. |
ticks | The maximum number of system time ticks to wait. |
true | All the sent data has been acknowledged by the other side of TCP connection. |
false | A timeout occurred. |