]> SAFE projects GIT repository - jmp/mailleur/commitdiff
TIME_wait problem fixed (at last)
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 31 Jul 2024 14:22:48 +0000 (10:22 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Wed, 31 Jul 2024 14:22:48 +0000 (10:22 -0400)
lib/modrec.c
lib/unisoc.c

index a482f5802232e7aab3aa91a9e4a60716c4ef651c..bf8fb6c7683af4d17f1a0ef34f96e04fd9153727 100644 (file)
@@ -35,6 +35,7 @@ void docontact(SOCTYP *binding)
 #define TESTL   4
 
 CONTYP *contact;
+int client_fd;
 pid_t child;
 int phase;
 _Bool proceed;
@@ -48,15 +49,12 @@ while (proceed==true) {
       (void) prc_settitle("Waiting contact on %s:%s",binding->ip,binding->port);
       break;
     case 1      :       //do we have a contact
-      if ((contact=tcp_getcontact(binding))==(CONTYP *)0) {
-        phase=999;      //no going further
-        }
+      client_fd=accept(binding->handle,NULL,NULL);
+      printf("New client connected: %d\n",client_fd);
       break;
     case 2      :       //forking process
       if ((child=fork())!=(pid_t)0) {
-        (void) close(contact->channel);
-        (void) free(contact);
-        (void) sleep(8);
+        (void) close(client_fd);
         (void) fprintf(stdout,"JMPDBG retart\n");
         phase=0;
         }
@@ -64,24 +62,17 @@ while (proceed==true) {
     case 3      :       //do contact
       (void) close(binding->handle);
       for (int i=0;i<TESTL;i++) {
-        int sent;
-        char tmpbuf[100];
-
-        if ((reload==true)||(hangup==true))
-          break;
-        if (prc_checkprocess(getppid())==false)
-          break;
-        sent=tcp_fprintf(contact,"Remote pid=%d iter=%d/%d\n",getpid(),i,TESTL);
-        if (sent<0) {
-          (void) rou_alert(0,"JMPDBG tcp_fprintf error <%s>",strerror(errno));
-          break;
-          }
-        (void) read(contact->channel,tmpbuf,sizeof(tmpbuf));
+        (void) dprintf(client_fd,"Remote pid=%d iter=%d/%d\n",getpid(),i,TESTL);
         (void) sleep(1);
         }
       break;
     case 4      :       //close contact
-      contact=tcp_dropcontact(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);
       break;
     default     :       //SAFE guard
index 1260fc6e461e2c8c3cf10bac031dae4f0d1d9392..f4825f1e9c464b0da108072b614c5c79cddc9296 100644 (file)
@@ -5,6 +5,7 @@
 /*     to handle TCP socket.                           */
 /*                                                     */
 /********************************************************/
+#include        <arpa/inet.h>
 #include        <sys/types.h>
 #include        <errno.h>
 #include        <fcntl.h>
@@ -66,6 +67,7 @@ static int bindhandle(struct addrinfo *ai,SOCTYP *binding)
 
 int handle;
 struct linger slg;
+struct sockaddr_in server_addr;
 int reuse;
 int phase;
 _Bool proceed;
@@ -79,7 +81,8 @@ proceed=true;
 while (proceed==true) {
   switch (phase) {
     case 0     :       //lets get a socket
-      if ((handle=socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol))<0) {
+      if ((handle=socket(AF_INET, SOCK_STREAM,0))<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
@@ -110,7 +113,11 @@ while (proceed==true) {
        }
       break;
     case 4     :       //getting socket option
-      if (bind(handle,ai->ai_addr,ai->ai_addrlen)<0) {
+      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) {
        (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
@@ -335,6 +342,7 @@ while (proceed==true) {
         }
       break;
     case 1      :       //
+      break;
       if ((setegid(getgid())<0)||(seteuid(getuid())<0)) {
         (void) rou_core_dump("%s, Unable to get root privilege! "
                              "(program config? error=<%s>)",