Re: timeout problem while using poll()
- From: scott@xxxxxxxxxxxxx (Scott Lurndal)
- Date: Sat, 08 Nov 2008 03:15:44 GMT
Rick Jones <rick.jones2@xxxxxx> writes:
Sinan <sardok@xxxxxxxxx> wrote:
i'm using poll() system call on 1 udp socket for both reading and
writing, i'm setting timeout value but poll() never returns 0 which
i need. instead of returnin 0, it returns 1 continuously and ready
for writing (POLLOUT flag is enabled) , so i'm guessing, since it is
never got block, timeout value resets all the time. what should i
do?
this is how i used in code,
int timeout = 2000;
while(1) {
if ( (pret = poll(&pfd, 1, timeout)) < 0) {
err_sys(1, "main()->poll");
}
if(!pret) {
printf("timeout happens sometimes\n");
break;
}
if(pfd.revents & POLLIN) {
nread = udm_socket_read(buff);
UCP_reply_handler(buff, nread,
&first_ubi_dev);
}
if(pfd.revents & POLLOUT) {
if(sendcmd) {
if(sendcmd()) {
sendcmd = NULL;
}
Um, why the two "sendcmd()" calls there?
There isn't. He's using a stupid C trick of treating a function pointer as
a boolean.
It more correctly should be
if (sendcmd != NULL) {
if (sendcmd() != 0) {
sendcmd = NULL;
}
}
Assuming sendcmd is a pointer to a function returning int.
scott
.
- Follow-Ups:
- Re: timeout problem while using poll()
- From: vippstar
- Re: timeout problem while using poll()
- References:
- timeout problem while using poll()
- From: Sinan
- Re: timeout problem while using poll()
- From: Rick Jones
- timeout problem while using poll()
- Prev by Date: Re: timeout problem while using poll()
- Next by Date: Re: timeout problem while using poll()
- Previous by thread: Re: timeout problem while using poll()
- Next by thread: Re: timeout problem while using poll()
- Index(es):