mark all fds used for select() as non-blocking
authorAndre <maan@p133.(none)>
Tue, 13 Jun 2006 09:41:28 +0000 (11:41 +0200)
committerAndre <maan@p133.(none)>
Tue, 13 Jun 2006 09:41:28 +0000 (11:41 +0200)
This shouldn't matter much, but there _are_ (rare) situations where
an fd is marked ready for reading, but a subsequent read will block
nevertheless. It's never wrong to use non-blocking fds, so just do it.

This patch also includes a check in para_fd_set() which spots blocking
fds as they are added to the fd sets. This check is commented out
for performance reasons but can easily be activated.

audiod.c
dccp.c
dccp_recv.c
fd.c
http_recv.c
stdin.c
stdout.c

index 52f4ff4cb18919bea60e4106e350fa2d13de6874..90290639d853ce3fb7fd7572b8e136669b66642a 100644 (file)
--- a/audiod.c
+++ b/audiod.c
@@ -882,6 +882,7 @@ static int audiod_get_socket(void)
                exit(EXIT_FAILURE); /* do not unlink socket */
        }
        add_close_on_fork_list(fd);
+       mark_fd_nonblock(fd);
        return fd;
 }
 
@@ -894,6 +895,7 @@ static int open_stat_pipe(void)
                ret = fd[1];
                PARA_NOTICE_LOG("stat pipe opened, fd %d\n", ret);
                add_close_on_fork_list(ret);
+               mark_fd_nonblock(ret);
        } else
                clean_exit(EXIT_FAILURE, "failed to open status pipe");
        return ret;
diff --git a/dccp.c b/dccp.c
index 147e46307676b60025561e4f81167a3a72b22b90..fa48976e72f44f0cc8b0bdac7d93bcf6368075ec 100644 (file)
--- a/dccp.c
+++ b/dccp.c
@@ -26,6 +26,7 @@
 #include "para.h"
 #include "error.h"
 #include "dccp.h"
+#include "fd.h"
 
 /** \cond some magic dccp constants */
 #define SOL_DCCP 269
index 335ad2e630598de4d98cafbb2257e5e07be144af..943b8283e6a0f135c3b0edbc3cd5de44e250cedb 100644 (file)
@@ -98,6 +98,7 @@ static int dccp_recv_open(struct receiver_node *rn)
        ret = -E_DCCP_CONNECT;
        if (connect(pdd->fd, ai->ai_addr, ai->ai_addrlen) < 0)
                goto err_out;
+       mark_fd_nonblock(pdd->fd);
        return 1;
 err_out:
        dccp_recv_close(rn);
diff --git a/fd.c b/fd.c
index d1e0412d3f3f22174229eab26582b9a688707e85..b913009369ba6029fcdf4fa8378c9d926e30dd10 100644 (file)
--- a/fd.c
+++ b/fd.c
@@ -100,10 +100,20 @@ int mark_fd_nonblock(int fd)
 */
 void para_fd_set(int fd, fd_set *fds, int *max_fileno)
 {
+
        if (fd < 0 || fd >= FD_SETSIZE) {
                PARA_EMERG_LOG("fatal: tried to add invalid fd %d\n", fd);
                exit(EXIT_FAILURE);
        }
+#if 0
+       {
+               int flags = fcntl(fd, F_GETFL);
+               if (!(flags & O_NONBLOCK)) {
+                       PARA_EMERG_LOG("fd %d is a blocking file descriptor\n", fd);
+                       exit(EXIT_FAILURE);
+               }
+       }
+#endif
        FD_SET(fd, fds);
        *max_fileno = PARA_MAX(*max_fileno, fd);
 }
index 3d72c7c7396ca3b8f96f63653aec9c021cb90846..096541679ea5ae30116f478436c2303c1aabf567 100644 (file)
@@ -189,9 +189,10 @@ static int http_recv_open(struct receiver_node *rn)
        if (!ret < 0)
                goto err_out;
        /* get new socket */
-       ret = -E_SOCKET;
-       if ((phd->fd = get_socket()) < 0)
+       ret = get_socket();
+       if (ret < 0)
                goto err_out;
+       phd->fd = ret;
        /* init their_addr */
        init_sockaddr(&their_addr, conf->port_arg, he);
        /* connect */
@@ -200,6 +201,7 @@ static int http_recv_open(struct receiver_node *rn)
        ret = para_connect(phd->fd, &their_addr);
        if (ret < 0)
                goto err_out;
+       mark_fd_nonblock(phd->fd);
        phd->status = HTTP_CONNECTED;
        return 1;
 err_out:
diff --git a/stdin.c b/stdin.c
index cb13250e269874399eb6892eac73242d80adc0ac..8b18c2e2cef6c54975cde07285fd68207334d63b 100644 (file)
--- a/stdin.c
+++ b/stdin.c
@@ -105,5 +105,6 @@ void stdin_set_defaults(struct stdin_task *sit)
        sit->task.post_select = stdin_post_select;
        sit->task.event_handler = stdin_default_event_handler;
        sit->task.private_data = sit;
+       mark_fd_nonblock(STDIN_FILENO);
        sprintf(sit->task.status, "stdin reader");
 }
index 1c1435a321dedaf445b39a0a1ad8791d024d636d..2e86fe965a022ac099c6c2effe5f582d10611c5a 100644 (file)
--- a/stdout.c
+++ b/stdout.c
@@ -107,5 +107,6 @@ void stdout_set_defaults(struct stdout_task *sot)
        sot->task.post_select = stdout_post_select;
        sot->task.event_handler = stdout_default_event_handler;
        sot->eof = 0;
+       mark_fd_nonblock(STDOUT_FILENO);
        sprintf(sot->task.status, "stdout writer");
 }