From e4d59e16cb19d90f0bf1f0e9182760900ea0b57b Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Mon, 31 Mar 2025 10:44:17 -0400 Subject: [PATCH] remote disconnect seem detected properly --- data-tst/feed00.tst | 1 + lib/devsoc.c | 19 ++++--------------- lib/gestcp.c | 31 ++++++++++++++----------------- lib/lvleml.c | 36 +++++++++++++++++++++++++++++------- lib/modrec.c | 19 +++++++++++++------ lib/subrou.c | 4 ++-- 6 files changed, 63 insertions(+), 47 deletions(-) diff --git a/data-tst/feed00.tst b/data-tst/feed00.tst index c852fd9..6f31b40 100644 --- a/data-tst/feed00.tst +++ b/data-tst/feed00.tst @@ -9,6 +9,7 @@ R:220 emlrcvr ESMTP emlrcvr... S:EHLO example.com R:250-emlrcvr ready, your IP/FQDN=[127.0.0.1/localhost.localdomain] R:250-SIZE 52428800 +R:250-ORGN R:250-STARTTLS R:250-8BITMIME R:250-ENHANCEDSTATUSCODES diff --git a/lib/devsoc.c b/lib/devsoc.c index caa23ff..950fbcf 100644 --- a/lib/devsoc.c +++ b/lib/devsoc.c @@ -892,13 +892,7 @@ if (soc!=(SOCTYP *)0) { case 1 : (void) rou_alert(0,"%s Polling return millisec='%d'",OPEP,millisec); (void) usleep(500000); - (void) soc_receive(socptr); - if ((polling[0].revents&POLLHUP)==POLLHUP) { - (void) close(soc->handle); - soc->handle=-1; - soc->connected=false; - status=0; - } + status=soc_receive(socptr); /* if ((polling[0].revents&POLLERR)==POLLERR) { (void) rou_alert(0,"%s Polling POLLERR",OPEP); @@ -1091,6 +1085,7 @@ while (proceed==true) { errno=EAGAIN; switch (errno) { case EAGAIN : //no char available yet + got=0; //lets report "no char" break; case ECONNRESET : //Connection reset by peer (void) rou_alert(0,"%s connection reset by peer",OPEP); @@ -1102,15 +1097,9 @@ while (proceed==true) { } break; case 0 : //No char available? - (void) rou_alert(0,"%s, detected EOF error=<%s:%d>", - OPEP,strerror(errno),errno); - if (close(soc->handle)<0) - (void) rou_alert(0,"%s, after close error=<%s:%d>", - OPEP,strerror(errno),errno); - soc->handle=-1; //Socket is now disconnected - soc->connected=false; + //wait for timeout detection break; - default : //we got some char from remote + default : //we got some char from remote for (int i=0;i0) phase=999; //we got a line. break; - case 2 : //still need to wait - break; - case 3 : //lets wait secwait*1000 millisec for input + case 2 : //lets wait secwait*1000 millisec for input got=soc_waitforchar(socptr,secwait*1000); switch (got) { case -1 : //trouble? signal? if ((hangup==true)||(reload==true)) phase=999; //we got a real signal - break; //no need to read line + break; case 0 : //normal time out - phase=0; //still waiting for a full line + if (soc_receive(socptr)<0) + got=-2; //remote disconnected + phase=999; break; default : //char available - phase=0; //check for new line - if (soc_receive(socptr)<0) { - got=-1; - phase=999; //remote disconnected? - } + phase=0; //is new line ready? break; } break; diff --git a/lib/lvleml.c b/lib/lvleml.c index bbb8067..d17b6ef 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -299,10 +299,12 @@ return true; /********************************************************/ /* */ /* Procedure to proceed with peer exchange */ -/* 3 return values: */ -/* -1 exit with trouble. */ -/* 0 normal exit. */ -/* 1 continue to proceed. */ +/* 5 return values: */ +/* 1 exiting via "quit" */ +/* 0 contact timeout */ +/* -1 signal received */ +/* -2 remote disconnected */ +/* -3 BUG! */ /* */ /********************************************************/ PUBLIC int eml_docontact(CONTYP *contact) @@ -322,10 +324,28 @@ proceed=true; while (proceed==true) { char *line; + line=(char *)0; status=tcp_getline(contact->socptr,delay,&line); - //(void) rou_alert(0,"%s, JMPDBG tcp_getline status='%d'",OPEP,status); if (status<=0) { //timeout or trouble? - (void) log_fprintlog(contact->logptr,false,"%s","Lost contact with remote"); + char str[100]; + + switch (status) { + case 0 : //timeout + (void) snprintf(str,sizeof(str),"Remote not responding with %d sec",delay); + break; + case -1 : //signal received + (void) snprintf(str,sizeof(str),"Signal Received"); + break; + case -2 : //contact lost + (void) snprintf(str,sizeof(str),"Lost link with remote"); + break; + default : + (void) snprintf(str,sizeof(str),"Unexpected status='%d' (Bug?)",status); + status=-3; + break; + } + (void) log_fprintlog(contact->logptr,"Exiting contact condition=<%s>",str); + //(void) rou_alert(0,"%s exit status='%d'",OPEP,status); break; //no need to go further } (void) log_fprintlog(contact->logptr,false,"%s",line); @@ -341,6 +361,7 @@ while (proceed==true) { (void) transmit(contact,"%d 2.0.0 Bye, closing connection %s", QUITOK,contact->mainsesid); //(void) rou_alert(0,"%s JMPDBG Bye transmitted",OPEP); + status=1; //every thing fine proceed=false; break; case c_mail : //MAIL FROM: checking originator @@ -371,7 +392,8 @@ while (proceed==true) { break; default : (void) rou_alert(0,"Unable to find keyword for <%s> (Bug?)",OPEP,line); - status=-1; + status=-3; + proceed=false; break; } line=rou_freestr(line); diff --git a/lib/modrec.c b/lib/modrec.c index 1f07abe..9105610 100644 --- a/lib/modrec.c +++ b/lib/modrec.c @@ -114,11 +114,12 @@ static void docontact(SOCPTR *socptr,int pos) #define TESTL 8 CONTYP *contact; - +int intstat; int phase; _Bool proceed; contact=(CONTYP *)0; +intstat=0; phase=0; proceed=true; while (proceed==true) { @@ -134,15 +135,21 @@ while (proceed==true) { (void) rou_checkleak(true); break; case 2 : //do contact - switch (eml_docontact(contact)) { - case -1 : //Signal received - (void) rou_alert(0,"Signal received within contact"); + intstat=eml_docontact(contact); + switch (intstat) { + case 1 : //quit done break; case 0 : //exit under timeout (void) rou_alert(0,"Lost contact with peer <%s>",contact->peerip); break; - default : //exit under quit - (void) rou_alert(0,"Contact terminated by 'quit'"); + 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"); + break; + default : //trouble trouble + (void) rou_alert(0,"%s Unepected status='%d' (BUG?!)",OPEP,intstat); break; } break; diff --git a/lib/subrou.c b/lib/subrou.c index a00472c..ba2a8ec 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -21,8 +21,8 @@ //version definition #define VERSION "0.6" -#define RELEASE "32" -#define BRANCH "dvl;" +#define RELEASE "33" +#define BRANCH "dvl" //Public variables PUBLIC int debug=0; //debug level -- 2.47.3