Removed the signal handler for the TCP server.
authorviric@llimona
Tue, 30 May 2006 00:57:22 +0200
changeset 52 3af277b9f73b
parent 51 a01abd65856a
child 53 667cd5966695
Removed the signal handler for the TCP server. Added a bit of tcp-server's childs code.
tcp_server.c
--- a/tcp_server.c	Tue May 30 00:32:32 2006 +0200
+++ b/tcp_server.c	Tue May 30 00:57:22 2006 +0200
@@ -7,6 +7,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <stdbool.h>
+#include <signal.h>
 #include <assert.h> // Per assert()
 #include <sys/select.h> // Pel select()
 
@@ -46,6 +47,7 @@
 
 	if (pid == 0)
 	{
+		program_child_handler(SIG_DFL);
 		/* Child */
 		close(0);
 		close(1);
@@ -238,9 +240,30 @@
 
 static int accept_connection(int socket)
 {
-	int res;
+	int newsock, pid;
+
+	newsock = accept(socket, NULL, NULL);
+	if (newsock == -1)
+		return 0;
+
+	/* We don't use child_fork(), as it's only for the _main parent_ */
+	pid = fork();
 
-	res = accept(socket, NULL, NULL);
-	close(res);
-	return res;
+	if (pid == 0)
+	{
+		/* Child */
+		close(socket);
+		send(newsock, "hola\n", 5, 0);
+		close(newsock);
+		exit(0);
+		/* Unreachable */
+	} else if (pid > 0)
+	{
+		/* Parent */
+		close(newsock);
+	}
+	else
+		return -1;
+
+	return 0;
 }