Embedded Linux poll() returns constantly -
i have particular problem. poll keeps returning when know there nothing read.
so setup follows, have 2 file descriptors form part of fd set poll watches. 1 pin high low change (gpio). other proxy input. problem occurs proxy input.
the order of processing is: start main functions; poll; write data proxy; poll break; accept data; send data on spi; receiving slave device, signals wants send ack, dropping gpio low; poll() senses drop , reacts; infinite pollins :(
if have no timeout on poll function, program works perfectly. moment include timeout on poll. poll returns continuously. not sure doing wrong here.
while(1) { memset((void*)fdset, 0, sizeof(fdset)); fdset[0].fd = gpio_fd; fdset[0].events = pollpri; // pollpri - there urgent data read fdset[1].fd = proxy_rx; fdset[1].events = pollin; // pollin - there data read rc = poll(fdset, nfds, 1000);//poll_timeout); if (rc < 0) // error { printf("\npoll() failed/interrupted!\n"); } else if (rc == 0) // timeout occurred { printf(" poll() timeout\n"); } else { if (fdset[1].revents & pollin) { printf("fdset[1].revents & pollin\n"); if( (resultr =read(fdset[1].fd,command_buf,10)<0) { printf("failed read data\n"); } if (fdset[0].revents & pollpri) //if( (gpio_fd != -1) && (fd_isset(gpio_fd, &err))) { lseek(fdset[0].fd, 0, seek_set); // read start of file len = read(fdset[0].fd, reader, 64); }
so gist of code, sorry untidiness, interface gets getting used to.
i have used gdb , while debugging, found gpio descriptor set revents = 0x10 means , error occured , polpri occured.
poll(2) doesn't empty event queue in above link similar addressed. read time when ever pollin. bit amazing, problem occurs when include timeout, if replace poll timeout -1, works perfectly.
help please.
when poll
fails (returning -1) should errno
, perhaps thru perror
; , nfds
(the second argument poll
) not set, should constant 2.
probably gcc compiler have given warning, @ least warnings enabled (-wall
), nfds
not being set.
(i'm guessing nfds
being uninitialized might "random" large value.... kernel might polling other "random" file descriptors, in fdset
after index 2...)
btw, strace
program. , using fdset
name bit confusing (it refer select(2)
).
Comments
Post a Comment