From: Jean-Marc Pigeon (Delson) Date: Wed, 31 Jul 2024 15:19:27 +0000 (-0400) Subject: AT last the TIME_WAIT condition is fixed X-Git-Tag: tag-0.4~36 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=c52d985d4bd19ca8ebb1ea87e5472cb38ae5778f;p=jmp%2Fmailleur AT last the TIME_WAIT condition is fixed --- diff --git a/kleenex/Makefile b/kleenex/Makefile index af5fa2f..4568285 100644 --- a/kleenex/Makefile +++ b/kleenex/Makefile @@ -1,3 +1,4 @@ +debug : server server : server.c diff --git a/kleenex/server.c b/kleenex/server.c index 5acd992..b94e359 100644 --- a/kleenex/server.c +++ b/kleenex/server.c @@ -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); diff --git a/lib/gestcp.c b/lib/gestcp.c index f1d9b04..a4a3db6 100644 --- a/lib/gestcp.c +++ b/lib/gestcp.c @@ -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); diff --git a/lib/modrec.c b/lib/modrec.c index bf8fb6c..4851da5 100644 --- a/lib/modrec.c +++ b/lib/modrec.c @@ -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;ichannel,"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; diff --git a/lib/unisoc.c b/lib/unisoc.c index f4825f1..71624c1 100644 --- a/lib/unisoc.c +++ b/lib/unisoc.c @@ -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