- int fd = accept(sock, NULL, 0);
- if (fd < 0) {
- if (errno != EINTR && errno != EAGAIN)
- UNIXERR("accept");
- continue;
+ fd_set rfd;
+ struct timeval tv = { 1, 0 };
+ int res;
+
+ FD_SET(sock, &rfd);
+ res = select(sock + 1, &rfd, NULL, NULL, &tv);
+
+ if (res < 0) {
+ if (errno != EINTR && errno != EAGAIN) {
+ UNIXERR("select");
+ return EXIT_FAILURE;
+ }
+ }
+ if (res > 0) {
+ int fd = accept(sock, NULL, 0);
+ if (fd < 0) {
+ if (errno != EINTR && errno != EAGAIN) {
+ UNIXERR("accept");
+ return EXIT_FAILURE;
+ }
+ continue;
+ }
+ thread_launch(policy_run, fd, NULL);