LWIP之TCP层接收相关

2009-05-12    LWIP既然定了这么个标题,当然是要从socket这个函数。它的大致过程是,先通过netconn_recv(sock->conn);中收取数据,在这里有个do_recv,关于这个函数的注释如下:
* 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.
回到主题, lwip_recvfrom ,这一步是通过 netbuf_copy_partial recvmbox 在工程中搜索 recvmbox ,就是它了。看看函数的原型:
* Receive callback function for TCP netconns.
* Posts the packet to conn->recvmbox, but doesn't delete it on errors.
static err_t recv_tcp(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
的接收回调用的。
 
       
* Setup a tcp_pcb with the correct callback function pointers
* and their arguments.
* @param conn the TCP netconn to setup
static void setup_tcp(struct netconn *conn)
{
  struct tcp_pcb *pcb;
 
  pcb = conn->pcb.tcp;
  tcp_arg(pcb, conn);
  tcp_recv(pcb, recv_tcp);
  tcp_sent(pcb, sent_tcp);
  tcp_poll(pcb, poll_tcp, 4);
  tcp_err(pcb, err_tcp);
}
的时候被调用的,创建完 pcb 有调用的,而唯一有的就是接收 TCP 函数。
 
        最底层的(在 tcp 层调用的,该函数的定义注释是这么写的:
* The initial input processing of TCP. It verifies the TCP header, demultiplexes
* the segment between the PCBs and passes it on to tcp_process(), which implements
* the TCP finite state machine. This function is called by the IP layer (in ip_input()).
 
Tcp_input 是的,下面是 tcp_receive 然而光有这些调用顺序是不行的,最重要的是下面两个变量【都在 tcp_in.c 中有以下主要几句
if (inseg.p->tot_len > 0)
{
          recv_data = inseg.p;
}
 
if (cseg->p->tot_len > 0)
{
    /* Chain this pbuf onto the pbuf that we will pass to
    the application. */
    if (recv_data)
{
         pbuf_cat(recv_data, cseg->p);
}
else
{
          recv_data = cseg->p;
     }
     cseg->p = NULL;
}
 
处理完之后的
if (recv_data != NULL)
{
          if(flags & TCP_PSH)
{
            recv_data->flags |= PBUF_FLAG_PUSH;
          }
 
          /* Notify application that data has been received. */
           TCP_EVENT_RECV(pcb, recv_data, ERR_OK, err);
}
<span times="" new="" roman';="" mso-hansi-font-family:="" 'times="" roman'"="" style="padding: 0px; margin: 0px; color: black; font-family: 宋体; ">看最后一条语句就好了,很熟悉是吧,对了,就是上面传说中的死胡同,到此也解开了。
 

本文出自 “bluefish” 博客,请务必保留此出处http://bluefish.blog.51cto.com/214870/158416

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值