Quote:
Originally Posted by xpi0t0s View Post
No I can't help. Despite me asking about five million times you still haven't said WHAT ACTUALLY GOES WRONG. So no, haven't got a clue, no idea whatsoever.


I am really sorry if I am unable to explain my problem. In short, I am unable to send the smallest time stamped packet at its play out time. I get the smallest time stamped packet when i come out of while() loop. Then I am checking this time stamp with the system clock time in the if() block. Here is the problem. I am comparing the clock time with the packet arrival time. If the packet time is smaller than the system clock time (means system clock time has already reached the packet time) then sending the packet. Here if the packet time is still greater then i dont want to wait here using any sleep or usleep or else. I only want the packet to take out from the list, when its play out time is reached and it's smallest among all packets.

I hope I have explained the problem in quite better way now. Sorry again.

Here is the code.

Code:
do
  {
  pthread_mutex_lock( &mut );


   //     pthread_mutex_lock( &mut );
      while(scurr->next!=NULL);
     {
       if(snode->ts.tv_sec < scurr->ts.tv_sec && snode->ts.tv_usec < scurr->ts.tv_usec)
        {
          TMPNode=snode;
          snode=scurr;
          scurr=TMPNode;
        }
       
       scurr=scurr->next;
     }
   
    
     
       gettimeofday(&curr_time,NULL);      
       if(curr_time.tv_sec >= snode->ts.tv_sec  && curr_time.tv_usec >= snode->ts.tv_usec)
     {
       
       struct sockaddr_ll destAddr;
       memcpy(buf,&snode->pkt,snode->pkt_len);
       memcpy(&(destAddr.sll_addr),&buf,MAC_ADDR_LEN);
       destAddr.sll_family=PF_PACKET;
       destAddr.sll_protocol=htons(ETH_P_ALL);
       destAddr.sll_ifindex=2;
       destAddr.sll_pkttype=PACKET_OTHERHOST;
       destAddr.sll_halen=ETH_ALEN;
       if(snode2->rFlag==0 && snode2->wFlag==1)
         {
           
           if((retVal=write(Fd,snode->pkt,snode->pkt_len))==-1)
         {
           printf("retVal is %d",retVal);
           printf("sendto() error \n");
         }
           printf("SENDER 1 --- packet number is %d OF length %d Sent \n",snode2->pkt_id,retVal);
           snode2->rFlag=1;
           snode2->wFlag=0;
         }
       
     }
  pthread_mutex_unlock( &mut );
       snode=snode->next;
  }while(snode->next != NULL);