Functions | |
int32_t | connect (SOCKET *so, void *data, uint32_t send_max, int32_t timeout) |
Actively establish a connection. More... | |
int32_t | shutdown (SOCKET *so, int32_t timeout) |
Active shut-down of a TCP connection. More... | |
SOCKET * | accept (SOCKET *so) |
Check TCP state; if connection established, the socket descriptor is returned else NULL. More... | |
int32_t | tcp_listen (SOCKET *so) |
Switch socket to listening state. More... | |
uint16_t | tcp_set_option (SOCKET *so, uint32_t option, uint32_t val) |
Set a TCP option. More... | |
int16_t | tcp_get_state (SOCKET *so) |
Determine tcp state. More... | |
uint16_t | tcp_tx_complete (SOCKET *so) |
Test if the last TCP transmission was acknowledged. More... | |
uint32_t | tcp_pending_window (SOCKET *so) |
returns the number of unacknowledged bytes More... | |
uint16_t | tcp_force_retransmit (SOCKET *so) |
force a retransmit More... | |
int16_t | tcp_set_keep_alive_time (SOCKET *so, uint32_t time) |
Set keep alive time. More... | |
void | tcp_send_zero_window (void *so) |
send a zero window packet More... | |
void | tcp_send_window_update (void *so) |
update window size More... | |
Actively establish a connection. A three-way-hand-shake is performed to negotiate transfer parameters. If a timeout of 0 is specified, this function returns immediately after a SYN is sent. You may identify the error condition by reading socket_struct ->error_code.
so | - the socket to use |
data | - pointer to a buffer to hold the data. The data type is defined by the socket. |
send_max | - specifies the maximum tries to connect to host |
timeout | - timeout if peer could not be connected measured in net_isq() loop counts |
In case of a successful connection (return code 1/true) event code SO_CONNECTION_ESTABLISHED is temporarily set. A parallel net_recv() function call or the corresponding callback function (if any) may signal this event code.
Possible error codes:
Blocking example:
Unblocking example for DSP/BIOS:
Active shut-down of a TCP connection. If socket option SO_TCP_STATE_CLOSED is not used, the socket state is switched back to TCP_LISTEN after sending out an ACK-FIN packet.
so | - the socket to use |
timeout | - timeout waiting for acknowledge finish from peer (measured in net_isq() loop counts). If timeout is zero, the socket state changes immediately to listening state (or TCP_CLOSED if SO_TCP_STATE_CLOSED is used) without waiting for a final ACK FIN from peer ( useful for hanging connection). |
SOCKET * accept | ( | SOCKET * | so | ) |
so | - listening socket |
Check TCP state; if connection established, the socket descriptor is returned else NULL.
int32_t tcp_listen | ( | SOCKET * | so | ) |
By default a netlib TCP socket is in listening state after socket_open() or shutdown(). To change this behaviour use set_socket_option() with option SO_TCP_STATE_CLOSED. This adds two additional states to the TCP state machine (TCP_CLOSED and TCPS_FIN_WAIT_2). In this case use function tcp_listen() to switch state from TCP_CLOSED to TCP_LISTEN. After shutdown() or when errors occur the socket falls back into closed state and function tcp_listen() needs to be called again.
so | - the socket to switch to listening state |
so | - valid socket |
option | - option to change |
val | - value |
set TCP option for specified socket. Two options are available:
int16_t tcp_get_state | ( | SOCKET * | so | ) |
so | - the socket to use |
This function returns the current TCP state
uint16_t tcp_tx_complete | ( | SOCKET * | so | ) |
so | - valid socket |
Check if all TCP data were acknowledged by the remote side. This may significantly decrease the performance, because a high performance TCP lives from the benefit of multiple packets being on the way (sliding window) and sending out the next portion of data even when the previous packet has not been acknowledged yet. As long as the remote side signals free buffer space, it is allowed to send out the next packet. To get track of which packets are on the way and which packets were transmitted and acknowledged, use function tcp_pending_window().
uint32_t tcp_pending_window | ( | SOCKET * | so | ) |
so | - valid socket |
This function returns the amount of data (in bytes) that is waiting for to be acknowledged (data that has been passed to the stack with function net_send()). It is useful to get track of buffers currently in use to handle ring-buffering or just to verify successful transmission. When tested for return value 0 this function replaces tcp_tx_complete().
uint16_t tcp_force_retransmit | ( | SOCKET * | so | ) |
so | - valid socket |
If this function is called, a retransmit of the oldest pending packet is forced. This is useful when the remote side has not acknowledged outstanding packets for a certain time and the DSP needs to maintain the buffers.
so | - the socket to use |
time | - keep alive time |
Set keep alive time. When a TCP connection is idle for a certain time, internet routers may drop the connection due to time-out. To prevent the connection being dropped, KEEP ALIVE packets are used. A KEEP ALIVE packet is a valid TCP packet with NULL data bytes and must be acknowledged by the remote connected side. This effect can be used to keep track of a connection path even over routers or multiple switches. When three consecutive KEEP ALIVE packets were not acknowledged by the remote side, the socket error code is set to SO_TIMED_OUT. The user can handle this condition to try a re-connect().
void tcp_send_zero_window | ( | void * | so | ) |
so | - the socket to use |
When time consuming operations are required which do not allow to call the main network processing function net_isq() (e.g. FLASH erase or program) or when no local buffer is available, use this function to prevent the remote side to send new data. This function immediately sends out a Zero Window TCP packet on the given connected socket which stops data packet transmission on this socket. Use function tcp_send_window_update() when the time consuming operation has finished or when a new buffer is available.
void tcp_send_window_update | ( | void * | so | ) |
so | - the socket to use |
This functions sends out an Window Update packet. Necessary after the TCP was stopped before by function tcp_send_zero_window().