您好,欢迎来到六九路网。
搜索
您的当前位置:首页lwIP API的封装方法

lwIP API的封装方法

来源:六九路网


lwIP API的封装方法(1)

lwIP API的封装方法

#首先回顾一下TCP的raw API:

1)struct tcp_pcb *tcp_new(void)

新建一个tcp pcb

2) err_t tcp_bind(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port);

绑定端口到此tcp连接

3)struct tcp_pcb *tcp_listen(struct tcp_pcb *pcb);

进入侦听状态,如果连接进来,则会回调tcp_accept设置的回调函数

4)err_t tcp_connect(struct tcp_pcb *pcb, struct ip_addr *ipaddr, u16_t port, err_t (* connected)(void *arg, struct tcp_pcb *tpcb,

err_t err));

连接远端机子,SYN会发送出去

5)err_t tcp_write(struct tcp_pcb *pcb, void *dataptr, u16_t len, u8_t copy)

void tcp_sent(struct tcp_pcb *pcb, err_t (* sent)(void *arg, struct tcp_pcb *tpcb, u16_t len))

6)void tcp_recv(struct tcp_pcb *pcb, err_t (* recv)(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err))

void tcp_recved(struct tcp_pcb *pcb, u16_t len);

tcp_recv设置回调,在回调函数里面调用tcp_recved;

7)void tcp_poll(struct tcp_pcb *pcb, u8_t interval, err_t (* poll)(void *arg, struct tcp_pcb *tpcb));

err_t tcp_close(struct tcp_pcb *pcb);

8)void tcp_err(struct tcp_pcb *pcb, void (* err)(void *arg, err_t err)) ;

#补充:TCP的数据传送

netif建立起基本底层的网络接口

netif_init->lowlevel_init->建立起线程

->lowlevel_input->ip_input->tcp_input->tcp_process(这个很重要,3次,4次握

手都在这里)->tcp_recevice

tcp_write->tcp_enqueue->tcp_output->ip_output_if->netif[output](^_^,init的时候设置了回调)->low_level_output->

#api_msg.c

api_msg_input在tcp_thread里面的main_loop

api_msg_post被api_lib.c各个对应函数调用

#socket调用(在lwIP里面netconn)

socket->netconn_new

bind->netconn_bind

listen->netconn_listen

accept->netconn_aet

recv->netconn_recv

send->netconn_send

close->netconn_close

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 69lv.com 版权所有 湘ICP备2023021910号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务