Breaking out of select for no reason

67 Views Asked by At

I am doing something like this

val = select(max_fd+1,&readfd,0,0,0);
if(val >=1){
    printf("I have got some value");
}

My code breaks out of select for no reason. It receives no packet. On 10 runs , I get 1 run where it waits on select. Rest it just quits.

Socket has been set up to receive ICMP packets. On that 1 run, it works perfectly. Why is this crapping out 9 times?

2

There are 2 best solutions below

2
n0p On

My guess is that your file descriptor is closed during the process. In this case val will be -1 and errno wil be set to EBADF.

1
kliteyn On

select() returns -1 if there is some error. Please check return value of select(), and check errno if the return value is -1.