fix two bugs concerning blocking fds
authorAndre Noll <maan@congo.fml.local>
Sun, 8 Oct 2006 21:31:05 +0000 (23:31 +0200)
committerAndre Noll <maan@congo.fml.local>
Sun, 8 Oct 2006 21:31:05 +0000 (23:31 +0200)
para_server's command socked and the socket of the http_sender
were blocking file descriptors. So make them non-blocking.

http_send.c
server.c

index 111c49b..1d970a5 100644 (file)
@@ -371,12 +371,19 @@ static void http_pre_select(int *max_fileno, fd_set *rfds, fd_set *wfds)
 
 static int open_tcp_port(int port)
 {
+       int ret;
+
        server_fd = init_tcp_socket(port);
        if (server_fd < 0) {
                http_shutdown_clients();
                self->status = SENDER_OFF;
                return server_fd;
        }
+       ret = mark_fd_nonblock(server_fd);
+       if (ret < 0) {
+               PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret));
+               exit(EXIT_FAILURE);
+       }
        self->status = SENDER_ON;
        add_close_on_fork_list(server_fd);
        return 1;
index c7e6812..9688c6c 100644 (file)
--- a/server.c
+++ b/server.c
@@ -302,11 +302,18 @@ random:
 
 static unsigned init_network(void)
 {
-       int sockfd = init_tcp_socket(conf.port_arg);
+       int fd, ret = init_tcp_socket(conf.port_arg);
 
-       if (sockfd < 0)
-               exit(EXIT_FAILURE);
-       return sockfd;
+       if (ret < 0)
+               goto err;
+       fd = ret;
+       ret = mark_fd_nonblock(fd);
+       if (ret < 0)
+               goto err;
+       return fd;
+err:
+       PARA_EMERG_LOG("%s\n", PARA_STRERROR(-ret));
+       exit(EXIT_FAILURE);
 }
 
 static void init_random_seed(void)