This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

急求hua例程中的TCP通信问题



各位专家:大家好!
       我采用hua例程实现TCP通讯时,在接收TCP数据时遇到一问题,花了几天时间也没解决。希望能百忙中帮忙看看。
-----------------------------------------------------------------------------------------------------------------------
问题描述:上位机做为TCP通信的客户端,在与开发板建立起TCP通信后,不断向开发板发送一个几兆大小的数据包,测试发现,在通信频繁的情况下几乎不出错,但如果停止通信几分钟后,再次通信,则必然会发现数据接收不全的情况(即丢包情况)。
-----------------------------------------------------------------------------------------------------------------------
 
       Hua例程中我的接收函数:
           while (1) {
 
           timeout.tv_sec = 1;
           timeout.tv_usec = 0;
           setsockopt(s,SOL_SOCKET,SO_RCVTIMEO,&timeout,sizeof(timeout));
 
           while(1){
                  bytes = (int)recv( s, (void *) &ctlField, sizeof(CONTROL_FIELD), 0);//ctlField结构体长度为8个字节
 
                  if(bytes > 0){
                         total = 0;
                         count = 0;
 
                            while(total < ctlField.bLength){
                                   count = (int)recv( s, (void *)(*(BigMem + ctlField.bCoreId) + total), ctlField.bLength - total, MSG_WAITALL);
                                   if(count >= 0 ){
                                          total += count;
                                          mark = 0;
                                   }
                                   else{
                                          mark++;
                                          if(mark > 5){
                                                 printf("mark > 5,count = %d, total = %d\n",count,total);
                                                 break;
                                          }
                                          continue;
                                   }
                            }
                            printf("count = %d,\ttotal = %d\n",count,total);
                  }
           }
-----------------------------------------------------------------------------------------------------------------------
运行的结果:
[C66xx_0] Start BIOS 6
[C66xx_0] QMSS successfully initialized
[C66xx_0] CPPI successfully initialized
[C66xx_0] PA successfully initialized
[C66xx_0] HUA version 2.00.00.04
[C66xx_0] Setting hostname to tidemo-CE5330
[C66xx_0] MAC Address: 90-D7-EB-0C-A9-1B
[C66xx_0] EVM in StaticIP mode at 192.168.2.100
[C66xx_0] Set IP address of PC to 192.168.2.101
[C66xx_0] PASS successfully initialized
[C66xx_0] Ethernet subsystem successfully initialized
[C66xx_0] Ethernet eventId : 48 and vectId (Interrupt) : 7
[C66xx_0] Registration of the EMAC Successful, waiting for link up ..
[C66xx_0] Network Added: If-1:192.168.2.100
[C66xx_0] count = 4300038,  total = 4300038
[C66xx_0] count = 4300038,  total = 4300038
[C66xx_0] count = 4300038,  total = 4300038
[C66xx_0] count = 4300038,  total = 4300038
[C66xx_0] count = 4300038,  total = 4300038
[C66xx_0] count = 4991129,  total = 4991129
[C66xx_0] count = 4300038,  total = 4300038
[C66xx_0] count = 4300038,  total = 4300038
[C66xx_0] count = 4300038,  total = 4300038
[C66xx_0] count = 4300038,  total = 4300038
[C66xx_0] mark > 5,count = -1, total = 1452    
[C66xx_0] count = -1,       total = 1452

其中倒数第二行是停止TCP通信几分钟后再次通信的结果,当时上位机传输的是4300038个字节的数据包,可实际只收到1452个字节的数据包(8字节的结构体包头除外)。