您的位置:首页 > 理论基础 > 计算机网络

lwIP(V1.0.0) RAW API函数源码分析4----tcp_accept()函数

2011-09-10 16:53 465 查看
位于: 位于:lwip-x.x.x/src/core/tcp.c

原型: void tcp_accept(struct tcp_pcb *pcb,

err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err))

功能: 指定处于监听状态的连接接通后将要调用的回调函数

函数源码:

/**
 * Used for specifying the function that should be called when a
 * LISTENing connection has been connected to another host.
 *处于监听状态的连接接通后,指定的函数被调用.
 * @param pcb tcp_pcb to set the accept callback
 * @param accept callback function to call for this pcb when LISTENing
 *        connection has been connected to another host
 */
void
tcp_accept(struct tcp_pcb *pcb,
     err_t (* accept)(void *arg, struct tcp_pcb *newpcb, err_t err))
{
  ((struct tcp_pcb_listen *)pcb)->accept = accept;
}


分析:将用户编写的一个函数的指针赋给处于监听状态tcp_pcb结构体中的一个参数,当处于监听状态的连接接通后,这个函数会被调用.虽然lwIP为应用嵌入式系统做了大量的精简工作,但结构体tcp_pcb还是一个庞大而复杂的数据结构,为了便于理解lwIP,对这个结构体下一番功夫还是很有必要的.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: