⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcp.h

📁 freescale k40/k60 freertos-lwip例程
💻 H
📖 第 1 页 / 共 2 页
字号:
#define TCP_SNDQUEUELEN_OVERFLOW (0xffff-3)  u16_t snd_queuelen; /* Available buffer space for sending (in tcp_segs). */      /* These are ordered by sequence number: */  struct tcp_seg *unsent;   /* Unsent (queued) segments. */  struct tcp_seg *unacked;  /* Sent but unacknowledged segments. */#if TCP_QUEUE_OOSEQ    struct tcp_seg *ooseq;    /* Received out of sequence segments. */#endif /* TCP_QUEUE_OOSEQ */  struct pbuf *refused_data; /* Data previously received but not yet taken by upper layer */#if LWIP_CALLBACK_API  /* Function to be called when more send buffer space is available.   * @param arg user-supplied argument (tcp_pcb.callback_arg)   * @param pcb the tcp_pcb which has send buffer space available   * @param space the amount of bytes available   * @return ERR_OK: try to send some data by calling tcp_output   */  err_t (* sent)(void *arg, struct tcp_pcb *pcb, u16_t space);    /* Function to be called when (in-sequence) data has arrived.   * @param arg user-supplied argument (tcp_pcb.callback_arg)   * @param pcb the tcp_pcb for which data has arrived   * @param p the packet buffer which arrived   * @param err an error argument (TODO: that is current always ERR_OK?)   * @return ERR_OK: try to send some data by calling tcp_output   */  err_t (* recv)(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);  /* Function to be called when a connection has been set up.   * @param arg user-supplied argument (tcp_pcb.callback_arg)   * @param pcb the tcp_pcb that now is connected   * @param err an error argument (TODO: that is current always ERR_OK?)   * @return value is currently ignored   */  err_t (* connected)(void *arg, struct tcp_pcb *pcb, err_t err);  /* Function which is called periodically.   * The period can be adjusted in multiples of the TCP slow timer interval   * by changing tcp_pcb.polltmr.   * @param arg user-supplied argument (tcp_pcb.callback_arg)   * @param pcb the tcp_pcb to poll for   * @return ERR_OK: try to send some data by calling tcp_output   */  err_t (* poll)(void *arg, struct tcp_pcb *pcb);  /* Function to be called whenever a fatal error occurs.   * There is no pcb parameter since most of the times, the pcb is   * already deallocated (or there is no pcb) when this function is called.   * @param arg user-supplied argument (tcp_pcb.callback_arg)   * @param err an indication why the error callback is called:   *            ERR_ABRT: aborted through tcp_abort or by a TCP timer   *            ERR_RST: the connection was reset by the remote host   */  void (* errf)(void *arg, err_t err);#endif /* LWIP_CALLBACK_API */#if LWIP_TCP_TIMESTAMPS  u32_t ts_lastacksent;  u32_t ts_recent;#endif /* LWIP_TCP_TIMESTAMPS */  /* idle time before KEEPALIVE is sent */  u32_t keep_idle;#if LWIP_TCP_KEEPALIVE  u32_t keep_intvl;  u32_t keep_cnt;#endif /* LWIP_TCP_KEEPALIVE */    /* Persist timer counter */  u32_t persist_cnt;  /* Persist timer back-off */  u8_t persist_backoff;  /* KEEPALIVE counter */  u8_t keep_cnt_sent;};struct tcp_pcb_listen {  /* Common members of all PCB types */  IP_PCB;/* Protocol specific PCB members */  TCP_PCB_COMMON(struct tcp_pcb_listen);#if TCP_LISTEN_BACKLOG  u8_t backlog;  u8_t accepts_pending;#endif /* TCP_LISTEN_BACKLOG */};#if LWIP_EVENT_APIenum lwip_event {  LWIP_EVENT_ACCEPT,  LWIP_EVENT_SENT,  LWIP_EVENT_RECV,  LWIP_EVENT_CONNECTED,  LWIP_EVENT_POLL,  LWIP_EVENT_ERR};err_t lwip_tcp_event(void *arg, struct tcp_pcb *pcb,         enum lwip_event,         struct pbuf *p,         u16_t size,         err_t err);#define TCP_EVENT_ACCEPT(pcb,err,ret)    ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\                LWIP_EVENT_ACCEPT, NULL, 0, err)#define TCP_EVENT_SENT(pcb,space,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\                   LWIP_EVENT_SENT, NULL, space, ERR_OK)#define TCP_EVENT_RECV(pcb,p,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\                LWIP_EVENT_RECV, (p), 0, (err))#define TCP_EVENT_CONNECTED(pcb,err,ret) ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\                LWIP_EVENT_CONNECTED, NULL, 0, (err))#define TCP_EVENT_POLL(pcb,ret)       ret = lwip_tcp_event((pcb)->callback_arg, (pcb),\                LWIP_EVENT_POLL, NULL, 0, ERR_OK)#define TCP_EVENT_ERR(errf,arg,err)  lwip_tcp_event((arg), NULL, \                LWIP_EVENT_ERR, NULL, 0, (err))#else /* LWIP_EVENT_API */#define TCP_EVENT_ACCEPT(pcb,err,ret)                          \  do {                                                         \    if((pcb)->accept != NULL)                                  \      (ret) = (pcb)->accept((pcb)->callback_arg,(pcb),(err));  \    else (ret) = ERR_OK;                                       \  } while (0)#define TCP_EVENT_SENT(pcb,space,ret)                          \  do {                                                         \    if((pcb)->sent != NULL)                                    \      (ret) = (pcb)->sent((pcb)->callback_arg,(pcb),(space));  \    else (ret) = ERR_OK;                                       \  } while (0)#define TCP_EVENT_RECV(pcb,p,err,ret)                           \  do {                                                          \    if((pcb)->recv != NULL) {                                   \      (ret) = (pcb)->recv((pcb)->callback_arg,(pcb),(p),(err)); \    } else {                                                    \      (ret) = tcp_recv_null(NULL, (pcb), (p), (err));           \    }                                                           \  } while (0)#define TCP_EVENT_CONNECTED(pcb,err,ret)                         \  do {                                                           \    if((pcb)->connected != NULL)                                 \      (ret) = (pcb)->connected((pcb)->callback_arg,(pcb),(err)); \    else (ret) = ERR_OK;                                         \  } while (0)#define TCP_EVENT_POLL(pcb,ret)                                \  do {                                                         \    if((pcb)->poll != NULL)                                    \      (ret) = (pcb)->poll((pcb)->callback_arg,(pcb));          \    else (ret) = ERR_OK;                                       \  } while (0)#define TCP_EVENT_ERR(errf,arg,err)                            \  do {                                                         \    if((errf) != NULL)                                         \      (errf)((arg),(err));                                     \  } while (0)#endif /* LWIP_EVENT_API *//* This structure represents a TCP segment on the unsent and unacked queues */struct tcp_seg {  struct tcp_seg *next;    /* used when putting segements on a queue */  struct pbuf *p;          /* buffer containing data + TCP header */  void *dataptr;           /* pointer to the TCP data in the pbuf */  u16_t len;               /* the TCP length of this segment */  u8_t  flags;#define TF_SEG_OPTS_MSS   (u8_t)0x01U   /* Include MSS option. */#define TF_SEG_OPTS_TS    (u8_t)0x02U   /* Include timestamp option. */  struct tcp_hdr *tcphdr;  /* the TCP header */};#define LWIP_TCP_OPT_LENGTH(flags)              \  (flags & TF_SEG_OPTS_MSS ? 4  : 0) +          \  (flags & TF_SEG_OPTS_TS  ? 12 : 0)/** This returns a TCP header option for MSS in an u32_t */#define TCP_BUILD_MSS_OPTION(x) (x) = htonl(((u32_t)2 << 24) |          \                                            ((u32_t)4 << 16) |          \                                            (((u32_t)TCP_MSS / 256) << 8) | \                                            (TCP_MSS & 255))/* Internal functions and global variables: */struct tcp_pcb *tcp_pcb_copy(struct tcp_pcb *pcb);void tcp_pcb_purge(struct tcp_pcb *pcb);void tcp_pcb_remove(struct tcp_pcb **pcblist, struct tcp_pcb *pcb);u8_t tcp_segs_free(struct tcp_seg *seg);u8_t tcp_seg_free(struct tcp_seg *seg);struct tcp_seg *tcp_seg_copy(struct tcp_seg *seg);#define tcp_ack(pcb)                               \  do {                                             \    if((pcb)->flags & TF_ACK_DELAY) {              \      (pcb)->flags &= ~TF_ACK_DELAY;               \      (pcb)->flags |= TF_ACK_NOW;                  \      tcp_output(pcb);                             \    }                                              \    else {                                         \      (pcb)->flags |= TF_ACK_DELAY;                \    }                                              \  } while (0)#define tcp_ack_now(pcb)                           \  do {                                             \    (pcb)->flags |= TF_ACK_NOW;                    \    tcp_output(pcb);                               \  } while (0)err_t tcp_send_ctrl(struct tcp_pcb *pcb, u8_t flags);err_t tcp_enqueue(struct tcp_pcb *pcb, void *dataptr, u16_t len,                  u8_t flags, u8_t apiflags, u8_t optflags);void tcp_rexmit_seg(struct tcp_pcb *pcb, struct tcp_seg *seg);void tcp_rst(u32_t seqno, u32_t ackno,       struct ip_addr *local_ip, struct ip_addr *remote_ip,       u16_t local_port, u16_t remote_port);u32_t tcp_next_iss(void);void tcp_keepalive(struct tcp_pcb *pcb);void tcp_zero_window_probe(struct tcp_pcb *pcb);#if TCP_CALCULATE_EFF_SEND_MSSu16_t tcp_eff_send_mss(u16_t sendmss, struct ip_addr *addr);#endif /* TCP_CALCULATE_EFF_SEND_MSS */#if LWIP_CALLBACK_APIerr_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err);#endif /* LWIP_CALLBACK_API */extern struct tcp_pcb *tcp_input_pcb;extern u32_t tcp_ticks;const char* tcp_debug_state_str(enum tcp_state s);#if TCP_DEBUG || TCP_INPUT_DEBUG || TCP_OUTPUT_DEBUGvoid tcp_debug_print(struct tcp_hdr *tcphdr);void tcp_debug_print_flags(u8_t flags);void tcp_debug_print_state(enum tcp_state s);void tcp_debug_print_pcbs(void);s16_t tcp_pcbs_sane(void);#else#  define tcp_debug_print(tcphdr)#  define tcp_debug_print_flags(flags)#  define tcp_debug_print_state(s)#  define tcp_debug_print_pcbs()#  define tcp_pcbs_sane() 1#endif /* TCP_DEBUG */#if NO_SYS#define tcp_timer_needed()#elsevoid tcp_timer_needed(void);#endif/* The TCP PCB lists. */union tcp_listen_pcbs_t { /* List of all TCP PCBs in LISTEN state. */  struct tcp_pcb_listen *listen_pcbs;   struct tcp_pcb *pcbs;};extern union tcp_listen_pcbs_t tcp_listen_pcbs;extern struct tcp_pcb *tcp_active_pcbs;  /* List of all TCP PCBs that are in a              state in which they accept or send              data. */extern struct tcp_pcb *tcp_tw_pcbs;      /* List of all TCP PCBs in TIME-WAIT. */extern struct tcp_pcb *tcp_tmp_pcb;      /* Only used for temporary storage. *//* Axioms about the above lists:      1) Every TCP PCB that is not CLOSED is in one of the lists.   2) A PCB is only in one of the lists.   3) All PCBs in the tcp_listen_pcbs list is in LISTEN state.   4) All PCBs in the tcp_tw_pcbs list is in TIME-WAIT state.*//* Define two macros, TCP_REG and TCP_RMV that registers a TCP PCB   with a PCB list or removes a PCB from a list, respectively. */#if 0#define TCP_REG(pcbs, npcb) do {\                            LWIP_DEBUGF(TCP_DEBUG, ("TCP_REG %p local port %d\n", npcb, npcb->local_port)); \                            for(tcp_tmp_pcb = *pcbs; \          tcp_tmp_pcb != NULL; \        tcp_tmp_pcb = tcp_tmp_pcb->next) { \                                LWIP_ASSERT("TCP_REG: already registered\n", tcp_tmp_pcb != npcb); \                            } \                            LWIP_ASSERT("TCP_REG: pcb->state != CLOSED", npcb->state != CLOSED); \                            npcb->next = *pcbs; \                            LWIP_ASSERT("TCP_REG: npcb->next != npcb", npcb->next != npcb); \                            *(pcbs) = npcb; \                            LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \              tcp_timer_needed(); \                            } while(0)#define TCP_RMV(pcbs, npcb) do { \                            LWIP_ASSERT("TCP_RMV: pcbs != NULL", *pcbs != NULL); \                            LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removing %p from %p\n", npcb, *pcbs)); \                            if(*pcbs == npcb) { \                               *pcbs = (*pcbs)->next; \                            } else for(tcp_tmp_pcb = *pcbs; tcp_tmp_pcb != NULL; tcp_tmp_pcb = tcp_tmp_pcb->next) { \                               if(tcp_tmp_pcb->next == npcb) { \                                  tcp_tmp_pcb->next = npcb->next; \                                  break; \                               } \                            } \                            npcb->next = NULL; \                            LWIP_ASSERT("TCP_RMV: tcp_pcbs sane", tcp_pcbs_sane()); \                            LWIP_DEBUGF(TCP_DEBUG, ("TCP_RMV: removed %p from %p\n", npcb, *pcbs)); \                            } while(0)#else /* LWIP_DEBUG */#define TCP_REG(pcbs, npcb)                        \  do {                                             \    npcb->next = *pcbs;                            \    *(pcbs) = npcb;                                \    tcp_timer_needed();                            \  } while (0)#define TCP_RMV(pcbs, npcb)                        \  do {                                             \    if(*(pcbs) == npcb) {                          \      (*(pcbs)) = (*pcbs)->next;                   \    }                                              \    else {                                         \      for(tcp_tmp_pcb = *pcbs;                                         \          tcp_tmp_pcb != NULL;                                         \          tcp_tmp_pcb = tcp_tmp_pcb->next) {                           \        if(tcp_tmp_pcb->next == npcb) {   \          tcp_tmp_pcb->next = npcb->next;          \          break;                                   \        }                                          \      }                                            \    }                                              \    npcb->next = NULL;                             \  } while(0)#endif /* LWIP_DEBUG */#ifdef __cplusplus}#endif#endif /* LWIP_TCP */#endif /* __LWIP_TCP_H__ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -