Beispiel #1
0
DWORD WINAPI ThreadProc(LPVOID lpParam)
{
	char ssochead[1024];  
    ssochead[0] = '\0';  
	char receive_buff[102400];  
    unsigned n_receive_len = 102400;  
    receive_buff[0] = '\0';
	char* strIP = (char*)lpParam;

	//init socket
	if(soc_init(strIP,ssochead) != 0)
	{
		return -1;
	}
	//connect
	SOCKET sock = soc_connect(strIP);
	if(sock == NULL)
	{
		return -1;
	}
	//send HTTP head
	int nret = soc_send(sock,ssochead,strlen(ssochead));
	if(nret < 0)
	{
		return -2;
	}
	// recv
	soc_recv(sock);
	//close
	soc_close(sock);
}
kal_int32 ntyHttpRecv(int sockId, U8 *buffer, int length) {
	kal_int32	ret_val;

	memset(buffer, 0, length);
	ret_val = soc_recv(sockId, buffer, length, 0);
	
	if (ret_val > 0) {
		//parse http response
		return ret_val;
	} else if (ret_val == SOC_WOULDBLOCK||ret_val == 0) {
		return 0;
	} else {
		return -1;
	}
}
Beispiel #3
0
//-----------------------------------------------------------------------------
void gps_soc_tcp_recv_response(void)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (gps_soc_transaction.state < GPS_SOC_RSP_RCVD)
    {
        int ret_val = 0;

        gps_soc_transaction.state = GPS_SOC_RSP_RCVING;
        ret_val = soc_recv(
                    gps_soc_transaction.socket_id,
                    (kal_uint8*) (gps_soc_transaction.rcvd_buffer + gps_soc_transaction.rcvd_counter),
                    (GPS_MAX_RCV_BUFFER_SIZE - gps_soc_transaction.rcvd_counter),
                    0);
        if (ret_val > 0)
        {
            gps_soc_transaction.rcvd_counter += ret_val;

            gps_soc_output_result(
                GPS_SOC_SUCCESS,
                (char*)gps_soc_transaction.rcvd_buffer,
                gps_soc_transaction.rcvd_counter);
        }
        else
        {
            if (ret_val == SOC_WOULDBLOCK)
            {
                /* waits for socket notify */
            	// msgId: MSG_ID_APP_SOC_NOTIFY_IND, 
            	// it will be handled by gps_soc_socket_notify
                return;
            }
            else
            {
                gps_soc_output_result(GPS_SOC_ERROR, NULL, 0);
            }
        }
    }
}
kal_bool EmPingRecvPkt(void)
{
   kal_int32    ret_val = -1;
   kal_uint16  i = 0;
   kal_uint32  duration = 0;
   sockaddr_struct   *addr = NULL;
   kal_char    str_buff[100];
   
   addr = &PING_CONTEXT_INFO(pingSrvAddr);
   ret_val = soc_recv(PING_CONTEXT_INFO(socketId), PING_CONTEXT_INFO(echo_rsp), 
               (PING_CONTEXT_INFO(pingSize)+8), 0);

   
   kal_sprintf(str_buff, "Rcvd !seqNO: %d, currCounterL: %d", PING_CONTEXT_INFO(seqNo), PING_CONTEXT_INFO(currCount));
   kal_print(str_buff);

   
   if(ret_val > 0)
   {
      if((PING_CONTEXT_INFO(echo_rsp[6]) *256+PING_CONTEXT_INFO(echo_rsp[7])) < PING_CONTEXT_INFO(currCount))
      {
         /* The is a invalid RSP for the waittime of this PING packet had been expiry, just ignore it */
         kal_print("Received a timed out response");
         return KAL_FALSE;
      }

      PING_CONTEXT_INFO(pingEndFN) = TMD_System_Clock;

      /* Stop timer */
      EmPingStopTimer();

      PING_CONTEXT_INFO(currCount)++;
      
      //check identifier
      if((PING_CONTEXT_INFO(echo_rsp[4]) *256+ PING_CONTEXT_INFO(echo_rsp[5])) != 100)
      {
         PING_CONTEXT_INFO(lostCounter)++;
         kal_print("Ping identifier wrong");
      }
      else
      {
         //check seq no
         if((PING_CONTEXT_INFO(echo_rsp[6]) *256+PING_CONTEXT_INFO(echo_rsp[7])) != (PING_CONTEXT_INFO(seqNo)-1))
         {
            PING_CONTEXT_INFO(lostCounter)++;
            kal_print("Ping seq no wrong");
         }
         else
         {
            //check ping data
            for(i=8;i<PING_CONTEXT_INFO(pingSize);i++)
            {
               if(PING_CONTEXT_INFO(echo_rsp[i]) != (kal_uint8)PING_CONTEXT_INFO(currCount))
               {
                  PING_CONTEXT_INFO(lostCounter)++;
                  kal_print("Ping data is wrong");
                  break;
               }
            }
            
            if(i==PING_CONTEXT_INFO(pingSize))
            {
               /* Pass all check */

               /* Calculate the time period */
               if(PING_CONTEXT_INFO(pingEndFN) >= PING_CONTEXT_INFO(pingStartFN) )
               {
                 duration = (((PING_CONTEXT_INFO(pingEndFN) - PING_CONTEXT_INFO(pingStartFN)) * 462) / 100);
               }
               else
               {
                 duration = (((2715647 + PING_CONTEXT_INFO(pingEndFN) - PING_CONTEXT_INFO(pingStartFN)) * 462) / 100);
               }

               /* Update statistics */
               if(PING_CONTEXT_INFO(maxRspMS) < duration)
                  PING_CONTEXT_INFO(maxRspMS) = duration;

               if((PING_CONTEXT_INFO(minRspMS) == 0) || (PING_CONTEXT_INFO(minRspMS) > duration))
                  PING_CONTEXT_INFO(minRspMS) = duration;
               
               PING_CONTEXT_INFO(avgRspMS) += duration;
               PING_CONTEXT_INFO(rcvdCounter)++;
               
               /* Output the result */
               kal_sprintf(str_buff,"Reply from %d.%d.%d.%d: bytes=%d time=%dms", 
                   addr->addr[0], addr->addr[1], addr->addr[2], addr->addr[3], PING_CONTEXT_INFO(pingSize), duration);
               kal_print(str_buff);
               EmPingUpdateScreen(EM_PING_RECV, duration);


               if(PING_CONTEXT_INFO(pingCount) == PING_CONTEXT_INFO(currCount)) 
               {
                  soc_close(PING_CONTEXT_INFO(socketId));
                  if(PING_CONTEXT_INFO(echo_req) != NULL)
                  {
                     OslMfree(PING_CONTEXT_INFO(echo_req));
                  }
                  if(PING_CONTEXT_INFO(echo_rsp) != NULL)
                  {
                     OslMfree(PING_CONTEXT_INFO(echo_rsp));
                  }
                  PING_CONTEXT_INFO(echo_req) = NULL;
                  PING_CONTEXT_INFO(echo_rsp) = NULL;
                  PING_CONTEXT_INFO(state) = PING_INACTIVE;

                  /* Output the statistics */
                  kal_mem_set(&str_buff[0], 0, 100);
                  kal_sprintf(str_buff,"Ping statstics for %d.%d.%d.%d:", 
                     addr->addr[0], addr->addr[1], addr->addr[2], addr->addr[3], PING_CONTEXT_INFO(pingSize), duration);
                  kal_print(str_buff);

                  kal_mem_set(&str_buff[0], 0, 100);
                  kal_sprintf(str_buff, "    Packets: Sent = %d, Received = %d, Lost = %d (%d%c loss)",
                     PING_CONTEXT_INFO(pingCount), PING_CONTEXT_INFO(rcvdCounter), PING_CONTEXT_INFO(lostCounter),
                     ((PING_CONTEXT_INFO(lostCounter)*100)/PING_CONTEXT_INFO(pingCount)), '%');
                  kal_print(str_buff);

                  kal_mem_set(&str_buff[0], 0, 100);
                  kal_sprintf(str_buff, "    Min: %dms, Max: %dms, Avg: %dms", 
                     PING_CONTEXT_INFO(minRspMS), PING_CONTEXT_INFO(maxRspMS), 
                     (PING_CONTEXT_INFO(avgRspMS)/PING_CONTEXT_INFO(rcvdCounter)));
                  kal_print(str_buff);
                  
                  EmPingUpdateScreen(EM_PING_FIN, (PING_CONTEXT_INFO(avgRspMS)/PING_CONTEXT_INFO(rcvdCounter)) );
                  
               }
            }
         }

         //PING_CONTEXT_INFO(seqNo)++;

      }

      return KAL_TRUE;
   } 
   else if(ret_val == SOC_WOULDBLOCK)
   {
      /* return KAL_FALSE to break out the for loop and wait for notification or timeout message */
      return KAL_FALSE;
   }
   else
   {
      /* If happen, ask Kavien to have a look */
      ASSERT(ret_val > 0);
   }

   return KAL_TRUE;
   
}