云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > LWIP的底层结构

LWIP的底层结构

  • 62 次阅读
  • 3 次下载
  • 2025/5/30 15:59:58

{

LOCK_TCPIP_CORE();

apimsg->function(&(apimsg->msg)); UNLOCK_TCPIP_CORE(); return ERR_OK; }

* Call the lower part of a netconn_* 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;

if (mbox != SYS_MBOX_NULL) { msg.type = TCPIP_MSG_API; msg.msg.apimsg = apimsg; sys_mbox_post(mbox, &msg);

sys_arch_sem_wait(apimsg->msg.conn->op_completed, 0); return ERR_OK; }

return ERR_VAL; }

其实,功能都是一样的,都是要对apimsg->function函数的调用。只是途径不一样而已。看看它们的功能说明就知道了。这么来说apimsg->function的调用很重要了。从netconn_new_with_proto_and_callback函数的实现,可以知道这个function就是do_newconn

Void do_newconn(struct api_msg_msg *msg) {

if(msg->conn->pcb.tcp == NULL) { pcb_new(msg); }

/* Else? This \ /* Is this an error condition? Should it be deleted? */ /* We currently just are happy and return. */

TCPIP_APIMSG_ACK(msg); }

还是看TCP的,在pcb_new函数中有如下代码: case NETCONN_TCP:

msg->conn->pcb.tcp = tcp_new(); if(msg->conn->pcb.tcp == NULL) { msg->conn->err = ERR_MEM;

break; }

setup_tcp(msg->conn); break;

我们知道在这里建立了这个tcp的连接。至于这个超级牛的函数,以后再做介绍。

嗯,还是回过头来接着看accept函数吧。

Sock获得了,接着就是newconn = netconn_accept(sock->conn);通过mbox取得新的

连接。粗略的估计了一下,这个新的连接应该和listen有关系。那就再次打断一下,看看那个listen操作。

lwip_listen --? netconn_listen_with_backlog--? do_listen--? tcp_arg(msg->conn->pcb.tcp, msg->conn);

tcp_accept(msg->conn->pcb.tcp, accept_function);//注册了一个接受函数

* Accept callback function for TCP netconns.

* Allocates a new netconn and posts that to conn->acceptmbox.

static err_t accept_function(void *arg, struct tcp_pcb *newpcb, err_t err) {

struct netconn *newconn; struct netconn *conn;

conn = (struct netconn *)arg;

/* We have to set the callback here even though

* the new socket is unknown. conn->socket is marked as -1. */ newconn = netconn_alloc(conn->type, conn->callback); if (newconn == NULL) { return ERR_MEM; }

newconn->pcb.tcp = newpcb; setup_tcp(newconn); newconn->err = err;

/* Register event with callback */ API_EVENT(conn, NETCONN_EVT_RCVPLUS, 0);

if (sys_mbox_trypost(conn->acceptmbox, newconn) != ERR_OK) {

/* When returning != ERR_OK, the connection is aborted in tcp_process(), so do nothing here! */ newconn->pcb.tcp = NULL; netconn_free(newconn); return ERR_MEM; }

return ERR_OK; }

搜索更多关于: LWIP的底层结构 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

{ LOCK_TCPIP_CORE(); apimsg->function(&(apimsg->msg)); UNLOCK_TCPIP_CORE(); return ERR_OK; } * Call the lower part of a netconn_* 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; if (mbox !

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com