LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Select() did not select my socket (http://www.linuxquestions.org/questions/programming-9/select-did-not-select-my-socket-321193/)

thvo 05-08-2005 12:56 AM

Select() did not select my socket
 
I use Fedora Core 1, kernel 2.4.22-1.2199.nptl. My program uses select() to poll five sockets, one is for accept() and others for read data. I set TCP_NO_DELAY by setsockopt and FIONBIO by ioctl. My program has 2 threads but it should not relate to my problem. The problem is my program sometimes block at select() but netstat shows that there are 29 bytes of data remaining in Recv-Q.

grupoapunte 05-08-2005 01:20 AM

I had a similar problem before, make sure that you are refreshing your fd_set (second param in select()) for example

main() {
int maxfd;
fd_set readfds, masterfds;
......
for(;;) {
readfds = masterfds;
select(maxfd+1, readfds, NULL, NULL, NULL);
.............
}

the comflicting line is "readfds = masterfds" you must put that before select if u want it to work, I mean you need a fd_set for reading, and another for refreshing the first one, this way if you make a FD_SET() you use the masterfds end then you copy it to the one you use for reading. This was my problem, maybe yours is diferent you should post a part of your code to let us see the problem.

I hope I helped you, good luck, Dam.


All times are GMT -5. The time now is 12:16 AM.