⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcp.lst

📁 基于51单片机和RTL8019以太网控制器的嵌入式以太网控制程序。
💻 LST
📖 第 1 页 / 共 5 页
字号:
 548   5                                                      //说明对方丢失一个ACK
 549   5                                                      //发生重传
 550   5                                                      conxn[index].his_sequence = packSeq + data_len;
C51 COMPILER V8.02   TCP                                                                   09/21/2006 20:16:32 PAGE 10  

 551   5                                                      
 552   5                                                      tcp_send(&TCPSend,FLG_ACK,20, index);           // Send ACK
 553   5                                                      //重定保活定时器
 554   5                                                      conxn[index].aty_timer = INACTIVITY_TIME;
 555   5                                                      conxn[index].aty_stat = ATY_ACTIVE;
 556   5                                              //      seq = conxn[index].my_sequence + conxn[index].iLen;
 557   5                                              //      PrintLong(seq);
 558   5                                              //      PrintStr("-");
 559   5                                              //      PrintLong(pRxdnet->tcpframe.acknumber);
 560   5                                              //      PrintStr(" ");
 561   5                                              //      PrintByte(conxn[index].iLen);
 562   5                                              //      PrintStr(" ");
 563   5                                                      /*
 564   5                                                      //己方丢失对方ACK
 565   5                                                      if(conxn[index].iLen != 0 && pRxdnet->tcpframe.acknumber == seq)
 566   5                                                      {       
 567   5                                                              if(conxn[index].pUnAcked->bUsed)
 568   5                                                              {
 569   5                                                                      //已经ACKED了在 pUnAcked里的包
 570   5                                                                      conxn[index].pUnAcked->bUsed=FALSE;     
 571   5                                                                      //增加自己的sequence
 572   5                                                                      conxn[index].my_sequence=seq;
 573   5                                                                      conxn[index].iLen=0;
 574   5                                                                      //如果有包等待发送
 575   5                                                                      if(conxn[index].pWaitForSend->bUsed)
 576   5                                                                      {
 577   5                                                                                      //检查空间是否够
 578   5                                                                              if(conxn[index].pWaitForSend->iLen<=conxn[index].pUnAcked->iLen)
 579   5                                                                              {       
 580   5                                                                                      conxn[index].pWaitForSend->bUsed=FALSE;
 581   5                                                                                      //发送数据,并将包登记进未ACKED里面
 582   5                                                                                      tcp_senddata(&TCPSend,conxn[index].pWaitForSend->pBuf,conxn[index].pWaitForSend->iLen+20,index,0
             -);
 583   5                                                                              }
 584   5                                                                      }
 585   5                                                              }
 586   5                                                              else
 587   5                                                              {
 588   5                                                                      //ACK缓冲区未被用,则检查WaitForSend区域
 589   5                                                                      if(conxn[index].pWaitForSend->bUsed)
 590   5                                                                      {
 591   5                                                                              //检查空间是否够
 592   5                                                                              if(conxn[index].pWaitForSend->iLen<=conxn[index].pUnAcked->iLen)
 593   5                                                                              {
 594   5                                                                                      conxn[index].pWaitForSend->bUsed=FALSE;
 595   5                                                                                      //发送数据,并将包登记进未ACKED里面
 596   5                                                                                      tcp_senddata(&TCPSend,conxn[index].pWaitForSend->pBuf,conxn[index].pWaitForSend->iLen+20,index,0
             -);
 597   5                                                                              }
 598   5                                                                      }
 599   5                                                              }
 600   5                                                      }*/
 601   5                                              }
 602   4                                              else
 603   4                                              {
 604   5                                                      conxn[index].his_sequence += data_len;
 605   5                                                      seq = conxn[index].my_sequence + conxn[index].iLen;
 606   5                      //                              PrintLong(seq);
 607   5                      //                              PrintStr("-");
 608   5              //                                      PrintLong(pRxdnet->tcpframe.acknumber);
 609   5              //                                      PrintStr(" ");
 610   5              //                                      PrintByte(conxn[index].iLen);
C51 COMPILER V8.02   TCP                                                                   09/21/2006 20:16:32 PAGE 11  

 611   5              //                                      PrintStr(" ");
 612   5                                                      if(packACK == seq)
 613   5                                                      {
 614   6                                                              //重定保活定时器
 615   6                                                              conxn[index].aty_timer = INACTIVITY_TIME;
 616   6                                                              conxn[index].aty_stat = ATY_ACTIVE;
 617   6                                                              //增加自己的sequence
 618   6                                                              conxn[index].my_sequence=seq;
 619   6                                                              conxn[index].iLen=0;
 620   6                                                              tcp_send(&TCPSend,FLG_ACK,20, index);           // Send ACK
 621   6                                                              if(conxn[index].pUnAcked->bUsed)
 622   6                                                              {
 623   7                                                                      //已经ACKED了在 pUnAcked里的包
 624   7                                                                      conxn[index].pUnAcked->bUsed=FALSE;     
 625   7                                                                      //如果有包等待发送
 626   7                                                                      if(conxn[index].pWaitForSend->bUsed)
 627   7                                                                      {
 628   8                                                                              //检查空间是否够
 629   8                                                                              if(conxn[index].pWaitForSend->iLen<=conxn[index].pUnAcked->iLen)
 630   8                                                                              {
 631   9                                                                                      conxn[index].pWaitForSend->bUsed=FALSE;
 632   9                                                                                      //发送数据,并将包登记进未ACKED里面
 633   9                                                                                      tcp_senddata(&TCPSend,conxn[index].pWaitForSend->pBuf,conxn[index].pWaitForSend->iLen+20,index,0
             -);
 634   9                                                                              }
 635   8                                                                      }
 636   7                                                              }
 637   6                                                              else
 638   6                                                              {
 639   7                                                                      //ACK缓冲区未被用,则检查WaitForSend区域
 640   7                                                                      if(conxn[index].pWaitForSend->bUsed)
 641   7                                                                      {
 642   8                                                                              //检查空间是否够
 643   8                                                                              if(conxn[index].pWaitForSend->iLen <= conxn[index].pUnAcked->iLen)
 644   8                                                                              {
 645   9                                                                                      conxn[index].pWaitForSend->bUsed=FALSE;
 646   9                                                                                      //发送数据,并将包登记进未ACKED里面
 647   9                                                                                      tcp_senddata(&TCPSend,conxn[index].pWaitForSend->pBuf,conxn[index].pWaitForSend->iLen+20,index,0
             -);
 648   9                                                                              }
 649   8                                                                      }
 650   7                                                              }
 651   6                                                              //      调用回调函数,通知应用程序收到数据。
 652   6                                                              (* conxn[index].recv)(pRxdnet->tcpframe.tcpdata,data_len);
 653   6                                                      }
 654   5                                              }
 655   4                                      }
 656   3                                      else
 657   3                                      {
 658   4                                              seq = conxn[index].my_sequence+conxn[index].iLen;
 659   4                                              if(packACK == seq)
 660   4                                              {
 661   5                                                      //重定保活定时器
 662   5                                                      conxn[index].aty_timer = INACTIVITY_TIME;
 663   5                                                      conxn[index].aty_stat = ATY_ACTIVE;
 664   5                                                      if(conxn[index].pUnAcked->bUsed)
 665   5                                                      {
 666   6                                                              //已经ACKED了在 pUnAcked里的包
 667   6                                                              conxn[index].pUnAcked->bUsed=FALSE;
 668   6                                                              //增加自己的sequence
 669   6                                                              conxn[index].my_sequence=seq;
 670   6                                                              conxn[index].iLen=0;            //iLen已经用于增加了my_sequence
C51 COMPILER V8.02   TCP                                                                   09/21/2006 20:16:32 PAGE 12  

 671   6                                                              //如果有包等待发送
 672   6                                                              if(conxn[index].pWaitForSend->bUsed)
 673   6                                                              {
 674   7                                                                      //检查空间是否够
 675   7                                                                      if(conxn[index].pWaitForSend->iLen<=conxn[index].pUnAcked->iLen)
 676   7                                                                      {
 677   8                                                                              conxn[index].pWaitForSend->bUsed = FALSE;
 678   8                                                                              //发送数据,并将包登记进未ACKED里面
 679   8                                                                              tcp_senddata(&TCPSend,conxn[index].pWaitForSend->pBuf,conxn[index].pWaitForSend->iLen+20,index,0)
             -;
 680   8                                                                      }
 681   7                                                              }
 682   6                                                      }
 683   5                                              }
 684   4                                              else
 685   4                                              {
 686   5                                                      //假如对方发送保活定时器请求,则返回一个正确ack
 687   5                                                      seq = seq - 1;
 688   5                                                      if(seq == packACK)
 689   5                                                      {
 690   6                                                              tcp_send(&TCPSend,FLG_ACK,20, index);   
 691   6                                                      }
 692   5                                              }
 693   4                                      }               
 694   3                                      break;
 695   3      
 696   3                              case STATE_CLOSE_WAIT:
 697   3                                      // With this code, should not get here
 698   3                                      //因为在进入STATE_CLOSE_WAIT后这边马上发送一个FIN,直接进入LAST_ACK状态
 699   3      //                              if (debug) PrintStr("TCP: Oops! Rcvd unexpected message\r");
 700   3      
 701   3                                      break;
 702   3      
 703   3                              case STATE_LAST_ACK:
 704   3                                      conxn[index].his_ack = packACK;
 705   3      
 706   3                                      // If he ACK's my FIN then close
 707   3                                      if (packACK == conxn[index].my_sequence)
 708   3                                      {
 709   4                                              conxn[index].state = STATE_CLOSED;
 710   4                                              InerClose(index);
 711   4                                              just_closed = TRUE;
 712   4                                      }
 713   3                                      break;
 714   3                              case STATE_FIN_WAIT_1:
 715   3                                      // He may still be sending me data - should process it
 716   3                                      conxn[index].his_sequence += data_len;
 717   3                                      conxn[index].his_ack = packACK;
 718   3      
 719   3                                      if (pRxdnet->tcpframe.control & FLG_FIN)
 720   3                                      {
 721   4                                              // His FIN counts as a byte of data
 722   4                                              conxn[index].his_sequence++;
 723   4                                              tcp_send(&TCPSend,FLG_ACK, 20, index);
 724   4      
 725   4                                              // If he has ACK'd my FIN then we can close connection
 726   4                                              if (packACK == conxn[index].my_sequence)
 727   4                                              {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -