]> SAFE projects GIT repository - jmp/mailleur/commitdiff
remote disconnect seem detected properly
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 31 Mar 2025 14:44:17 +0000 (10:44 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 31 Mar 2025 14:44:17 +0000 (10:44 -0400)
data-tst/feed00.tst
lib/devsoc.c
lib/gestcp.c
lib/lvleml.c
lib/modrec.c
lib/subrou.c

index c852fd91a037b04d6785887c98ba2ea6ea79c1db..6f31b40d9975c66634c053ba644411a60f3cfb1f 100644 (file)
@@ -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
index caa23ffb8039a900b6feb911c0f5054258328992..950fbcf67e77571b45d49988b347516750262488 100644 (file)
@@ -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;i<got;i++,buffer++) {
             if (*buffer=='\000')
               *buffer='?';
index 5acfdcd5ced65a9d939f20c9f91ced3ba8eed37c..e77b881bd4f18db2a54e19d85144ff6c8e1e4217 100644 (file)
@@ -29,8 +29,9 @@
 /*      for a CRLF AS EOL.                              */
 /*      - Return "got", which could be:                 */
 /*      - a positive number of character read.          */
-/*      -  0, then reading reach time out               */
-/*      - -1, the link is disconnected (by remote)      */
+/*      -  0, reading reach time out                    */
+/*      - -1, signal received                           */
+/*      - -2, remote disconnect                         */
 /*                                                      */
 /********************************************************/
 PUBLIC int tcp_getline(SOCPTR *socptr,u_int secwait,char **lineptr)
@@ -48,34 +49,30 @@ proceed=true;
 while (proceed==true) {
   //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase);
   switch (phase) {
-    case 0      :
-      if (socptr==(SOCPTR *)0) {
-        (void) rou_alert(0,"%s socket pointer is NULL (Bug!?)",OPEP);
-        phase=999;      //trouble trouble
+    case 0      :       //link still open?
+      if (soc_receive(socptr)<0) {
+        got=-2;
+        phase=999;
         }
       break;
-    case 1      :       //get nextline
+    case 1      :       //get nextline if ready
       if ((got=soc_getnextline(socptr,lineptr))>0)
         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;
index bbb8067a29559ca774102dcf919ef3caa4f5f5e8..d17b6ef6ca53216c672f6d6a0992387077e271ea 100644 (file)
@@ -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);
index 1f07abefe274eb76bc4574cea6d47a1ab82af1bc..9105610691fa830e1b71167e13fe3d849e7b1da3 100644 (file)
@@ -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;
index a00472ca82e318ad8e1e0dc2f1dc765feb9d231e..ba2a8ec741dc9eafc7ce116a5c8a506d0f70a82c 100644 (file)
@@ -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