#include "lwip/opt.h" #if LWIP_NETCONN /* don't build if not configured for use in lwipopts.h */ #include "lwip/api.h" #include "lwip/pbuf.h" #include "lwip/sys.h" #include "lwip/ip.h" #include "lwip/raw.h" #include "lwip/udp.h" #include "lwip/tcp.h" #ifdef __cplusplus extern "C" { #endif struct netconn { enum netconn_type type; enum netconn_state state; union { struct ip_pcb *ip; struct tcp_pcb *tcp; struct udp_pcb *udp; struct raw_pcb *raw; } pcb; err_t err; sys_mbox_t mbox; sys_mbox_t recvmbox; sys_mbox_t acceptmbox; int socket; #if LWIP_SO_RCVTIMEO int recv_timeout; #endif /* LWIP_SO_RCVTIMEO */ u16_t recv_avail; /** TCP: when data passed to netconn_write doesn't fit into the send buffer, this temporarily stores the message. */ struct api_msg_msg *write_msg; /** TCP: when data passed to netconn_write doesn't fit into the send buffer, this temporarily stores how much is already sent. */ int write_offset; #if LWIP_TCPIP_CORE_LOCKING /** TCP: when data passed to netconn_write doesn't fit into the send buffer, this temporarily stores whether to wake up the original application task if data couldn't be sent in the first try. */ u8_t write_delayed; #endif /* LWIP_TCPIP_CORE_LOCKING */ void (* callback)(struct netconn *, enum netconn_evt, u16_t len); }; struct netbuf { struct pbuf *p, *ptr; struct ip_addr *addr; u16_t port; }; #define NETCONN_ERR(conn) ((conn)->err) #define NETBUF_COPY_PARTIAL(buf, dataptr, len, offset) \ pbuf_copy_partial((buf)->p, (dataptr), (len), (offset)) #define NETBUF_COPY(buf,dataptr,len) NETBUF_COPY_PARTIAL(buf, dataptr, len, 0) #define NETBUF_LEN(buf) ((buf)->p->tot_len) #define NETBUF_FROMADDR(buf) ((buf)->addr) #define NETBUF_FROMPORT(buf) ((buf)->port) /* Register an Network connection event */ #define API_EVENT(c,e,l) if (c->callback) { \ (*c->callback)(c, e, l); \ } #ifdef __cplusplus } #endif #endif /* LWIP_NETCONN */