]> SAFE projects GIT repository - jmp/mailleur/commitdiff
AT last the TIME_WAIT condition is fixed
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 31 Jul 2024 15:19:27 +0000 (11:19 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 31 Jul 2024 15:19:27 +0000 (11:19 -0400)
kleenex/Makefile
kleenex/server.c
lib/gestcp.c
lib/modrec.c
lib/unisoc.c

index af5fa2f2f3a282cd45075887568f7026a5e2dc63..45682856145b54a414e26dc6d44d955bc430f63b 100644 (file)
@@ -1,3 +1,4 @@
+debug  : server
 
 server :  server.c
 
index 5acd99225c32ad2cc49f4437d38b27a793be01d4..b94e3592e755c001247aa4a3baacc1ff2a2ff166 100644 (file)
@@ -91,7 +91,7 @@ int main(int argc, char *argv[]) {
 
         if (pid == 0) {
            // Child process handles client
-           //close(server_fd);  
+           close(server_fd);  
 
            // Receive data then send response
            receiveAndRespond(client_fd);
index f1d9b04cda7b0ccec31af3938b975a110e373ad3..a4a3db64fb92de67ffbc79d83b33cefdb5c52ae9 100644 (file)
@@ -120,7 +120,7 @@ while (proceed==true) {
         phase=999;      //not going further
         }
       break;
-    case 1      :       //waiting from contact
+    case 1      :       //properly closing remote contact
       if (shutdown(contact->channel,SHUT_RDWR)<0) {
         switch (errno) {
           case ENOTCONN :       //already disconnect by other side!
@@ -133,8 +133,10 @@ while (proceed==true) {
             break;
           }
         }
-      (void) usleep(10000);
-      (void) close(contact->channel);
+      if (close(contact->channel)<0) {
+        (void) rou_alert(0,"%s unable to close channel properly (errno=<%s>)",
+                            OPEP,strerror(errno));
+        }
       break;
     case 2      :       //freeing contact memory
       (void) free(contact);              
index bf8fb6c7683af4d17f1a0ef34f96e04fd9153727..4851da517633ef90e31d217418511d7fb66cf551 100644 (file)
@@ -35,7 +35,6 @@ void docontact(SOCTYP *binding)
 #define TESTL   4
 
 CONTYP *contact;
-int client_fd;
 pid_t child;
 int phase;
 _Bool proceed;
@@ -49,31 +48,33 @@ while (proceed==true) {
       (void) prc_settitle("Waiting contact on %s:%s",binding->ip,binding->port);
       break;
     case 1      :       //do we have a contact
-      client_fd=accept(binding->handle,NULL,NULL);
-      printf("New client connected: %d\n",client_fd);
+      if ((contact=tcp_getcontact(binding))==(CONTYP *)0) {
+        phase=999;      //No contact!
+        }
       break;
     case 2      :       //forking process
+      printf("New client connected: %d\n",contact->channel);
       if ((child=fork())!=(pid_t)0) {
-        (void) close(client_fd);
-        (void) fprintf(stdout,"JMPDBG retart\n");
-        phase=0;
+        (void) close(contact->channel);
+        (void) free(contact);
+        contact=(CONTYP *)0;
+        phase=999;      //no need to go further
         }
       break;
     case 3      :       //do contact
       (void) close(binding->handle);
+      printf("Client channel=%d (pid=%d)\n",contact->channel,getpid());
       for (int i=0;i<TESTL;i++) {
-        (void) dprintf(client_fd,"Remote pid=%d iter=%d/%d\n",getpid(),i,TESTL);
+        (void) dprintf(contact->channel,"Remote pid=%d iter=%d/%d\n",
+                        getpid(),i,TESTL);
         (void) sleep(1);
         }
       break;
-    case 4      :       //close contact
-      if (shutdown(client_fd,SHUT_RDWR)<0) {
-        (void) printf("Unable to shutdown properly (error=<%s>)\n",strerror(errno));
-        }
-      if (close(client_fd)<0) {
-        (void) printf("Unable to close properly (error=<%s>(\n",strerror(errno));
-        }
-      (void) exit(0);
+    case 4      :       //connection terminated
+      (void) rou_alert(0,"Contact IP/PORT=<%s/%s> Exiting",
+                          binding->ip,binding->port);
+      contact=tcp_dropcontact(contact);
+      (void) exit(0);   //exiting sub process
       break;
     default     :       //SAFE guard
       proceed=false;
@@ -108,7 +109,6 @@ while (proceed==true) {
       break;
     case 1      :               //dispating need process
       (void) docontact(binding);  //waiting, handling remote contact
-      (void) rou_alert(0,"Contact Exiting: %s-%s",appname,rou_getversion());
       break;
     default     :       //SAFE Guard
       proceed=false;
index f4825f1e9c464b0da108072b614c5c79cddc9296..71624c1b226eac88e2ac45be97bfb182b1c78495 100644 (file)
@@ -81,8 +81,7 @@ proceed=true;
 while (proceed==true) {
   switch (phase) {
     case 0     :       //lets get a socket
-      if ((handle=socket(AF_INET, SOCK_STREAM,0))<0) {
-      //if ((handle=socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol))<0) {
+      if ((handle=socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol))<0) {
         (void) rou_alert(0,"%s Unable to open socket for <%s> (error='%s')",
                           OPEP,ai->ai_canonname,strerror(errno));
        phase=999;      //trouble trouble
@@ -116,8 +115,7 @@ while (proceed==true) {
       server_addr.sin_family = AF_INET;
       inet_pton(AF_INET,"127.0.0.1", &(server_addr.sin_addr));
       server_addr.sin_port = htons(2525);
-      if (bind(handle,(struct sockaddr*) &server_addr, sizeof(server_addr))<0) {
-      //if (bind(handle,ai->ai_addr,ai->ai_addrlen)<0) {
+      if (bind(handle,ai->ai_addr,ai->ai_addrlen)<0) {
        (void) rou_alert(0,"%s Unable to bind on IP/port <%s/%s> (error='%s')",
                           OPEP,ai->ai_canonname,binding->port,strerror(errno));
         phase=999;     //trouble cleanup phase