Here is my example code:
#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <errno.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
int main()
{
int fd = socket(AF_INET, SOCK_STREAM, 0);
printf("--> fd is %d, FD_SETSIZE is %d\n", fd, FD_SETSIZE);
fd_set set;
FD_ZERO(&set);
FD_SET(fd, &set);
int retval = select(fd + 1, &set, NULL, NULL, NULL);
if(-1 == retval)
{
perror("select");
}
printf("retval is %d\n", retval);
}
Why does select not fail or block/timeout? (retval
is 1, and fd
is set in set) But on an an openend socket, there is no data availible. Is there anything in the documentation i missed?