32 #ifndef __LWIP_TCP_H__
33 #define __LWIP_TCP_H__
41 #include "lwip/pbuf.h"
43 #include "lwip/icmp.h"
61 typedef err_t (*tcp_accept_fn)(
void *arg,
struct tcp_pcb *newpcb, err_t err);
73 typedef err_t (*tcp_recv_fn)(
void *arg,
struct tcp_pcb *tpcb,
74 struct pbuf *p, err_t err);
87 typedef err_t (*tcp_sent_fn)(
void *arg,
struct tcp_pcb *tpcb,
99 typedef err_t (*tcp_poll_fn)(
void *arg,
struct tcp_pcb *tpcb);
111 typedef void (*tcp_err_fn)(
void *arg, err_t err);
125 typedef err_t (*tcp_connected_fn)(
void *arg,
struct tcp_pcb *tpcb, err_t err);
141 #if LWIP_CALLBACK_API
149 #define DEF_ACCEPT_CALLBACK tcp_accept_fn accept;
151 #define DEF_ACCEPT_CALLBACK
157 #define TCP_PCB_COMMON(type) \
159 enum tcp_state state; \
161 void *callback_arg; \
163 DEF_ACCEPT_CALLBACK \
173 TCP_PCB_COMMON(
struct tcp_pcb);
179 #define TF_ACK_DELAY ((u8_t)0x01U)
180 #define TF_ACK_NOW ((u8_t)0x02U)
181 #define TF_INFR ((u8_t)0x04U)
182 #define TF_TIMESTAMP ((u8_t)0x08U)
183 #define TF_RXCLOSED ((u8_t)0x10U)
184 #define TF_FIN ((u8_t)0x20U)
185 #define TF_NODELAY ((u8_t)0x40U)
186 #define TF_NAGLEMEMERR ((u8_t)0x80U)
194 u32_t rcv_ann_right_edge;
198 u8_t polltmr, pollinterval;
224 u32_t snd_wl1, snd_wl2;
231 #define TCP_SNDQUEUELEN_OVERFLOW (0xffff-3)
236 u16_t unsent_oversize;
240 struct tcp_seg *unsent;
241 struct tcp_seg *unacked;
243 struct tcp_seg *ooseq;
246 struct pbuf *refused_data;
248 #if LWIP_CALLBACK_API
254 tcp_connected_fn connected;
261 #if LWIP_TCP_TIMESTAMPS
262 u32_t ts_lastacksent;
268 #if LWIP_TCP_KEEPALIVE
276 u8_t persist_backoff;
282 struct tcp_pcb_listen {
286 TCP_PCB_COMMON(
struct tcp_pcb_listen);
288 #if TCP_LISTEN_BACKLOG
290 u8_t accepts_pending;
300 LWIP_EVENT_CONNECTED,
305 err_t lwip_tcp_event(
void *arg,
struct tcp_pcb *pcb,
314 struct tcp_pcb * tcp_new (
void)ICACHE_FLASH_ATTR;
316 void tcp_arg (struct tcp_pcb *pcb,
void *arg) ICACHE_FLASH_ATTR;
317 void tcp_accept (struct tcp_pcb *pcb, tcp_accept_fn accept) ICACHE_FLASH_ATTR;
318 void tcp_recv (struct tcp_pcb *pcb, tcp_recv_fn recv) ICACHE_FLASH_ATTR;
319 void tcp_sent (struct tcp_pcb *pcb, tcp_sent_fn sent)ICACHE_FLASH_ATTR;
320 void tcp_poll (struct tcp_pcb *pcb, tcp_poll_fn poll, u8_t interval)ICACHE_FLASH_ATTR;
321 void tcp_err (struct tcp_pcb *pcb, tcp_err_fn err)ICACHE_FLASH_ATTR;
323 #define tcp_mss(pcb) (((pcb)->flags & TF_TIMESTAMP) ? ((pcb)->mss - 12) : (pcb)->mss)
324 #define tcp_sndbuf(pcb) ((pcb)->snd_buf)
325 #define tcp_sndqueuelen(pcb) ((pcb)->snd_queuelen)
326 #define tcp_nagle_disable(pcb) ((pcb)->flags |= TF_NODELAY)
327 #define tcp_nagle_enable(pcb) ((pcb)->flags &= ~TF_NODELAY)
328 #define tcp_nagle_disabled(pcb) (((pcb)->flags & TF_NODELAY) != 0)
330 #if TCP_LISTEN_BACKLOG
331 #define tcp_accepted(pcb) do { \
332 LWIP_ASSERT("pcb->state == LISTEN (called for wrong pcb?)", pcb->state == LISTEN); \
333 (((struct tcp_pcb_listen *)(pcb))->accepts_pending--); } while(0)
335 #define tcp_accepted(pcb) LWIP_ASSERT("pcb->state == LISTEN (called for wrong pcb?)", \
336 pcb->state == LISTEN)
339 void tcp_recved (
struct tcp_pcb *pcb, u16_t len)ICACHE_FLASH_ATTR;
340 err_t tcp_bind (
struct tcp_pcb *pcb, ip_addr_t *ipaddr,
341 u16_t port)ICACHE_FLASH_ATTR;
342 err_t tcp_connect (
struct tcp_pcb *pcb, ip_addr_t *ipaddr,
343 u16_t port, tcp_connected_fn connected)ICACHE_FLASH_ATTR;
345 struct tcp_pcb * tcp_listen_with_backlog(
struct tcp_pcb *pcb, u8_t backlog)ICACHE_FLASH_ATTR;
346 #define tcp_listen(pcb) tcp_listen_with_backlog(pcb, TCP_DEFAULT_LISTEN_BACKLOG)
348 void tcp_abort (
struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
349 err_t tcp_close (
struct tcp_pcb *pcb)ICACHE_FLASH_ATTR;
350 err_t tcp_shutdown(
struct tcp_pcb *pcb,
int shut_rx,
int shut_tx)ICACHE_FLASH_ATTR;
353 #define TCP_WRITE_FLAG_COPY 0x01
354 #define TCP_WRITE_FLAG_MORE 0x02
356 err_t tcp_write (
struct tcp_pcb *pcb,
const void *dataptr, u16_t len,
357 u8_t apiflags)ICACHE_FLASH_ATTR;
359 void tcp_setprio (
struct tcp_pcb *pcb, u8_t prio)ICACHE_FLASH_ATTR;
361 #define TCP_PRIO_MIN 1
362 #define TCP_PRIO_NORMAL 64
363 #define TCP_PRIO_MAX 127
365 extern err_t tcp_output(
struct tcp_pcb *pcb);
368 const char* tcp_debug_state_str(
enum tcp_state s)ICACHE_FLASH_ATTR;