Thread: Delay Calculatin of Packet Sending Loop

  1. #1
    Registered User
    Join Date
    Dec 2014
    Location
    Mumbai, Maharashtra, India, India
    Posts
    14

    Delay Calculatin of Packet Sending Loop

    I want to calculate the total some of delay pf receiving Side Packet .
    Code is as Follow ..
    What is weired that even if i invoke a sleep of 2 sec ,than its show delay alwts zero. Delay will be in microsec ..Is there any problem with logic or anyhting else..
    Code:
    do 
    {
    
    #pragma omp parallel private(nthreads, tid)
     {
    
      /* Obtain thread number */
      tid = omp_get_thread_num();
       if (tid == 0) 
    
       {
        nthreads = omp_get_num_threads();
        printf("Number of threads = %d\n", nthreads);
        }
        
        #pragma omp critical
        {  
              gettimeofday(&tv3,NULL);
                 if(flag==0)
              Cur_Pkt_Time=tv3.tv_sec+tv3.tv_usec;
              else
            
              {
                  Las_Pkt_Time= Cur_Pkt_Time ;
                   Cur_Pkt_Time=tv3.tv_sec+tv3.tv_usec;
                   sleep(2);
                   Delay=Delay+(Cur_Pkt_Time-Las_Pkt_Time); 
              }
              flag=1;             
              n = write(sockfd,buffer,packet_size);                   
              num_pkt_send++;
              TotalSend=TotalSend+n;
        }
        if (n < 0) 
        {
             error("ERROR writing to socket");
              exit(1);
        }
        printf("%d Bytes Send: %d\n",num_pkt_send,n);
        
        }
        gettimeofday(&tv2, NULL);
    } while((tv2.tv_sec-tv1.tv_sec)<=Sen_Loop_time);

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Code:
    Cur_Pkt_Time=tv3.tv_sec+tv3.tv_usec;
    This is incorrect. Think about what you are doing here: you are treating a microsecond the same as a second. A common way to generate integer based timestamps is to do something like this instead:
    Code:
    Cur_Pkt_Time=tv3.tv_sec*1000000ul+tv3.tv_usec;
    Now Cur_Pkt_Time is a timestamp in microseconds. Make sure that Cur_Pkt_Time is a type that can hold very large integers.
    Last edited by bithub; 12-17-2014 at 11:33 AM.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Registered User
    Join Date
    Dec 2014
    Location
    Mumbai, Maharashtra, India, India
    Posts
    14
    I tried by following modification in code .but instead of giving delay ,its giving total Loop run time which is not expected

    Code:
    while(n>0)
    {
         n = read(newsockfd,buffer,packet_size);
         if(n<packet_size) 
         overhead++; 
              gettimeofday(&tv3,NULL);
                 if(flag==0)
              Las_Pkt_Time=tv3.tv_sec*1000000ul+tv3.tv_usec;
              else
            
              {
                  
                  Cur_Pkt_Time=tv3.tv_sec*1000000ul+tv3.tv_usec;
                  Delay=Delay+(Cur_Pkt_Time-Las_Pkt_Time); 
                  Las_Pkt_Time= Cur_Pkt_Time ;
                   //sleep(2);
                   
              }
              flag=1; 
         TotalRecv=TotalRecv+n;
         num_pkt_rec++;
         printf("%d Bytes Received: %d\n",num_pkt_rec ,n);       
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem in sending dns packet
    By umarali89 in forum C Programming
    Replies: 1
    Last Post: 10-25-2009, 02:57 AM
  2. Packet sending
    By like_no_other in forum Networking/Device Communication
    Replies: 3
    Last Post: 03-03-2009, 10:46 AM
  3. Problem while constructing IP packet and sending using socket() system call
    By cavestine in forum Networking/Device Communication
    Replies: 10
    Last Post: 10-15-2007, 05:49 AM
  4. Networking (queuing delay, avg packet loss)
    By spoon_ in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-05-2005, 11:23 AM
  5. packet sending
    By Peaches in forum C Programming
    Replies: 2
    Last Post: 03-08-2002, 03:21 PM

Tags for this Thread