#include #include #include #include #include #include #include #include int main(int ac, char **av) { struct sockaddr_in sin; int fl; int fd; struct timeval tv; struct fd_set set; fd = socket(PF_INET, SOCK_STREAM, 0); fl = fcntl(fd, F_GETFD, 0); fcntl(fd, F_SETFD, fl | FD_CLOEXEC); fl = fcntl(fd, F_GETFL, 0); fcntl(fd, F_SETFL, fl | O_NONBLOCK); bzero(&sin, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_len = sizeof(sin); inet_aton("8.8.178.110", &sin.sin_addr); sin.sin_port = htons(80); connect(fd, (struct sockaddr *)&sin, sizeof(sin)); tv.tv_sec = 3; tv.tv_usec = 0; FD_ZERO(&set); FD_SET(fd, &set); fl = select(fd + 1, NULL, &set, NULL, &tv); printf("select -> %d\n", fl); }