]> SAFE projects GIT repository - jmp/mailleur/commitdiff
TCP link using feeder.c seems to be working fine
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 28 Mar 2025 16:27:10 +0000 (12:27 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Fri, 28 Mar 2025 16:27:10 +0000 (12:27 -0400)
Makefile
app/feeder.c
lib/devsoc.c
lib/devsoc.h
lib/gestcp.c
lib/gestcp.h
lib/lvleml.c
lib/subrou.c

index ccbadb2aa0c869f7147d661d92bc88bbd2a15472..4539da9cb39643df0b5ab19ad4effdd137c57d09 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -40,7 +40,7 @@ FEEDPAR       =                                               \
                $(TESTPORT)                             \
                $(TESTDIR)/$(DATATST)/feed*.tst         \
 
-onefeed        :       debug
+onefeed        :       
                @ bin/feeder                            \
                        -d3                             \
                        $(TESTIP)                       \
index 7272735352b8da0aa69c8a43ddda1a70939ded53..0cf3277a1d49aa91533a06fc73d228fb7699cfaf 100644 (file)
@@ -13,6 +13,7 @@
 #include       <stdlib.h>
 #include       <stdio.h>
 #include       <string.h>
+#include       <syslog.h>
 #include       <unistd.h>
 
 #include       "subrou.h"
@@ -90,21 +91,18 @@ static _Bool doincoming(SOCPTR *socptr,int numline,char *line)
 
 _Bool status;
 char *received;
-TIMESPEC attend;
 int phase;
 _Bool proceed;
 
 status=false;
 received=(char *)0;
-attend.tv_sec=WAITLINE;
-attend.tv_nsec=0;
 phase=0;
 proceed=true;
 while (proceed==true) {
-  (void) fprintf(stdout,"JMPDBG %s, phase='%d'\n",OPEP,phase);
+  //(void) fprintf(stdout,"JMPDBG %s, phase='%d'\n",OPEP,phase);
   switch (phase) {
     case 0      :       //waiting for a line with CRLF
-      if (tcp_getline(socptr,&attend,&received)==0) {
+      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
         }
@@ -319,10 +317,12 @@ while (proceed==true) {
         }
       break;
     case 2      :       //opening remote channel
+      (void) openlog("feeder",LOG_NDELAY|LOG_PID,LOG_DAEMON);
       numfile=scanallfiles(params->argc,params->argv);
       if (numfile==(params->argc-2))
         (void) fprintf(stdout,"%d file successfully transmitted to <%s.%s>\n",
                                numfile,params->argv[0],params->argv[1]);
+      (void) closelog();
       break;
     default     :       //end of task
       params=par_freeparams(params);
index e32244f22153ecb05c0be580492929b68cc82ab8..b59da541f928a7f4f9a11c3e6d81c95c753f61d0 100644 (file)
@@ -13,6 +13,7 @@
 #include        <poll.h>
 #include        <stdio.h>
 #include        <stdlib.h>
+#include        <signal.h>
 #include        <string.h>
 #include        <unistd.h>
 
@@ -398,7 +399,7 @@ _Bool proceed;
 
 handle=-1;
 slg.l_onoff=true;
-slg.l_linger=0; /*0 sec timeout on close*/
+slg.l_linger=2; /*0 sec timeout on close*/
 reuse=1;
 phase=0;
 proceed=true;
@@ -855,14 +856,17 @@ while (proceed==true) {
 /*      socket, waiting up to attend second.            */
 /*                                                     */
 /********************************************************/
-PUBLIC int soc_waitforchar(SOCPTR *socptr,TIMESPEC *attend)
+PUBLIC int soc_waitforchar(SOCPTR *socptr,u_long microsec)
 
 {
 #define OPEP    "devsoc.c:soc_waitforchar"
 register int status;
+int timeout;
+sigset_t origmask;
 SOCTYP *soc;
 
 status=-1;
+timeout=microsec/1000;  //From microsec to millisec 
 soc=(SOCTYP *)socptr;
 if (soc!=(SOCTYP *)0) {      
   struct pollfd polling[1];
@@ -877,14 +881,15 @@ if (soc!=(SOCTYP *)0) {
       polling[0].fd=soc->handle;
       break;
     }
-
-  status=ppoll(polling,1,attend,(sigset_t *)0);
+  (void) sigprocmask(SIG_SETMASK,(sigset_t *)0,&origmask);
+  status=poll(polling,1,timeout);
+  (void) sigprocmask(SIG_SETMASK,&origmask,(sigset_t *)0);
   switch (status) {
     case -1     :
       (void) rou_alert(0,"%s Polling error (error=<%s>)",OPEP,strerror(errno));
       break;
     case  0     :
-      (void) rou_alert(0,"%s Polling timeout",OPEP);
+      //(void) rou_alert(0,"%s Polling timeout",OPEP);
       break;
     case 1      :
       if ((polling[0].revents&POLLHUP)==POLLHUP) {
@@ -1065,8 +1070,10 @@ if (soc!=(SOCTYP *)0) {
               (void) rou_alert(0,"%s JMPDBG connection reset by peer",OPEP);
               break;
             default         :
+              foreground=false; //JMPDBG?
               (void) rou_alert(0,"%s Unexpected error=%d <%s> (Bug)",
                                   OPEP,errno,strerror(errno));
+              (void) exit(1);   //JMPDBG!
               break;
             }
           break;
index ad609666c31f4c95beeb349a2403c50efd76722f..a33cbccef2f2ad51a58dd8ab2f9ac1e582b64a88 100644 (file)
@@ -55,7 +55,7 @@ extern _Bool soc_openbinding(SOCPTR *socptr);
 extern void soc_closebinding(SOCPTR *socptr);
 
 //procedure to wait for character from contact
-extern int soc_waitforchar(SOCPTR *socptr,TIMESPEC *attend);
+extern int soc_waitforchar(SOCPTR *socptr,u_long microsec);
 
 //procedure to return a char array with the available line
 extern int soc_getnextline(SOCPTR *socptr,char **lineptr);
index 9652a93639b60fa1e3763fead25155183ef08e04..d8081fe1ebe0b272bbb0f51d34b910d291d156cf 100644 (file)
 /*      for a CRLF AS EOL.                              */
 /*                                                      */
 /********************************************************/
-PUBLIC int tcp_getline(SOCPTR *socptr,TIMESPEC *attend,char **lineptr)
+PUBLIC int tcp_getline(SOCPTR *socptr,u_int secwait,char **lineptr)
 
 {
 #define OPEP    "gestcp.c:tcp_getline"
 
 int got;
+u_long milliwait;
 int phase;
 _Bool proceed;
 
 got=0;
+milliwait=secwait*100;          //10 msec increment
 phase=0;
 proceed=true;
 while (proceed==true) {
@@ -54,19 +56,21 @@ while (proceed==true) {
       if ((got=soc_getnextline(socptr,lineptr))>0)
         phase=999;      //we got a line.
       break;
-    case 2      :       //waiting for new character presence
-      got=soc_waitforchar(socptr,attend);
+    case 2      :       //still need to wait
+      //(void) rou_alert(0,"%s JMPDBG milliwait='%d'",OPEP,milliwait);
+      if (milliwait==0) //waiting time expired?
+        phase=999;
+      milliwait--;
+      break;
+    case 3      :       //lets wait 10 ms for input 
+      got=soc_waitforchar(socptr,10000);
       switch (got) {
         case -1         :       //trouble? signal?
           if ((hangup==true)||(reload==true))
             phase=999;          //we got a real signal
           break;                //no need to read line
         case  0         :       //normal time out
-          phase=999;            //no need to go further, no need to read line
-          (void) rou_alert(0,"%s JMPDBG no char? sec='%d', nsec='%d'",
-                               OPEP,attend->tv_sec,attend->tv_nsec);
-          if ((attend->tv_sec>0)||(attend->tv_nsec>0))
-            phase=0;            //waiting for a full line
+           phase=0;             //still waiting for a full line
           break;                
         default         :       //char available
           phase=0;              //check for new line
index 7096e2b94c59f6846915e20418cd2eed189ccfaa..b0df0572d4154f7e53ec05cef477b44e2126d1ab 100644 (file)
@@ -16,7 +16,7 @@
 #define         WAITLINE        10      //full line waiting time
 
 //read a line from contact up to CRLF
-extern int tcp_getline(SOCPTR *socptr,TIMESPEC *attend,char **lineptr);
+extern int tcp_getline(SOCPTR *socptr,u_int secwait,char **lineptr);
 
 //Transmit formated data to the contact channel
 extern int tcp_write(SOCPTR *socptr,char *buffer,int tosend);
index f5c506ad984d20322485b3164022e7f0aefe58d4..471c6e1da9db61690e026da9bfcf1f01c5fbf45f 100644 (file)
@@ -9,6 +9,7 @@
 #include        <stdlib.h>
 #include        <stdio.h>
 #include        <string.h>
+#include        <unistd.h>
 
 #include       "subrou.h"
 #include       "unieml.h"
@@ -317,11 +318,8 @@ proceed=true;
 (void) signon(contact);
 while (proceed==true) {
   char *line;
-  TIMESPEC attend;
 
-  attend.tv_sec=delay;
-  attend.tv_nsec=0;
-  status=tcp_getline(contact->socptr,&attend,&line);
+  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");
@@ -336,8 +334,10 @@ while (proceed==true) {
       proceed=doehlo(contact,line);
       break;
     case c_quit         :       //QUIT SMTP protocol
-      (void) transmit(contact,"%d 2.0.0 Bye, closing connection %s",
+      //(void) rou_alert(0,"%s JMPDBG sleep started",OPEP);
+      (void) transmit(contact,"%d 2.0.0 Bye, closing connection %s",    
                               QUITOK,contact->mainsesid);
+      //(void) rou_alert(0,"%s JMPDBG Bye transmitted",OPEP);
       proceed=false;
       break;
     case c_mail         :       //MAIL FROM: checking originator
index e25be3388e3b35d3463f3b9dc451115d133909e2..52ec5d10642e43c3e8ec1fe5fdc338428de1ae0c 100644 (file)
@@ -21,7 +21,7 @@
 
 //version definition 
 #define VERSION "0.6"
-#define RELEASE "22"
+#define RELEASE "23"
 
 //Public variables
 PUBLIC  int debug=0;            //debug level