]> jspc29.x-matter.uni-frankfurt.de Git - trbnettools.git/commitdiff
tcp server bug fixed, close(myFd) added
authorhadaq <hadaq>
Fri, 9 Jul 2010 16:48:08 +0000 (16:48 +0000)
committerhadaq <hadaq>
Fri, 9 Jul 2010 16:48:08 +0000 (16:48 +0000)
libtrbnet/trbcmd.c

index c973a353236c796a60b686a7b6766d3a914c17db..7fcdb60738bd93d7474933be70b5ba96ca780f02 100644 (file)
@@ -34,7 +34,7 @@
 
 static int hexMode = HEXMODE;
 
-static const char trbcmd_version[] = "$Revision: 2.53 $";
+static const char trbcmd_version[] = "$Revision: 2.54 $";
 
 #define BACKLOG 10
 static uint16_t tcp_port = 55555;
@@ -1241,11 +1241,8 @@ static int myFd = -1;
 
 static void atexit0(void)
 {
-  if (tcp_debug == 1) {
-    fprintf(stderr, "%d: exit called\n", myPid);
-  }
   shutdown(myFd, SHUT_RDWR);
-  if (close(myFd) == -1) perror("close");
+  if (close(myFd) == -1) perror("atexit0 close");
 }
 
 static void sigHandler(int sig)
@@ -1378,7 +1375,9 @@ int main(int argc, char **argv)
               " to port %d   [OK]\n\n",
               tcp_port);
     }
-
+    
+    if (init_ports() == -1) exit(EXIT_FAILURE);
+    
     /* Enter an infinite loop to accept clients */
     while (1) {
       socklen_t sin_size = sizeof(struct sockaddr_in);
@@ -1395,11 +1394,15 @@ int main(int argc, char **argv)
         fprintf(stderr, "accept()     OK...\n");
       }
       if ((myPid = fork()) == -1) { /* Error fork, Mother exit, no child */
-        perror(argv[0]);
+        perror("Error fork");
         exit(EXIT_FAILURE);
       }
       if (myPid > 0) {
-        /* Mother process: continue accepting connections */
+        /* Mother process: close myFd and continue accepting connections */
+        if (close(myFd) == -1) {
+          perror("Error close fd");
+          exit(EXIT_FAILURE);
+        }
         continue;
       } else {
         /* Child process */
@@ -1416,8 +1419,6 @@ int main(int argc, char **argv)
         stdout = clientout;
         stderr = clientout;
         
-        if (init_ports() == -1) exit(EXIT_FAILURE);
-        
         while (1) {
           msgLen = recv(myFd, (void *)command, 256, 0);
           if (msgLen == -1) {