lwip协议栈的学习与应用-googlecode内容摘要:
tcp 的 原型: int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen) 可以看到这里的 socket 类型参数 s,实际上是个 int型 在这个函数中的第一个函数调用是 sock = get_socket(s)。 这里的 sock 变量类型是 lwip_socket,定义如下: /** Contains all internal pointers and states used for a socket */ struct lwip_socket { /** sockets currently are built on conns, each socket has one conn */ struct conn *conn。 /** data that was left from the previous read */ struct buf *lastdata。 /** offset in the data that was left from the previous read */ u16_t lastoffset。 /** number of times data was received, set by event_callback(), tested by the receive and select functions */ u16_t rcvevent。 /** number of times data was received, set by event_callback(), tested by select */ u16_t sendevent。 /** socket flags (currently, only used for O_NONBLOCK) */ u16_t flags。 /** last error that occurred on this socket */ int err。 }。 好,这个结构先不管它,接着看下 get_socket 函数的实现【也是在 src\api\】,在这里我们看到这样一条语句 sock = amp。 sockets[s]。 很明显,返回值也是这个 sock,它是根据传进来的序列号在 sockets数组中找到对应的元素并返回该元素的地址。 好了,那么这个 sockets 数组是在哪里被赋值了这些元素的呢。 进行到这里似乎应该从标准的 socket编程的开始,也就是 socket函数讲起,那我们就顺便看一下。 它对应的实际实现是下面这个函数 Int lwip_socket(int domain, int type, int protocol)【 src\api\】 19 这个函数根据不同的协议类型,也就是函数中的 type 参数,创建了一个 conn结构体的指针,接着就是用这个指针作为参数调用了 alloc_socket 函数,下面具体看下这个函数的实现 static int alloc_socket(struct conn *newconn) { int i。 /* Protect socket array */ sys_sem_wait(socksem)。 /* allocate a new socket identifier */ for (i = 0。 i NUM_SOCKETS。 ++i) { if (!sockets[i].conn) { sockets[i].conn = newconn。 sockets[i].lastdata = NULL。 sockets[i].lastoffset = 0。 sockets[i].rcvevent = 0。 sockets[i].sendevent = 1。 /* TCP send buf is empty */ sockets[i].flags = 0。 sockets[i].err = 0。 sys_sem_signal(socksem)。 return i。 } } sys_sem_signal(socksem)。 return 1。 } 对了,就是这个时候对全局变量 sockets 数组的元素赋值的。 既然都来到这 里了,那就顺便看下 conn 结构的情况吧。 它的学名叫 conn descriptor /** A conn descriptor */ struct conn { /** type of the conn (TCP, UDP or RAW) */ enum conn_type type。 /** current state of the conn */ enum conn_state state。 /** the lwIP internal protocol control block */ union { struct ip_pcb *ip。 struct tcp_pcb *tcp。 struct udp_pcb *udp。 struct raw_pcb *raw。 } pcb。 /** the last error this conn had */ 20 err_t err。 /** sem that is used to synchroneously execute functions in the core context */ sys_sem_t op_pleted。 /** mbox where received packets are stored until they are fetched by the conn application thread (can grow quite big) */ sys_mbox_t recvmbox。 /** mbox where new connections are stored until processed by the application thread */ sys_mbox_t acceptmbox。 /** only used for socket layer */ int socket。 if LWIP_SO_RCVTIMEO /** timeout to wait for new data to be received (or connections to arrive for listening conns) */ int recv_timeout。 endif /* LWIP_SO_RCVTIMEO */ if LWIP_SO_RCVBUF /** maximum amount of bytes queued in recvmbox */ int recv_bufsize。 endif /* LWIP_SO_RCVBUF */ u16_t recv_avail。 /** TCP: when data passed to conn_write doesn39。 t fit into the send buffer, this temporarily stores the message. */ struct api_msg_msg *write_msg。 /** TCP: when data passed to conn_write doesn39。 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 conn_write doesn39。 t fit into the send buffer, this temporarily stores whether to wake up the original application task if data couldn39。 t be sent in the first try. */ u8_t write_delayed。 endif /* LWIP_TCPIP_CORE_LOCKING */ /** A callback function that is informed about events for this conn */ conn_callback callback。 }。 【 src\include\lwip\】 到此,对这个结构都有些什么,做了一个大概的了解。 下面以 SOCK_STREAM 类型为例,看下 conn 的 new 过程: 在 lwip_socket 函数中有 case SOCK_DGRAM: 21 conn = conn_new_with_callback( (protocol == IPPROTO_UDPLITE) ? NETCONN_UDPLITE : NETCONN_UDP, event_callback)。 define conn_new_with_callback(t, c) conn_new_with_proto_and_callback(t, 0, c) 简略实现如下: struct conn* conn_new_with_proto_and_callback(enum conn_type t, u8_t proto, conn_callback callback) { struct conn *conn。 struct api_msg msg。 conn = conn_alloc(t, callback)。 if (conn != NULL ) { = do_newconn。 = proto。 = conn。 TCPIP_APIMSG(amp。 msg)。 } return conn。 } 主要就看 TCPIP_APIMSG 了,这个宏有两个定义,一个是 LWIP_TCPIP_CORE_LOCKING的,一个非 locking的。 分别分析这两个不同类型的函数 * Call the lower part of a conn_* function * This function has exclusive access to lwIP core code by locking it * before the function is called. err_t tcpip_apimsg_lock(struct api_msg *apimsg)【这个是可以 locking的】 { LOCK_TCPIP_CORE()。 apimsgfunction(amp。 (apimsgmsg))。 UNLOCK_TCPIP_CORE()。 return ERR_OK。 } * Call the lower part of a conn_* function * This function is then running in the thread context * of tcpip_thread and has exclusive access to lwIP core code. err_t tcpip_apimsg(struct api_msg *apimsg)【此为非 locking的】 { struct tcpip_msg msg。 22 if (mbox != SYS_MBOX_NULL) { = TCPIP_MSG_API。 = apimsg。 sys_mbox_post(mbox, amp。 msg)。 sys_arch_sem_wait(apimsgop_pleted, 0)。 return ERR_OK。 } return ERR_VAL。 } 其实,功能都是一样的,都是要对 apimsgfunction 函数的调用。 只是途径不一样而已。 看看它们的功能说明就知道了。 这么来 说 apimsgfunction 的调用很重要了。 从 conn_new_with_proto_and_callback 函数的实现,可以知道这个 function 就是 do_newconn Void do_newconn(struct api_msg_msg *msg) { if(msgconn == NULL) { pcb_new(msg)。 } /* Else? This new c。lwip协议栈的学习与应用-googlecode
相关推荐
EDIA CUT, C. 按确认键即可。 (在裁切的过程中双手扶好材料,以免材料起拱刮伤 喷头) 4. 如何设置设置加热。 A. 在喷画过程中或待机过程中,按 HEATER 键 B. 屏幕显示 (OFF OFF OFF),分别显示的是前加热,中加热,后加热 C. 按确定键,屏幕上会出现指针,按上、下键选择温度,按左、右键选着加热位置 D. 选择适当的温度, 按确认键即可 JV33 日常维护 1.
展。 物料入库情况 输出信息 : 市场开发 开发可行性报告 合同评审 合同评审表 合同、订单 顾客财产 标识清晰、保存完全好 相关的质量记录 顾客满意度 顾客满意度报告 经验证有效的纠正预防措施 竞争对手分析 收付款管理 收付款计划 收款统计报表 付款统计报表 相关文件 : 市场开发流程控制程序 合同评审程序 顾客财产控制程序 顾客满意度控制程序 收付款控制程序 C2研究和开发 输入信息 :
Customer 客户 SOP COP MOP 左图二描述公司 COP、 SOP及 MOP 过程相互关系 /作用 /节 点及 持 续 改 进 方 式 同健 (惠阳 )电子有限公司 TONG JIANG( HUIYANG) ELECTRONICS CO., LTD. 标题 Title 第四章 品质管理体系 页次 Page 1/4 制作单位 Fabrication Dept 品保处 版本
产品使用手册 _常用资料 1 169。 Landray 2020. 蓝凌 版权所有 蓝凌标准产品常用资料用户操作手册(编号: CORE01) 博贞充琢纶逊轴谴菇春堡芳闽羡戍任法空狮贬佃瘸射戚跑钩二娶攒疾章诵卓掺饥虐菏祷窿疏蒋长糖汲侣胜务侮勃芳枢揭敞真依泅籽验贿胸彬六鞠壳 (常用资料图 1:模块主页面 )LKS EKP V6. 0 产品使用手册 _常用资料 1. 0 1 169。 Landr ay
principle 4 . 3 Model officeLH .. . . 48 designingofnewspaper 12t.. .....一 ,49 4. 4 office projcct ofnewspaper designing 4 . 4I plan „„ „„„„„ „„„. 49 Careerdevelopment 442 ...„ . „. ???????? systcms