On one thread I just have select(NULL,NULL,NULL,NULL, time); to make
it sleep for "time" amount of time.
In the second thread 'm receiving that on socket but before that I
have select(sockfd+1, &fds, NULL,NULL, time);
now this gives me an error "select: Invalid Argument"
my code is
if(select(sock+1, &fds, NULL, NULL, &tv) == -1)
{
perror("select");
exit(0);
}
if (FD_ISSET(sock, &fds)){
printf("YES...");
}
In nutshell:
Thread 1:
while(1){
sleep for some time
create Thread and make it execute function THREAD-2
}
Thread 2:
while(1){
select on socket for some time
check if data received
yes? take action
no? continue
}
When I was not checking the return value of select on socket, my
thread was running infinitely give NO CHANCE to other parent thread to
execute. I dont understand what's wrong with this code.
Can anyone pls help me with this?
Thanks in advance
<snip>
> In nutshell:
> Thread 1:
> while(1){
> sleep for some time
>
> create Thread and make it execute function THREAD-2
> }
>
> Thread 2:
> while(1){
> select on socket for some time
>
> check if data received
>
> yes? take action
>
> no? continue
>
> }
>
Don't use select for your sleep, use nanosleep.
Use non-blocking mode for the data socket with select, or blocking mode
without select.
--
Ian Collins
> Can anyone pls help me with this?
Odds are there is a bug in code you haven't posted.
DS