LWIPÖ®SOCKETµÄʵÏÖ(5)
¹þ¹þ£¬¿ÉνÊÇÒ»Íø´ò¾¡°¡¡£¶ÔÓÚÕâ¸öº¯ÊýÖеöµ÷Óã¬ÎÒÃÇ¿´Ò»¸ö¾ÍºÃÁË£¬±ðµÄʵÏÖÒ²²î²»¶à£¬¾ÍÊǸö¸³ÖµµÄ¹ý³Ì
Void tcp_recv(struct tcp_pcb *pcb, err_t (* recv)(void *arg, struct tcp_pcb *tpcb, struct pbuf *p, err_t err)) {
pcb->recv = recv; }
setup_tcpÉÏÃæÒ²Óн²¹ý£¬ÊÇÔÚnewconnµÄʱºò±»µ÷Óõ쬴´½¨Íêpcb£¬¾ÍÊǵ÷ÓõÄÕâ¸öº¯Êý£¬ÒÔÅäÖÃÁ¬½ÓµÄ¸÷¸ö»Øµ÷º¯Êý¡£
È»¶øµ½ÕâÀïËÆºõ×ßÁËÒ»¸öËÀºúͬÀïÁË£¬Ã²ËÆÃ»ÓÐʲôµØ·½¶Ôpcb->recvÓе÷Óõ쬶øÎ¨Ò»ÓеľÍÊǽÓÊÕTCPʼþTCP_EVENT_RECVµÄºê¶¨ÒåÖС£Í¬Ê±£¬ÆäËûµÄ¼¸¸öº¯ÊýÒ²ÊÇÀàËÆµÄÇé¿ö£¬ÀýÈçsend_tcpº¯Êý¡£
ÕæÊÇ¡°É½ÇîË®¾¡ÒÉÎÞ·£¬Áø°µ»¨Ã÷ÓÖÒ»´å¡±°¡¡£ÔÀ´ÉÏÃæµÄÒ²²»Ö»ÊÇËÀºúͬ¡£Õâ×îµ×²ãµÄ£¨ÔÚtcp²ã£©¾ÍÊÇtcp_input£¬ËüÊÇÖ±½Ó±»ip²ãµ÷Óõģ¬¸Ãº¯ÊýµÄ¶¨Òå×¢ÊÍÊÇÕâôдµÄ£º
* The initial input processing of TCP. It verifies the TCP header, demultiplexes * the segment between the PCBs and passes it on to tcp_process(), which implements * the TCP finite state machine. This function is called by the IP layer (in ip_input()).
Àï¾ÍÒª´ÓtcpµÄÈý´ó½ÓÊÕ´¦Àíº¯Êý˵ÆðÁË¡£
Tcp_inputÓÖµ÷ÓÃÁËtcp_processº¯Êý×ö½øÒ»²½µÄ´¦Àí£¬ËüµÄ¶¨Òå×¢ÊÍÈçÏ£º
* Implements the TCP state machine. Called by tcp_input. In some * states tcp_receive() is called to receive data. The tcp_seg * argument will be freed by the caller (tcp_input()) unless the * recv_data pointer in the pcb is set.
Êǵģ¬ÏÂÃæÊÇtcp_receiveº¯Êý£¬±»tcp_processµ÷ÓÃ
* Called by tcp_process. Checks if the given segment is an ACK for outstanding * data, and if so frees the memory of the buffered data. Next, is places the
* segment on any of the receive queues (pcb->recved or pcb->ooseq). If the segment * is buffered, the pbuf is referenced by pbuf_ref so that it will not be freed until * i it has been removed from the buffer.
È»¶ø¹âÓÐÕâЩµ÷ÓÃ˳ÐòÊDz»Ðеģ¬×îÖØÒªµÄÊÇÏÂÃæÁ½¸ö±äÁ¿¡¾¶¼ÔÚtcp_in.cÖС¿ static u8_t recv_flags;
static struct pbuf *recv_data;
ÔÚtcp_receiveÖÐÓÐÒÔÏÂÖ÷Òª¼¸¾ä if (inseg.p->tot_len > 0)
{
recv_data = inseg.p; }
if (cseg->p->tot_len > 0) {
/* Chain this pbuf onto the pbuf that we will pass to the application. */ if (recv_data)
{
pbuf_cat(recv_data, cseg->p);
} else {
recv_data = cseg->p; }
cseg->p = NULL; }
ÏÂÃæµÄÕâ¸öÊÇtcp_inputÖеģ¬ÊÇÔÚtcp_process´¦ÀíÍêÖ®ºóµÄ if (recv_data != NULL) {
if(flags & TCP_PSH)
{
recv_data->flags |= PBUF_FLAG_PUSH; }
/* Notify application that data has been received. */ TCP_EVENT_RECV(pcb, recv_data, ERR_OK, err); }
¿´×îºóÒ»ÌõÓï¾ä¾ÍºÃÁË£¬ºÜÊìϤÊǰɣ¬¶ÔÁË£¬¾ÍÊÇÉÏÃæ´«ËµÖеÄËÀºúͬ£¬µ½´ËÒ²½â¿ªÁË¡£
LWIPÖ®IP²ãʵÏÖ
ÕâÒ»²¿·ÖµÄʵÏÖ¶¼ÊÇÔÚip.cÎļþÖС¾src\\cor\\ipv4¡¿£¬¿ÉÒÔ¿´µ½ÔÚÕâ¸öÎļþÖÐÖ÷ҪʵÏÖÁË3¸öº¯Êý£¬ip_input£»ip_route£»ip_outputÒÔ¼°ip_output_if¡£ÏÂÃæ·Ö±ðÀ´½éÉÜËüÃÇ¡£
ÕâЩº¯Êý¿ÉÒÔ·Ö³ÉÁ½´óÀࣺ½ÓÊպͷ¢ËÍ¡£ÏÂÃæ¾ÍÏÈ´Ó·¢ËÍ¿ªÊ¼£¬Ê×ÏÈҪ˵µÄ¾ÍÊÇip_outputº¯Êý£¬Õâ¸öÒ²ÊÇ·¢Ë͹ý³ÌÖÐ×îÖØÒªµÄÒ»¸ö£¬ËüÊDZ»tcp²ãµ÷Óõģ¬Ïêϸ¿É²Î¼ûÒÔÉÏÕ½ڡ£
* Simple interface to ip_output_if. It finds the outgoing network * interface and calls upon ip_output_if to do the actual work.
err_t ip_output(struct pbuf *p, struct ip_addr *src, struct ip_addr *dest, u8_t ttl, u8_t tos, u8_t proto) {
struct netif *netif;
if ((netif = ip_route(dest)) == NULL) { return ERR_RTE; }
return ip_output_if(p, src, dest, ttl, tos, proto, netif); }
¿ÉÒÔ¿´µ½¸Ãº¯ÊýµÄʵÏÖ¾ÍÏñ×¢ÊÍËù˵µÄÒ»Ñù£¬Ö±½Óµ÷ÓÃÁËip_routeºÍip_outputifÁ½¸öº¯Êý¡£¸ù¾ÝÒÔÍùµÄ¾Ñ飬ÏÈ¿´ÏÂnetifÕâ¸ö½á¹¹µÄʵÏÖÇé¿ö£º
* Generic data structure used for all lwIP network interfaces. * The following fields should be filled in by the initialization
* function for the device driver: hwaddr_len, hwaddr[], mtu, flags//Õ⼸¸öÊÇÒªÓÃÇý¶¯²ãÌîдµÄ
struct netif {
/** pointer to next in linked list */ struct netif *next;
/** IP address configuration in network byte order */ struct ip_addr ip_addr; struct ip_addr netmask; struct ip_addr gw;
/** This function is called by the network device driver
* to pass a packet up the TCP/IP stack. */
err_t (* input)(struct pbuf *p, struct netif *inp);
/** This function is called by the IP module when it wants
* to send a packet on the interface. This function typically * first resolves the hardware address, then sends the packet. */
err_t (* output)(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr);
/** This function is called by the ARP module when it wants
* to send a packet on the interface. This function outputs * the pbuf as-is on the link medium. */
err_t (* linkoutput)(struct netif *netif, struct pbuf *p);
#if LWIP_NETIF_STATUS_CALLBACK
/** This function is called when the netif state is set to up or down */ void (* status_callback)(struct netif *netif); #endif /* LWIP_NETIF_STATUS_CALLBACK */ ¡¡ ´Ë´¦Òþ²Ø£º1976×Ö£¬È«²¿ÎĵµÄÚÈÝÇëÏÂÔØºó²é¿´¡£Ï²»¶¾ÍÏÂÔØ°É ¡¡
ÏÂһƪ£ºÅ£½ò¸ßÖÐÓ¢ÓïÄ£¿éÒ»ÖÁÎåÖØÒª¾äÐÍ£¨ººÒëÓ¢£©Microsoft-Word-Îĵµ
Ïà¹ØÍÆ¼ö£º
- [ʵÓÃÄ£°å]µÚ°ËÕ£º·¨¹ú¡°ÐÂÀ˳±¡±Óë¡°×ó°¶ÅÉ¡±
- [ʵÓÃÄ£°å]2021Äê±±¾©ÉϰëÄêÁÙ´²Ò½Ñ§¼ìÑ鼼ʦÉúÎï
- [ʵÓÃÄ£°å]SAP GUI 7.10¿Í»§¶Ë°²×°ÅäÖÃÎĵµ
- [ʵÓÃÄ£°å]2001ÄêÁÙ´²Ö´ÒµÒ½Ê¦×ʸñ¿¼ÊÔ×ۺϱÊÊÔÊÔ
- [ʵÓÃÄ£°å]36»ú³¡¹¤×÷ʵÓÃÓ¢Óï´Ê»ã×ܽá
- [ʵÓÃÄ£°å](Ò»)Éç»á±£ÏÕ»üºË֪ͨÊé
- [ʵÓÃÄ£°å]°²È«½ÌÓýÖ÷Ìâ°à»á²ÄÁÏ
- [ʵÓÃÄ£°å]å¡ÏªÏØ´º¼¾ºôÎüµÀ´«È¾²¡·À¿ØÓ¦¼±ÑÝÁ··½
- [ʵÓÃÄ£°å]³¤É³·¿µØ²úÊг¡Öܱ¨(1.30-2.3)
- [ʵÓÃÄ£°å]ÁùÄê¼¶ÊýѧÉϲáµäÖеã - ͼÎÄ
- [ʵÓÃÄ£°å]C³ÌÐòÉè¼Æ£¨ºìƤÊ飩ϰÌâ¹Ù·½²Î¿¼´ð°¸
- [ʵÓÃÄ£°å]ÖйúÖ¤¼à»áµÚÒ»½ì´´Òµ°å·¢ÐÐÉóºËίԱ»á
- [ʵÓÃÄ£°å]ÇÅÁº¹¤³Ì¸´Ï°Ìâ
- [ʵÓÃÄ£°å]2011ѧ¶øË¼Êýѧ¼°´ð°¸
- [ʵÓÃÄ£°å]³õÖв¡¾äÐÞ¸ÄרÏîÁ·Ï°
- [ʵÓÃÄ£°å]¼àÀíѧϰ֪ʶ1 - ͼÎÄ
- [ʵÓÃÄ£°å]С»úÁé±ËÄÄê¼¶ÊÔÌâ
- [ʵÓÃÄ£°å]¹úóרҵ±ÏÒµÂÛÎÄÄ£°å
- [ʵÓÃÄ£°å]½ÌÓýѧ¸ÅÂÛ¿¼ÊÔÁ·Ï°Ìâ-ÅжÏÌâ4
- [ʵÓÃÄ£°å]2015½ì¸ß¿¼Ó¢ÓïÒ»ÂÖ¸´Ï°¾«Æ·×ÊÁÏ£¨ÒëÁÖ
- 00Nkmhe_Êг¡ÓªÏúѧ¹¤É̹ÜÀí_µç×ÓÉÌÎñ_
- ÊÂÒµµ¥Î»¿¼ÊÔ·¨Âɳ£Ê¶
- ³ÏÐŽÌÓýʵʩ·½°¸
- ¼ª´óСÌì¶ìʳƷ°²È«¼ì²âÏä·½°¸(¸ßÖеÍ
- ·¿µØ²úÏúÊÛÅàѵ×ÊÁÏ
- ¸ßÒ»µØÀí±ØÐÞ1¸´Ï°Ìá¸Ù
- иÅÄîÓ¢ÓïµÚ¶þ²álesson_1_Á·Ï°Ìâ
- ֤ȯ¹«Ë¾ÄÚ²¿Åàѵ×ÊÁÏ
- СѧӢÓïʱ¼ä½é´ÊרÏîÁ·Ï°
- ÐÂÊÀ¼ÍÓ¢Óïרҵ×ۺϽ̳Ì(µÚ¶þ°æ)µÚ1²áU
- ¡¾Ð¿α꡿Õã½Ì°æ×îÐÂ2018Äê°ËÄê¼¶Êýѧ
- ¹¤³Ì½¨Éè¹ÜÀí¸ÙÒª
- ÍâÑÐ°æ ±ØÐÞÒ»Module 4 A Social Surve
- AdobeÈÏÖ¤¿¼ÊÔ AE¸´Ï°×ÊÁÏ
- »ùÓÚH.264AVCÓëAVS±ê×¼µÄÖ¡ÄÚÔ¤²â¼¼Êõ
- ¡¶Ê³Æ·¼ìÑé»ú¹¹×ÊÖÊÈ϶¨¹ÜÀí°ì·¨¡·(ÖÊ
- ABB±äƵÆ÷Åàѵ¿Î¼þ
- (ÍêÕû°æ)Сѧ˵Ã÷ÎÄÔĶÁÁ·Ï°Ìâ¼°´ð°¸
- Éî˼Âå¿Ë(SenseLock) Éî˼IV,Éî˼4,Éî
- µÜ×Ó¹æÈ«ÎÄ´øÆ´Òô




