From: Jean-Marc Pigeon (Delson) Date: Mon, 31 Mar 2025 17:28:13 +0000 (-0400) Subject: Better disconnect|timeout detection X-Git-Tag: tag-0.7~41 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=598ac87ec2855fce9aa86bccdb478d440d93ff73;p=jmp%2Fmailleur Better disconnect|timeout detection --- diff --git a/app/feeder.c b/app/feeder.c index 416c8cb..9c9ac7e 100644 --- a/app/feeder.c +++ b/app/feeder.c @@ -90,12 +90,14 @@ static _Bool doincoming(SOCPTR *socptr,int numline,char *line) #define STRETC "..." _Bool status; +int got; char *received; int tocheck; int phase; _Bool proceed; status=false; +got=0; received=(char *)0; tocheck=strlen(line); phase=0; @@ -115,9 +117,23 @@ while (proceed==true) { } break; case 1 : //waiting for a line with CRLF - if (tcp_getline(socptr,WAITLINE,&received)<=0) { - (void) fprintf(stdout,"Unable to receive line in due time\n"); - phase=999; //No need to go further + received=(char *)0; + got=tcp_getline(socptr,WAITLINE,&received); + (void) rou_alert(0,"%s, JMPDNG got='%d'",OPEP,got); + switch (got) { + case 0 : //Reading timeout + (void) rou_alert(0,"Unable to receive line in due time"); + phase=999; //No need to go further + break; + case -1 : //signal received + (void) rou_alert(0,"A Signal was received"); + break; + case -2 : //remot disconnected + received=rou_freestr(received); + received=strdup("Disconnected"); + break; + default : //got a good line + break; } break; case 2 : //get available character diff --git a/lib/devsoc.c b/lib/devsoc.c index 950fbcf..9d6d963 100644 --- a/lib/devsoc.c +++ b/lib/devsoc.c @@ -891,8 +891,10 @@ if (soc!=(SOCTYP *)0) { break; case 1 : (void) rou_alert(0,"%s Polling return millisec='%d'",OPEP,millisec); - (void) usleep(500000); + //(void) usleep(500000); status=soc_receive(socptr); + (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); @@ -1026,8 +1028,10 @@ return sent; */ /********************************************************/ /* */ -/* Procedure to read incoming character from the */ +/* Procedure to read incoming character from the */ /* socket. */ +/* Return -1 if trouble. */ +/* the number of char read otherwise */ /* */ /********************************************************/ PUBLIC int soc_receive(SOCPTR *socptr) @@ -1049,7 +1053,7 @@ buffer=(char *)0; phase=0; proceed=true; while (proceed==true) { - //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); + (void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); switch (phase) { case 0 : //is socket available if (soc==(SOCTYP *)0) { diff --git a/lib/gestcp.c b/lib/gestcp.c index e77b881..8145152 100644 --- a/lib/gestcp.c +++ b/lib/gestcp.c @@ -67,8 +67,7 @@ while (proceed==true) { phase=999; //we got a real signal break; case 0 : //normal time out - if (soc_receive(socptr)<0) - got=-2; //remote disconnected + got=soc_receive(socptr); phase=999; break; default : //char available diff --git a/lib/lvleml.c b/lib/lvleml.c index d17b6ef..3293893 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -312,26 +312,28 @@ PUBLIC int eml_docontact(CONTYP *contact) { #define OPEP "lvleml.c:eml_docontact" int status; +int got; int delay; _Bool proceed; status=1; +got=0; delay=300; //5 minutes standard delay if (debug>1) - delay/=5; //one minute in debug mode + delay/=30; //10 sec in debug mode proceed=true; (void) signon(contact); while (proceed==true) { char *line; line=(char *)0; - status=tcp_getline(contact->socptr,delay,&line); - if (status<=0) { //timeout or trouble? + got=tcp_getline(contact->socptr,delay,&line); + if (got<=0) { //timeout or trouble? char str[100]; - switch (status) { + switch (got) { case 0 : //timeout - (void) snprintf(str,sizeof(str),"Remote not responding with %d sec",delay); + (void) snprintf(str,sizeof(str),"No data from remote within %d sec",delay); break; case -1 : //signal received (void) snprintf(str,sizeof(str),"Signal Received"); @@ -344,7 +346,8 @@ while (proceed==true) { status=-3; break; } - (void) log_fprintlog(contact->logptr,"Exiting contact condition=<%s>",str); + (void) log_fprintlog(contact->logptr,false,"Contact terminated; " + "condition=<%s>",str); //(void) rou_alert(0,"%s exit status='%d'",OPEP,status); break; //no need to go further } diff --git a/lib/modrec.c b/lib/modrec.c index 9105610..0c9933c 100644 --- a/lib/modrec.c +++ b/lib/modrec.c @@ -140,16 +140,16 @@ while (proceed==true) { case 1 : //quit done break; case 0 : //exit under timeout - (void) rou_alert(0,"Lost contact with peer <%s>",contact->peerip); + (void) rou_alert(0,"Contact timeout with peer <%s>",contact->peerip); break; case -1 : //Signal received (void) rou_alert(0,"Signal received within contact"); break; case -2 : //Signal received - (void) rou_alert(0,"Signal received within contact"); + (void) rou_alert(0,"Remote disconnected"); break; default : //trouble trouble - (void) rou_alert(0,"%s Unepected status='%d' (BUG?!)",OPEP,intstat); + (void) rou_alert(0,"%s Unexpected status='%d' (BUG?!)",OPEP,intstat); break; } break; diff --git a/lib/subrou.c b/lib/subrou.c index ba2a8ec..bf4a41b 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -21,7 +21,7 @@ //version definition #define VERSION "0.6" -#define RELEASE "33" +#define RELEASE "34" #define BRANCH "dvl" //Public variables