Rtos API example
TCP
[Callback-style APIs]
Transmission Control Protocol for IP
.
More...
Functions | |
void | tcp_backlog_delayed (struct tcp_pcb *pcb) |
Delay accepting a connection in respect to the listen backlog: the number of outstanding connections is increased until tcp_backlog_accepted() is called. | |
void | tcp_backlog_accepted (struct tcp_pcb *pcb) |
A delayed-accept a connection is accepted (or closed/aborted): decreases the number of outstanding connections after calling tcp_backlog_delayed(). | |
err_t | tcp_close (struct tcp_pcb *pcb) |
Closes the connection held by the PCB. | |
err_t | tcp_shutdown (struct tcp_pcb *pcb, int shut_rx, int shut_tx) |
Causes all or part of a full-duplex connection of this PCB to be shut down. | |
void | tcp_abort (struct tcp_pcb *pcb) |
Aborts the connection by sending a RST (reset) segment to the remote host. | |
err_t | tcp_bind (struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) |
Binds the connection to a local port number and IP address. | |
struct tcp_pcb * | tcp_listen_with_backlog (struct tcp_pcb *pcb, u8_t backlog) |
Set the state of the connection to be LISTEN, which means that it is able to accept incoming connections. | |
struct tcp_pcb * | tcp_listen_with_backlog_and_err (struct tcp_pcb *pcb, u8_t backlog, err_t *err) |
Set the state of the connection to be LISTEN, which means that it is able to accept incoming connections. | |
void | tcp_recved (struct tcp_pcb *pcb, u16_t len) |
This function should be called by the application when it has processed the data. | |
err_t | tcp_connect (struct tcp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port, tcp_connected_fn connected) |
Connects to another host. | |
struct tcp_pcb * | tcp_new (void) |
Creates a new TCP protocol control block but doesn't place it on any of the TCP PCB lists. | |
struct tcp_pcb * | tcp_new_ip_type (u8_t type) |
Creates a new TCP protocol control block but doesn't place it on any of the TCP PCB lists. | |
void | tcp_arg (struct tcp_pcb *pcb, void *arg) |
Used to specify the argument that should be passed callback functions. | |
void | tcp_recv (struct tcp_pcb *pcb, tcp_recv_fn recv) |
Used to specify the function that should be called when a TCP connection receives data. | |
void | tcp_sent (struct tcp_pcb *pcb, tcp_sent_fn sent) |
Used to specify the function that should be called when TCP data has been successfully delivered to the remote host. | |
void | tcp_err (struct tcp_pcb *pcb, tcp_err_fn err) |
Used to specify the function that should be called when a fatal error has occurred on the connection. | |
void | tcp_accept (struct tcp_pcb *pcb, tcp_accept_fn accept) |
Used for specifying the function that should be called when a LISTENing connection has been connected to another host. | |
void | tcp_poll (struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval) |
Used to specify the function that should be called periodically from TCP. | |
err_t | tcp_write (struct tcp_pcb *pcb, const void *arg, u16_t len, u8_t apiflags) |
Write data for sending (but does not send it immediately). | |
err_t | tcp_output (struct tcp_pcb *pcb) |
Find out what we can send and send it. |
Detailed Description
Transmission Control Protocol for IP
.
- See also:
- lwIP API and Netconn API
Common functions for the TCP implementation, such as functinos for manipulating the data structures and the TCP timer functions. TCP functions related to input and output is found in tcp_in.c and tcp_out.c respectively.
Function Documentation
void tcp_abort | ( | struct tcp_pcb * | pcb ) |
Aborts the connection by sending a RST (reset) segment to the remote host.
The pcb is deallocated. This function never fails.
ATTENTION: When calling this from one of the TCP callbacks, make sure you always return ERR_ABRT (and never return ERR_ABRT otherwise or you will risk accessing deallocated memory or memory leaks!
- Parameters:
-
pcb the tcp pcb to abort
Definition at line 535 of file lwip_tcp.c.
void tcp_accept | ( | struct tcp_pcb * | pcb, |
tcp_accept_fn | accept | ||
) |
Used for specifying the function that should be called when a LISTENing connection has been connected to another host.
- Parameters:
-
pcb tcp_pcb to set the accept callback accept callback function to call for this pcb when LISTENing connection has been connected to another host
Definition at line 1769 of file lwip_tcp.c.
void tcp_arg | ( | struct tcp_pcb * | pcb, |
void * | arg | ||
) |
Used to specify the argument that should be passed callback functions.
- Parameters:
-
pcb tcp_pcb to set the callback argument arg void pointer argument to pass to callback functions
Definition at line 1695 of file lwip_tcp.c.
void tcp_backlog_accepted | ( | struct tcp_pcb * | pcb ) |
A delayed-accept a connection is accepted (or closed/aborted): decreases the number of outstanding connections after calling tcp_backlog_delayed().
ATTENTION: the caller is responsible for calling tcp_backlog_accepted() or else the backlog feature will get out of sync!
- Parameters:
-
pcb the connection pcb which is now fully accepted (or closed/aborted)
Definition at line 235 of file lwip_tcp.c.
void tcp_backlog_delayed | ( | struct tcp_pcb * | pcb ) |
Delay accepting a connection in respect to the listen backlog: the number of outstanding connections is increased until tcp_backlog_accepted() is called.
ATTENTION: the caller is responsible for calling tcp_backlog_accepted() or else the backlog feature will get out of sync!
- Parameters:
-
pcb the connection pcb which is not fully accepted yet
Definition at line 213 of file lwip_tcp.c.
Binds the connection to a local port number and IP address.
If the IP address is not given (i.e., ipaddr == NULL), the IP address of the outgoing network interface is used instead.
- Parameters:
-
pcb the tcp_pcb to bind (no check is done whether this pcb is already bound!) ipaddr the local ip address to bind to (use IP4_ADDR_ANY to bind to any local address port the local port to bind to
- Returns:
- ERR_USE if the port is already in use ERR_VAL if bind failed because the PCB is not in a valid state ERR_OK if bound
Definition at line 556 of file lwip_tcp.c.
Closes the connection held by the PCB.
Listening pcbs are freed and may not be referenced any more. Connection pcbs are freed if not yet connected and may not be referenced any more. If a connection is established (at least SYN received or in a closing state), the connection is closed, and put in a closing state. The pcb is then automatically freed in tcp_slowtmr(). It is therefore unsafe to reference it (unless an error is returned).
- Parameters:
-
pcb the tcp_pcb to close
- Returns:
- ERR_OK if connection has been closed another err_t if closing failed and pcb is not freed
Definition at line 393 of file lwip_tcp.c.
err_t tcp_connect | ( | struct tcp_pcb * | pcb, |
const ip_addr_t * | ipaddr, | ||
u16_t | port, | ||
tcp_connected_fn | connected | ||
) |
Connects to another host.
The function given as the "connected" argument will be called when the connection has been established.
- Parameters:
-
pcb the tcp_pcb used to establish the connection ipaddr the remote ip address to connect to port the remote tcp port to connect to connected callback function to call when connected (on error, the err calback will be called)
- Returns:
- ERR_VAL if invalid arguments are given ERR_OK if connect request has been sent other err_t values if connect request couldn't be sent
Definition at line 871 of file lwip_tcp.c.
void tcp_err | ( | struct tcp_pcb * | pcb, |
tcp_err_fn | err | ||
) |
Used to specify the function that should be called when a fatal error has occurred on the connection.
- Note:
- The corresponding pcb is already freed when this callback is called!
- Parameters:
-
pcb tcp_pcb to set the err callback err callback function to call for this pcb when a fatal error has occurred on the connection
Definition at line 1751 of file lwip_tcp.c.
Set the state of the connection to be LISTEN, which means that it is able to accept incoming connections.
The protocol control block is reallocated in order to consume less memory. Setting the connection to LISTEN is an irreversible process.
- Parameters:
-
pcb the original tcp_pcb backlog the incoming connections queue limit
- Returns:
- tcp_pcb used for listening, consumes less memory.
- Note:
- The original tcp_pcb is freed. This function therefore has to be called like this: tpcb = tcp_listen_with_backlog(tpcb, backlog);
Definition at line 658 of file lwip_tcp.c.
struct tcp_pcb* tcp_listen_with_backlog_and_err | ( | struct tcp_pcb * | pcb, |
u8_t | backlog, | ||
err_t * | err | ||
) | [read] |
Set the state of the connection to be LISTEN, which means that it is able to accept incoming connections.
The protocol control block is reallocated in order to consume less memory. Setting the connection to LISTEN is an irreversible process.
- Parameters:
-
pcb the original tcp_pcb backlog the incoming connections queue limit err when NULL is returned, this contains the error reason
- Returns:
- tcp_pcb used for listening, consumes less memory.
- Note:
- The original tcp_pcb is freed. This function therefore has to be called like this: tpcb = tcp_listen_with_backlog_and_err(tpcb, backlog, &err);
Definition at line 680 of file lwip_tcp.c.
struct tcp_pcb* tcp_new | ( | void | ) | [read] |
Creates a new TCP protocol control block but doesn't place it on any of the TCP PCB lists.
The pcb is not put on any list until binding using tcp_bind().
Definition at line 1654 of file lwip_tcp.c.
struct tcp_pcb* tcp_new_ip_type | ( | u8_t | type ) | [read] |
Creates a new TCP protocol control block but doesn't place it on any of the TCP PCB lists.
The pcb is not put on any list until binding using tcp_bind().
- Parameters:
-
type IP address type, see lwip_ip_addr_type definitions. If you want to listen to IPv4 and IPv6 (dual-stack) connections, supply IPADDR_TYPE_ANY as argument and bind to IP_ANY_TYPE.
- Returns:
- a new tcp_pcb that initially is in state CLOSED
Definition at line 1671 of file lwip_tcp.c.
Find out what we can send and send it.
- Parameters:
-
pcb Protocol control block for the TCP connection to send data
- Returns:
- ERR_OK if data has been sent or nothing to send another err_t on error
Definition at line 993 of file lwip_tcp_out.c.
void tcp_poll | ( | struct tcp_pcb * | pcb, |
tcp_poll_fn | poll, | ||
u8_t | interval | ||
) |
Used to specify the function that should be called periodically from TCP.
The interval is specified in terms of the TCP coarse timer interval, which is called twice a second.
Definition at line 1787 of file lwip_tcp.c.
void tcp_recv | ( | struct tcp_pcb * | pcb, |
tcp_recv_fn | recv | ||
) |
Used to specify the function that should be called when a TCP connection receives data.
- Parameters:
-
pcb tcp_pcb to set the recv callback recv callback function to call for this pcb when data is received
Definition at line 1714 of file lwip_tcp.c.
void tcp_recved | ( | struct tcp_pcb * | pcb, |
u16_t | len | ||
) |
This function should be called by the application when it has processed the data.
The purpose is to advertise a larger window when the data has been processed.
- Parameters:
-
pcb the tcp_pcb for which data is read len the amount of bytes that have been read by the application
Definition at line 788 of file lwip_tcp.c.
void tcp_sent | ( | struct tcp_pcb * | pcb, |
tcp_sent_fn | sent | ||
) |
Used to specify the function that should be called when TCP data has been successfully delivered to the remote host.
- Parameters:
-
pcb tcp_pcb to set the sent callback sent callback function to call for this pcb when data is successfully sent
Definition at line 1731 of file lwip_tcp.c.
Causes all or part of a full-duplex connection of this PCB to be shut down.
This doesn't deallocate the PCB unless shutting down both sides! Shutting down both sides is the same as calling tcp_close, so if it succeds, the PCB should not be referenced any more.
- Parameters:
-
pcb PCB to shutdown shut_rx shut down receive side if this is != 0 shut_tx shut down send side if this is != 0
- Returns:
- ERR_OK if shutdown succeeded (or the PCB has already been shut down) another err_t on error.
Definition at line 420 of file lwip_tcp.c.
Write data for sending (but does not send it immediately).
It waits in the expectation of more data being sent soon (as it can send them more efficiently by combining them together). To prompt the system to send data now, call tcp_output() after calling tcp_write().
- Parameters:
-
pcb Protocol control block for the TCP connection to enqueue data for. arg Pointer to the data to be enqueued for sending. len Data length in bytes apiflags combination of following flags : - TCP_WRITE_FLAG_COPY (0x01) data will be copied into memory belonging to the stack
- TCP_WRITE_FLAG_MORE (0x02) for TCP connection, PSH flag will not be set on last segment sent,
- Returns:
- ERR_OK if enqueued, another err_t on error
Definition at line 368 of file lwip_tcp_out.c.
Generated on Sun Jul 17 2022 08:25:37 by 1.7.2