From: Jean-Marc Pigeon (Delson) Date: Mon, 31 Mar 2025 19:42:56 +0000 (-0400) Subject: Disconnect properly reported X-Git-Tag: tag-0.7~39 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=1f9f8fd23484c1aff7d126fe069d2191de233c50;p=jmp%2Fmailleur Disconnect properly reported --- diff --git a/lib/devsoc.c b/lib/devsoc.c index 035ad6f..812eb1a 100644 --- a/lib/devsoc.c +++ b/lib/devsoc.c @@ -203,6 +203,27 @@ return newhandle; */ /********************************************************/ /* */ +/* Procedure to check if a socket is connected */ +/* This procedure is called when pool exit with */ +/* en event. */ +/* */ +/********************************************************/ +static _Bool isconnected(SOCTYP *soc) + +{ +_Bool connected; +char buffer[10]; + +connected=true; +if (recv(soc->handle,buffer,sizeof(buffer),MSG_PEEK|MSG_DONTWAIT)==0) + connected=false; +return connected; +} +/* + +*/ +/********************************************************/ +/* */ /* Procedure to open plain incoming channel */ /* */ /********************************************************/ @@ -580,6 +601,7 @@ ai=(struct addrinfo *)0; phase=0; proceed=true; while (proceed==true) { + (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); switch (phase) { case 0 : //Do we have parameters if ((ip==(const char *)0)||(port==(const char *)0)) { @@ -603,23 +625,7 @@ while (proceed==true) { phase=999; //no need to go further } break; - case 3 : //getting newhandle flag - if ((flags=fcntl(handle,F_GETFL,0))<0) { - (void) rou_core_dump("%s, Unable to get socket descripteur on " - "IP/PORT <%s/%s> (Bug? error=<%s>)", - OPEP,soc->ip,soc->port,strerror(errno)); - phase=999; //never reached - } - break; - case 4 : //setting newhandle working mode - if ((flags=fcntl(handle,F_SETFL,flags|O_NONBLOCK|O_ASYNC))<0) { - (void) rou_core_dump("%s, Unable to set socket descripteur on " - "IP/PORT <%s/%s> (Bug? error=<%s>)", - OPEP,soc->ip,soc->port,strerror(errno)); - phase=999; //never reached - } - break; - case 5 : //connecting to remote + case 3 : //connecting to remote if (connect(handle,ai->ai_addr,ai->ai_addrlen)<0) { switch (errno) { case EINPROGRESS : //its acceptable @@ -633,6 +639,22 @@ while (proceed==true) { } } break; + case 4 : //getting newhandle flag + if ((flags=fcntl(handle,F_GETFL,0))<0) { + (void) rou_core_dump("%s, Unable to get socket descripteur on " + "IP/PORT <%s/%s> (Bug? error=<%s>)", + OPEP,soc->ip,soc->port,strerror(errno)); + phase=999; //never reached + } + break; + case 5 : //setting newhandle working mode + if ((flags=fcntl(handle,F_SETFL,flags|O_NONBLOCK))<0) { + (void) rou_core_dump("%s, Unable to set socket descripteur on " + "IP/PORT <%s/%s> (Bug? error=<%s>)", + OPEP,soc->ip,soc->port,strerror(errno)); + phase=999; //never reached + } + break; case 6 : //socket is now ready soc=newsocket(); soc->proto=proto; @@ -910,20 +932,11 @@ if (soc!=(SOCTYP *)0) { case 1 : (void) rou_alert(0,"%s Polling return millisec='%d' revent='%08x", OPEP,millisec,polling[0].revents); - //(void) usleep(500000); - status=soc_receive(socptr); - (void) rou_alert(0,"%s JMPDBG recv status='%d'",OPEP, - recv(soc->handle,(char *)0,0,MSG_DONTWAIT|MSG_PEEK)); - (void) rou_alert(0,"%s JMPDBG soc_recieve status='%d'",OPEP,status); - -/* - if ((polling[0].revents&POLLERR)==POLLERR) { - (void) rou_alert(0,"%s Polling POLLERR",OPEP); - soc->handle=-1; - soc->connected=false; - status=0; + status=-2; //wlets say it is disconnected + if (isconnected(soc)==true) { + status=soc_receive(socptr); + (void) rou_alert(0,"%s JMPDBG soc_recieve status='%d'",OPEP,status); } -*/ break; default : break; diff --git a/lib/gestcp.c b/lib/gestcp.c index 8145152..5531085 100644 --- a/lib/gestcp.c +++ b/lib/gestcp.c @@ -62,6 +62,8 @@ while (proceed==true) { case 2 : //lets wait secwait*1000 millisec for input got=soc_waitforchar(socptr,secwait*1000); switch (got) { + case -2 : //remote is disconnectd + break; case -1 : //trouble? signal? if ((hangup==true)||(reload==true)) phase=999; //we got a real signal diff --git a/lib/subrou.c b/lib/subrou.c index 48e0f6f..4f57ae9 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -21,7 +21,7 @@ //version definition #define VERSION "0.6" -#define RELEASE "35" +#define RELEASE "36" #define BRANCH "dvl" //Public variables