What happens when you run it?
Or build, if it doesn't get as far as creating an executable.
|
Mentor
|
![]() |
| 31Jul2009,12:37 | #11 |
|
Go4Expert Member
|
|
| 31Jul2009,20:28 | #12 |
|
Problem seems to be in synchronization of the threads. Can you please answer my other thread in this forum "synchronizing two threads".
In this post I would like you to help me where I am taking out the smallest packet from the list. I need not to wait using sleep() or usleep() for the system clock time to reach the packet time stamp. Can you please tell me how is it possible that I'll read the smallest packet and send it only when the system clock time is reached. If I Search in the list with the smallest packet and in match case if I use the system clock time to check with the packet time stamp. How this can be good enough to do the task? Here is the code. Thanks for your replies. Code:
while(scurr->next!=NULL) // checking for the entire list
{
// this if is finding the packet with smallest time stamp
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);
// this if is checking the smallest packet with the system clock time
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)
{
// here I am writing the data on the wire
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;
}
}
snode=snode->next;
}while(snode->next != NULL);
|
|
Go4Expert Member
|
|
| 31Jul2009,20:36 | #13 |
|
Quote:
Originally Posted by kami1219 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);
|
|
Mentor
|
![]() |
| 31Jul2009,20:38 | #14 |
|
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.
|
|
Go4Expert Member
|
|
| 31Jul2009,20:58 | #15 |
|
Quote:
Originally Posted by xpi0t0s 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);
|


