Analysis of interaction process between LWIP socket Layer and protocol stack layer

Source: Internet
Author: User
Tags socket connect

A great advantage of LWIP is that it supports standard socket applications, which can completely mask the underlying interactive process and bring a lot of convenience to use. Today, as an example of socket creation, connection, transceiver

The process of data interaction between the socket layer and the protocol stack layer.

(1) Socket creation

App Layer

Socket , lwip_socket , Sock_stream netconn_new_with_callback (netconn_tcp)

tcpip_apimsg (msg.type=tcpip_msg_api, msg.function = do_newconn) sends a message and waits for

TCP/IP protocol stack layer

Case TCPIP_MSG_API:msg.function = do_newconn - sys_mbox_fetch by Tcpip_thread - > pcb_new (netconn_tcp) , tcp_new ( ), tcp_alloc ()

Pcb=memp_malloc (), PCB initialization , return

(2) Socket connect process

Data processing Flow:

APP Layer

tcpip_apimsg ( &msg) , Netconn_connect, Lwip_connect, connect, Msg.type = Tcpip_msg_api, msg.function = do_connect)

sys_mbox_post (mbox, &msg);


TCP/IP protocol stack layer

Pass

tcpip_thread,sys_mbox_fetch,tcpip_msg_api:do_connect, setup_ TCP (Setup recv_tcp, Sent_tcp, Poll_tcp and Err_tcp),tcp_connect (Setup

paramters) - Tcp_enqueue (Enqueue data for transmission), tcp_output, tcp_output_segment- >ip_output,ip_output_if->(netif->output)

Low_level_, etharp_output, etharp_send_ip , Netif->linkoutput Output. Automatically handle the handshake process

After the connection is established, the data is sent and received, and the following diagram shows the flow process of the data clearly:

 

(3) Data recv receiving process:


TCP/IP protocol stack layer

ethernetif_input, low_level_input , s_pxnetif->input), Tcpip _input- sys_mbox_trypost

(Msg->type = tcpip_msg_inpkt), tcpip_thread,sys_mbox_fetch, Case TCPIP_MSG_INPKT: (1 or 2)

1. Ethernet_input (ARP packet processing), etharp_arp_input,update_arp_entry (arp_request->setup ARP reply - netif->linkoutput) or (arp_reply-> updated

The ARP cache)

2. Ip_input- tcp_input (to the PCB linked list to query the relevant operation of each PCB, processing should reply to the data, according to the content call Tcp_event_err, tcp_event_recv-

> Sys_mbox_trypost send email to app layer)

APP Layer

The Connect call returns.

(4) Data send process

APP Layer

Send->lwip_send->netconn_write-> (msg.type=tcpip_msg_api, msg.function = do_write)

Send Message

TCP/IP protocol stack layer

Pass

Tcpip_thread->sys_mbox_fetch->case Tcpip_msg_api:do_write->do_writemore (see if have more data to be sent) Tcp_write-> data to be written into

Tcp_enqueue and populates each data segment to complete the packet->tcp_output->tcp_output_segment->ip_output->ip_output_if-> (netif-> Output)

etharp_output->etharp_send_ip, (netif->linkoutput), Low_level_output

Through today's analysis, the LWIP data flow process has been collated, before thoroughly understand a protocol stack to do this is necessary, and then further in-depth study.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.