I am having trouble understanding the use of select system call. As per select documentation , select will return after timeout or socket is ready for I/O operation. What does it mean by socket is ready for I/O operation
?
received_len = 0
do {
/* There is only one fd in readfds */
rv = select(fd+1, &readfds, NULL, NULL, timeout)
if (rv < 0){
/*socket select failed.*/
break
}else if (rv == 0){
/*socket timeout.*/
break
}else
/* Go for reading */
readbytes = read(fd, (buf + received_len), (expected_len - received_len))
if (readbytes < 0)
{
/*read fail*/
break
}
received_len += readbytes;
}while(received_len < expected_len)
I though select will timed out when peer socket connection closes. but after closing peer connection select returns 1 and read happens on socket. Then read call returns 0 (Which basically means peer terminated). I thought select will be timed out since the socket is not still ready for read operation but that is not happenning.