From: Jean-Marc Pigeon (Delson) Date: Wed, 31 Jul 2024 14:22:48 +0000 (-0400) Subject: TIME_wait problem fixed (at last) X-Git-Tag: tag-0.4~37 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=ec04fd45611573b2da3595fb5d0d8f1b14b5a861;p=jmp%2Fmailleur TIME_wait problem fixed (at last) --- diff --git a/lib/modrec.c b/lib/modrec.c index a482f58..bf8fb6c 100644 --- a/lib/modrec.c +++ b/lib/modrec.c @@ -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",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 diff --git a/lib/unisoc.c b/lib/unisoc.c index 1260fc6..f4825f1 100644 --- a/lib/unisoc.c +++ b/lib/unisoc.c @@ -5,6 +5,7 @@ /* to handle TCP socket. */ /* */ /********************************************************/ +#include #include #include #include @@ -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>)",