I am new to this thread.
I am using select() in my code.
my code snippet:
---------------------
twait.tv_sec = 0;
twait.tv_usec = THIRTY_MILLISECONDS;
pollfds2_count = select (0, readfds, writefds,exceptfds, &twait);
From one of the support forums i came to know that select() will return immediately even timeval parameter set to "non zero" or non NULL values. Am i correct? (They mentioned a possible bug in windows).
For our application to work correctly select should wait for THIRTY_MILLISECONDS.
How can i ensure that?
How sleep will help?
Please help me.
Regards,
Naga
Comments
The timeout specifies the [b]maximum[/b] time for the status to change.
A sample usage of select is to check if there is data to be read from socket to ensure that read does not block:
[code]
twait.tv_sec = 0;
twait.tv_usec = THIRTY_MILLISECONDS
count = select (0, readfds, NULL,NULL, &twait);
if( count == 0 ) {
// select failed after waiting for THIRTY_MILLLISECONDS
} else {
// We have data ready to be read
}
[/code]
If you want to wait for THIRTY_MILLLISECONDS for whatever reason, use
Sleep(THIRTY_MILLLISECONDS)
Regards
The timeout specifies the [b]maximum[/b] time for the status to change.
A sample usage of select is to check if there is data to be read from socket to ensure that read does not block:
[code]
twait.tv_sec = 0;
twait.tv_usec = THIRTY_MILLISECONDS
count = select (0, readfds, NULL,NULL, &twait);
if( count == 0 ) {
// select failed after waiting for THIRTY_MILLLISECONDS
} else {
// We have data ready to be read
}
[/code]
If you want to wait for THIRTY_MILLLISECONDS for whatever reason, use
Sleep(THIRTY_MILLLISECONDS)
Regards
[code]
sockfd = socket(PF_INET, SOCK_STREAM, 0);
fcntl(sockfd, F_SETFL, O_NONBLOCK);
[/code]
If you want a GREAT guide on programming sockets (TCP and UDP), check out the link below.
http://beej.us/guide/bgnet/output/html/multipage/index.html
-[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]