Sequential API Internal module.
#include "lwip/opt.h"
#include "lwip/api_msg.h"
#include "lwip/ip.h"
#include "lwip/udp.h"
#include "lwip/tcp.h"
#include "lwip/raw.h"
#include "lwip/memp.h"
#include "lwip/tcpip.h"
#include "lwip/igmp.h"
#include "lwip/dns.h"
#include <string.h>
Macros | |
#define | IN_NONBLOCKING_CONNECT(conn) (((conn)->flags & NETCONN_FLAG_IN_NONBLOCKING_CONNECT) != 0) |
#define | SET_NONBLOCKING_CONNECT(conn, val) |
Functions | |
static err_t | accept_function (void *arg, struct tcp_pcb *newpcb, err_t err) |
Accept callback function for TCP netconns. More... | |
void | do_bind (struct api_msg_msg *msg) |
Bind a pcb contained in a netconn Called from netconn_bind. More... | |
void | do_close (struct api_msg_msg *msg) |
Close a TCP pcb contained in a netconn Called from netconn_close. More... | |
static void | do_close_internal (struct netconn *conn) |
Internal helper function to close a TCP netconn: since this sometimes doesn't work at the first attempt, this function is called from multiple places. More... | |
void | do_connect (struct api_msg_msg *msg) |
Connect a pcb contained inside a netconn Called from netconn_connect. More... | |
static err_t | do_connected (void *arg, struct tcp_pcb *pcb, err_t err) |
TCP callback function if a connection (opened by tcp_connect/do_connect) has been established (or reset by the remote host). More... | |
void | do_delconn (struct api_msg_msg *msg) |
Delete the pcb inside a netconn. More... | |
void | do_disconnect (struct api_msg_msg *msg) |
Connect a pcb contained inside a netconn Only used for UDP netconns. More... | |
void | do_getaddr (struct api_msg_msg *msg) |
Return a connection's local or remote address Called from netconn_getaddr. More... | |
void | do_listen (struct api_msg_msg *msg) |
Set a TCP pcb contained in a netconn into listen mode Called from netconn_listen. More... | |
void | do_newconn (struct api_msg_msg *msg) |
Create a new pcb of a specific type inside a netconn. More... | |
void | do_recv (struct api_msg_msg *msg) |
Indicate data has been received from a TCP pcb contained in a netconn Called from netconn_recv. More... | |
void | do_send (struct api_msg_msg *msg) |
Send some data on a RAW or UDP pcb contained in a netconn Called from netconn_send. More... | |
void | do_write (struct api_msg_msg *msg) |
Send some data on a TCP pcb contained in a netconn Called from netconn_write. More... | |
static err_t | do_writemore (struct netconn *conn) |
See if more data needs to be written from a previous call to netconn_write. More... | |
static void | err_tcp (void *arg, err_t err) |
Error callback function for TCP netconns. More... | |
struct netconn * | netconn_alloc (enum netconn_type t, netconn_callback callback) |
Create a new netconn (of a specific type) that has a callback function. More... | |
static void | netconn_drain (struct netconn *conn) |
Delete rcvmbox and acceptmbox of a netconn and free the left-over data in these mboxes. More... | |
void | netconn_free (struct netconn *conn) |
Delete a netconn and all its resources. More... | |
static void | pcb_new (struct api_msg_msg *msg) |
Create a new pcb of a specific type. More... | |
static err_t | poll_tcp (void *arg, struct tcp_pcb *pcb) |
Poll callback function for TCP netconns. More... | |
static err_t | recv_tcp (void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) |
Receive callback function for TCP netconns. More... | |
static err_t | sent_tcp (void *arg, struct tcp_pcb *pcb, u16_t len) |
Sent callback function for TCP netconns. More... | |
static void | setup_tcp (struct netconn *conn) |
Setup a tcp_pcb with the correct callback function pointers and their arguments. More... | |
#define IN_NONBLOCKING_CONNECT | ( | conn | ) | (((conn)->flags & NETCONN_FLAG_IN_NONBLOCKING_CONNECT) != 0) |
Referenced by do_connected(), do_delconn(), and err_tcp().
#define SET_NONBLOCKING_CONNECT | ( | conn, | |
val | |||
) |
Referenced by do_connect(), do_connected(), and err_tcp().
Accept callback function for TCP netconns.
Allocates a new netconn and posts that to conn->acceptmbox.
References netconn::acceptmbox, API_EVENT, API_MSG_DEBUG, netconn::callback, ERR_MEM, ERR_OK, ERR_VAL, netconn::last_err, LWIP_DEBUGF, netconn_alloc(), NETCONN_EVT_RCVPLUS, netconn_free(), NULL, netconn::pcb, netconn::recvmbox, setup_tcp(), sys_mbox_free(), sys_mbox_set_invalid(), sys_mbox_trypost(), sys_mbox_valid(), netconn::tcp, tcp_debug_state_str(), and netconn::type.
Referenced by do_listen().
void do_bind | ( | struct api_msg_msg * | msg | ) |
Bind a pcb contained in a netconn Called from netconn_bind.
msg | the api_msg_msg pointing to the connection and containing the IP address and port to bind to |
References api_msg_msg::bc, api_msg_msg::conn, api_msg_msg::err, ERR_IS_FATAL, ERR_VAL, netconn::last_err, api_msg_msg::msg, NETCONN_RAW, NETCONN_TCP, NETCONN_UDP, NETCONNTYPE_GROUP, NULL, netconn::pcb, netconn::raw, netconn::tcp, tcp_bind(), TCPIP_APIMSG_ACK, netconn::type, and netconn::udp.
Referenced by netconn_bind().
void do_close | ( | struct api_msg_msg * | msg | ) |
Close a TCP pcb contained in a netconn Called from netconn_close.
msg | the api_msg_msg pointing to the connection |
References api_msg_msg::conn, netconn::current_msg, do_close_internal(), api_msg_msg::err, ERR_CONN, ERR_INPROGRESS, ERR_VAL, LWIP_ASSERT, api_msg_msg::msg, NETCONN_CLOSE, netconn_drain(), NETCONN_LISTEN, NETCONN_NONE, NETCONN_SHUT_RD, NETCONN_SHUT_RDWR, NETCONN_TCP, NULL, netconn::op_completed, netconn::pcb, api_msg_msg::sd, netconn::state, sys_sem_signal(), netconn::tcp, netconn::type, and netconn::write_offset.
Referenced by netconn_close_shutdown().
Internal helper function to close a TCP netconn: since this sometimes doesn't work at the first attempt, this function is called from multiple places.
conn | the TCP netconn to close |
References API_EVENT, close, netconn::current_msg, api_msg_msg::err, ERR_OK, err_tcp(), LISTEN, LWIP_ASSERT, api_msg_msg::msg, NETCONN_CLOSE, NETCONN_EVT_ERROR, NETCONN_EVT_RCVPLUS, NETCONN_EVT_SENDPLUS, NETCONN_NONE, NETCONN_SHUT_RD, NETCONN_SHUT_RDWR, NETCONN_SHUT_WR, NETCONN_TCP, NULL, netconn::op_completed, netconn::pcb, poll_tcp(), api_msg_msg::sd, sent_tcp(), netconn::state, sys_sem_signal(), netconn::tcp, tcp_accept(), tcp_arg(), tcp_close(), tcp_err(), tcp_poll(), tcp_recv(), tcp_sent(), tcp_shutdown(), and netconn::type.
Referenced by do_close(), do_delconn(), poll_tcp(), and sent_tcp().
void do_connect | ( | struct api_msg_msg * | msg | ) |
Connect a pcb contained inside a netconn Called from netconn_connect.
msg | the api_msg_msg pointing to the connection and containing the IP address and port to connect to |
References api_msg_msg::bc, api_msg_msg::conn, netconn::current_msg, do_connected(), api_msg_msg::err, ERR_CLSD, ERR_INPROGRESS, ERR_ISCONN, ERR_OK, ERR_VAL, LWIP_ERROR(), api_msg_msg::msg, NETCONN_CONNECT, netconn_is_nonblocking, NETCONN_NONE, NETCONN_RAW, NETCONN_TCP, NETCONN_UDP, NETCONNTYPE_GROUP, NULL, netconn::op_completed, netconn::pcb, netconn::raw, SET_NONBLOCKING_CONNECT, setup_tcp(), netconn::state, sys_sem_signal(), netconn::tcp, tcp_connect(), netconn::type, and netconn::udp.
Referenced by netconn_connect().
TCP callback function if a connection (opened by tcp_connect/do_connect) has been established (or reset by the remote host).
References API_EVENT, netconn::current_msg, api_msg_msg::err, ERR_OK, ERR_VAL, IN_NONBLOCKING_CONNECT, LWIP_ASSERT, LWIP_UNUSED_ARG, NETCONN_CONNECT, NETCONN_EVT_SENDPLUS, NETCONN_NONE, NETCONN_SET_SAFE_ERR, NETCONN_TCP, NULL, netconn::op_completed, SET_NONBLOCKING_CONNECT, setup_tcp(), netconn::state, sys_sem_signal(), and netconn::type.
Referenced by do_connect().
void do_delconn | ( | struct api_msg_msg * | msg | ) |
Delete the pcb inside a netconn.
Called from netconn_delete.
msg | the api_msg_msg pointing to the connection |
References API_EVENT, api_msg_msg::conn, netconn::current_msg, do_close_internal(), api_msg_msg::err, ERR_INPROGRESS, IN_NONBLOCKING_CONNECT, LWIP_ASSERT, api_msg_msg::msg, NETCONN_CLOSE, NETCONN_CONNECT, netconn_drain(), NETCONN_EVT_RCVPLUS, NETCONN_EVT_SENDPLUS, NETCONN_LISTEN, NETCONN_NONE, NETCONN_RAW, NETCONN_SHUT_RDWR, NETCONN_TCP, NETCONN_UDP, NETCONNTYPE_GROUP, NULL, netconn::op_completed, netconn::pcb, netconn::raw, api_msg_msg::sd, netconn::state, sys_sem_signal(), sys_sem_valid(), netconn::tcp, netconn::type, netconn::udp, and netconn::write_offset.
Referenced by netconn_delete().
void do_disconnect | ( | struct api_msg_msg * | msg | ) |
Connect a pcb contained inside a netconn Only used for UDP netconns.
Called from netconn_disconnect.
msg | the api_msg_msg pointing to the connection to disconnect |
References api_msg_msg::conn, api_msg_msg::err, ERR_OK, ERR_VAL, NETCONN_UDP, NETCONNTYPE_GROUP, netconn::pcb, TCPIP_APIMSG_ACK, netconn::type, and netconn::udp.
Referenced by netconn_disconnect().
void do_getaddr | ( | struct api_msg_msg * | msg | ) |
Return a connection's local or remote address Called from netconn_getaddr.
msg | the api_msg_msg pointing to the connection |
References api_msg_msg::ad, api_msg_msg::conn, api_msg_msg::err, ERR_CONN, ERR_OK, netconn::ip, LWIP_ASSERT, api_msg_msg::msg, NETCONN_RAW, NETCONN_TCP, NETCONN_UDP, NETCONNTYPE_GROUP, NULL, netconn::pcb, netconn::raw, tcp_pcb::remote_port, netconn::tcp, TCPIP_APIMSG_ACK, netconn::type, and netconn::udp.
Referenced by netconn_getaddr().
void do_listen | ( | struct api_msg_msg * | msg | ) |
Set a TCP pcb contained in a netconn into listen mode Called from netconn_listen.
msg | the api_msg_msg pointing to the connection |
References accept_function(), netconn::acceptmbox, api_msg_msg::conn, DEFAULT_ACCEPTMBOX_SIZE, api_msg_msg::err, ERR_CONN, ERR_IS_FATAL, ERR_MEM, ERR_OK, netconn::last_err, api_msg_msg::msg, NETCONN_LISTEN, NETCONN_NONE, NETCONN_TCP, NULL, netconn::pcb, netconn::recvmbox, netconn::state, sys_mbox_free(), sys_mbox_new(), sys_mbox_set_invalid(), sys_mbox_valid(), netconn::tcp, tcp_accept(), tcp_arg(), tcp_close(), tcp_listen, tcp_listen_with_backlog(), TCPIP_APIMSG_ACK, and netconn::type.
Referenced by netconn_listen_with_backlog().
void do_newconn | ( | struct api_msg_msg * | msg | ) |
Create a new pcb of a specific type inside a netconn.
Called from netconn_new_with_proto_and_callback.
msg | the api_msg_msg describing the connection type |
References api_msg_msg::conn, api_msg_msg::err, ERR_OK, NULL, netconn::pcb, pcb_new(), netconn::tcp, and TCPIP_APIMSG_ACK.
Referenced by netconn_new_with_proto_and_callback().
void do_recv | ( | struct api_msg_msg * | msg | ) |
Indicate data has been received from a TCP pcb contained in a netconn Called from netconn_recv.
msg | the api_msg_msg pointing to the connection |
References api_msg_msg::conn, api_msg_msg::err, ERR_OK, LISTEN, api_msg_msg::msg, NETCONN_TCP, NULL, netconn::pcb, api_msg_msg::r, netconn::tcp, tcp_accepted, tcp_recved(), TCPIP_APIMSG_ACK, and netconn::type.
Referenced by netconn_accept(), netconn_recv_data(), and netconn_recved().
void do_send | ( | struct api_msg_msg * | msg | ) |
Send some data on a RAW or UDP pcb contained in a netconn Called from netconn_send.
msg | the api_msg_msg pointing to the connection |
References netbuf::addr, api_msg_msg::b, api_msg_msg::conn, api_msg_msg::err, ERR_CONN, ERR_IS_FATAL, ip_addr_isany, netconn::last_err, api_msg_msg::msg, NETBUF_FLAG_CHKSUM, NETCONN_RAW, NETCONN_UDP, NETCONNTYPE_GROUP, NULL, netbuf::p, netconn::pcb, netbuf::port, netconn::raw, netconn::tcp, TCPIP_APIMSG_ACK, netconn::type, and netconn::udp.
Referenced by netconn_send().
void do_write | ( | struct api_msg_msg * | msg | ) |
Send some data on a TCP pcb contained in a netconn Called from netconn_write.
msg | the api_msg_msg pointing to the connection |
References api_msg_msg::conn, netconn::current_msg, do_writemore(), api_msg_msg::err, ERR_CONN, ERR_INPROGRESS, ERR_IS_FATAL, ERR_OK, ERR_VAL, netconn::flags, netconn::last_err, LOCK_TCPIP_CORE, LWIP_ASSERT, api_msg_msg::msg, NETCONN_FLAG_WRITE_DELAYED, NETCONN_NONE, NETCONN_TCP, NETCONN_WRITE, NULL, netconn::op_completed, netconn::pcb, netconn::state, sys_arch_sem_wait(), netconn::tcp, TCPIP_APIMSG_ACK, netconn::type, UNLOCK_TCPIP_CORE, api_msg_msg::w, and netconn::write_offset.
Referenced by netconn_write().
See if more data needs to be written from a previous call to netconn_write.
Called initially from do_write. If the first call can't send all data (because of low memory or empty send-buffer), this function is called again from sent_tcp() or poll_tcp() to send more data. If all data is sent, the blocking application thread (waiting in netconn_write) is released.
conn | netconn (that is currently in state NETCONN_WRITE) to process |
References API_EVENT, netconn::current_msg, api_msg_msg::err, ERR_MEM, ERR_OK, ERR_WOULDBLOCK, netconn::flags, if(), LWIP_ASSERT, api_msg_msg::msg, NETCONN_DONTBLOCK, NETCONN_EVT_SENDMINUS, NETCONN_FLAG_CHECK_WRITESPACE, NETCONN_FLAG_WRITE_DELAYED, netconn_is_nonblocking, NETCONN_NONE, NETCONN_WRITE, NULL, netconn::op_completed, netconn::pcb, netconn::state, sys_sem_signal(), netconn::tcp, tcp_output(), tcp_sndbuf, TCP_SNDLOWAT, tcp_sndqueuelen, TCP_SNDQUEUELOWAT, tcp_write(), TCP_WRITE_FLAG_MORE, api_msg_msg::w, and netconn::write_offset.
Referenced by do_write(), poll_tcp(), and sent_tcp().
Error callback function for TCP netconns.
Signals conn->sem, posts to all conn mboxes and calls API_EVENT. The application thread has then to decide what to do.
References netconn::acceptmbox, API_EVENT, netconn::current_msg, api_msg_msg::err, IN_NONBLOCKING_CONNECT, netconn::last_err, LWIP_ASSERT, NETCONN_CLOSE, NETCONN_CONNECT, NETCONN_EVT_ERROR, NETCONN_EVT_RCVPLUS, NETCONN_EVT_SENDPLUS, NETCONN_NONE, NETCONN_WRITE, NULL, netconn::op_completed, netconn::pcb, netconn::recvmbox, SET_NONBLOCKING_CONNECT, netconn::state, SYS_ARCH_DECL_PROTECT(), SYS_ARCH_PROTECT(), SYS_ARCH_UNPROTECT(), sys_mbox_trypost(), sys_mbox_valid(), sys_sem_signal(), and netconn::tcp.
Referenced by do_close_internal(), and setup_tcp().
struct netconn* netconn_alloc | ( | enum netconn_type | t, |
netconn_callback | callback | ||
) |
Create a new netconn (of a specific type) that has a callback function.
The corresponding pcb is NOT created!
t | the type of 'connection' to create ( |
proto | the IP protocol for RAW IP pcbs |
callback | a function to call on status changes (RX available, TX'ed) |
References netconn::acceptmbox, netconn::callback, netconn::current_msg, DEFAULT_RAW_RECVMBOX_SIZE, DEFAULT_TCP_RECVMBOX_SIZE, DEFAULT_UDP_RECVMBOX_SIZE, ERR_OK, netconn::flags, netconn::last_err, LWIP_ASSERT, memp_free(), memp_malloc(), NETCONN_NONE, NETCONN_RAW, NETCONN_TCP, NETCONN_UDP, NETCONNTYPE_GROUP, NULL, netconn::op_completed, netconn::pcb, RECV_BUFSIZE_DEFAULT, netconn::recvmbox, netconn::socket, netconn::state, sys_mbox_new(), sys_mbox_set_invalid(), sys_sem_free(), sys_sem_new(), netconn::tcp, netconn::type, and netconn::write_offset.
Referenced by accept_function(), and netconn_new_with_proto_and_callback().
Delete rcvmbox and acceptmbox of a netconn and free the left-over data in these mboxes.
conn | the netconn to free bytes drained from recvmbox pending connections drained from acceptmbox |
References netconn::acceptmbox, netbuf_delete(), netconn_free(), NETCONN_TCP, NULL, pbuf_free(), netconn::pcb, netconn::recvmbox, SYS_MBOX_EMPTY, sys_mbox_free(), sys_mbox_set_invalid(), sys_mbox_tryfetch, sys_mbox_valid(), netconn::tcp, tcp_abort(), tcp_accepted, tcp_recved(), pbuf::tot_len, and netconn::type.
Referenced by do_close(), and do_delconn().
Delete a netconn and all its resources.
The pcb is NOT freed (since we might not be in the right thread context do this).
conn | the netconn to free |
References netconn::acceptmbox, LWIP_ASSERT, memp_free(), NULL, netconn::op_completed, netconn::pcb, netconn::recvmbox, sys_mbox_valid(), sys_sem_free(), sys_sem_set_invalid(), and netconn::tcp.
Referenced by accept_function(), netconn_delete(), and netconn_drain().
|
static |
Create a new pcb of a specific type.
Called from do_newconn().
msg | the api_msg_msg describing the connection type |
References api_msg_msg::conn, api_msg_msg::err, ERR_MEM, ERR_VAL, LWIP_ASSERT, api_msg_msg::msg, api_msg_msg::n, NETCONN_RAW, NETCONN_TCP, NETCONN_UDP, NETCONN_UDPLITE, NETCONN_UDPNOCHKSUM, NETCONNTYPE_GROUP, NULL, netconn::pcb, netconn::raw, setup_tcp(), netconn::tcp, tcp_new(), netconn::type, and netconn::udp.
Referenced by do_newconn().
Poll callback function for TCP netconns.
Wakes up an application thread that waits for a connection to close or data to be sent. The application thread then takes the appropriate action to go on.
Signals the conn->sem. netconn_close waits for conn->sem if closing failed.
References API_EVENT, do_close_internal(), do_writemore(), ERR_OK, netconn::flags, LWIP_ASSERT, LWIP_UNUSED_ARG, NETCONN_CLOSE, NETCONN_EVT_SENDPLUS, NETCONN_FLAG_CHECK_WRITESPACE, NETCONN_WRITE, NULL, netconn::pcb, netconn::state, netconn::tcp, tcp_sndbuf, TCP_SNDLOWAT, tcp_sndqueuelen, and TCP_SNDQUEUELOWAT.
Referenced by do_close_internal(), and setup_tcp().
Receive callback function for TCP netconns.
Posts the packet to conn->recvmbox, but doesn't delete it on errors.
References API_EVENT, ERR_MEM, ERR_OK, ERR_VAL, LWIP_ASSERT, LWIP_UNUSED_ARG, NETCONN_EVT_RCVPLUS, NETCONN_SET_SAFE_ERR, NULL, pbuf_free(), netconn::pcb, netconn::recvmbox, SYS_ARCH_INC, sys_mbox_trypost(), sys_mbox_valid(), netconn::tcp, tcp_recved(), and pbuf::tot_len.
Referenced by setup_tcp().
Sent callback function for TCP netconns.
Signals the conn->sem and calls API_EVENT. netconn_write waits for conn->sem if send buffer is low.
References API_EVENT, do_close_internal(), do_writemore(), ERR_OK, netconn::flags, LWIP_ASSERT, LWIP_UNUSED_ARG, NETCONN_CLOSE, NETCONN_EVT_SENDPLUS, NETCONN_FLAG_CHECK_WRITESPACE, NETCONN_WRITE, NULL, netconn::pcb, netconn::state, netconn::tcp, tcp_sndbuf, TCP_SNDLOWAT, tcp_sndqueuelen, and TCP_SNDQUEUELOWAT.
Referenced by do_close_internal(), and setup_tcp().
Setup a tcp_pcb with the correct callback function pointers and their arguments.
conn | the TCP netconn to setup |
References err_tcp(), netconn::pcb, poll_tcp(), recv_tcp(), sent_tcp(), netconn::tcp, tcp_arg(), tcp_err(), tcp_poll(), tcp_recv(), and tcp_sent().
Referenced by accept_function(), do_connect(), do_connected(), and pcb_new().