]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Better disconnect|timeout detection
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 31 Mar 2025 17:28:13 +0000 (13:28 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Mon, 31 Mar 2025 17:28:13 +0000 (13:28 -0400)
app/feeder.c
lib/devsoc.c
lib/gestcp.c
lib/lvleml.c
lib/modrec.c
lib/subrou.c

index 416c8cbdc4613ac56b9a36a2ba73c484b6d1401a..9c9ac7eb2d23b18393ffb234f63807bacf012903 100644 (file)
@@ -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
index 950fbcf67e77571b45d49988b347516750262488..9d6d963bbe93d52a6f8f1c1c02380987599368d8 100644 (file)
@@ -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) {
index e77b881bd4f18db2a54e19d85144ff6c8e1e4217..814515284be55f95ed0ed981d59d623c9ce28ef9 100644 (file)
@@ -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
index d17b6ef6ca53216c672f6d6a0992387077e271ea..329389322b56d407dffebe547fdd0622a5700c63 100644 (file)
@@ -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
     }
index 9105610691fa830e1b71167e13fe3d849e7b1da3..0c9933cb91b2623a97265958eaabc2d3e5822cef 100644 (file)
@@ -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;
index ba2a8ec741dc9eafc7ce116a5c8a506d0f70a82c..bf4a41b5e1003890ab5ded3dda7af6219475d8a6 100644 (file)
@@ -21,7 +21,7 @@
 
 //version definition 
 #define VERSION "0.6"
-#define RELEASE "33"
+#define RELEASE "34"
 #define BRANCH "dvl"
 
 //Public variables