From: Andre Noll <maan@congo.fml.local>
Date: Sun, 8 Oct 2006 21:31:05 +0000 (+0200)
Subject: fix two bugs concerning blocking fds
X-Git-Tag: v0.2.14~2^2~6
X-Git-Url: https://git.tuebingen.mpg.de/?a=commitdiff_plain;h=c4012aab461993e6c8a9930d27d924a8462a9775;p=paraslash.git

fix two bugs concerning blocking fds

para_server's command socked and the socket of the http_sender
were blocking file descriptors. So make them non-blocking.
---

diff --git a/http_send.c b/http_send.c
index 111c49ba..1d970a5d 100644
--- a/http_send.c
+++ b/http_send.c
@@ -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;
diff --git a/server.c b/server.c
index c7e68126..9688c6cc 100644
--- 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)