From 8306c58c22cce2581a121af9ee0969210ff7acc1 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Fri, 28 Mar 2025 12:27:10 -0400 Subject: [PATCH] TCP link using feeder.c seems to be working fine --- Makefile | 2 +- app/feeder.c | 10 +++++----- lib/devsoc.c | 17 ++++++++++++----- lib/devsoc.h | 2 +- lib/gestcp.c | 20 ++++++++++++-------- lib/gestcp.h | 2 +- lib/lvleml.c | 10 +++++----- lib/subrou.c | 2 +- 8 files changed, 38 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index ccbadb2..4539da9 100644 --- a/Makefile +++ b/Makefile @@ -40,7 +40,7 @@ FEEDPAR = \ $(TESTPORT) \ $(TESTDIR)/$(DATATST)/feed*.tst \ -onefeed : debug +onefeed : @ bin/feeder \ -d3 \ $(TESTIP) \ diff --git a/app/feeder.c b/app/feeder.c index 7272735..0cf3277 100644 --- a/app/feeder.c +++ b/app/feeder.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #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); diff --git a/lib/devsoc.c b/lib/devsoc.c index e32244f..b59da54 100644 --- a/lib/devsoc.c +++ b/lib/devsoc.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -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; diff --git a/lib/devsoc.h b/lib/devsoc.h index ad60966..a33cbcc 100644 --- a/lib/devsoc.h +++ b/lib/devsoc.h @@ -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); diff --git a/lib/gestcp.c b/lib/gestcp.c index 9652a93..d8081fe 100644 --- a/lib/gestcp.c +++ b/lib/gestcp.c @@ -29,16 +29,18 @@ /* 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 diff --git a/lib/gestcp.h b/lib/gestcp.h index 7096e2b..b0df057 100644 --- a/lib/gestcp.h +++ b/lib/gestcp.h @@ -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); diff --git a/lib/lvleml.c b/lib/lvleml.c index f5c506a..471c6e1 100644 --- a/lib/lvleml.c +++ b/lib/lvleml.c @@ -9,6 +9,7 @@ #include #include #include +#include #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 diff --git a/lib/subrou.c b/lib/subrou.c index e25be33..52ec5d1 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -21,7 +21,7 @@ //version definition #define VERSION "0.6" -#define RELEASE "22" +#define RELEASE "23" //Public variables PUBLIC int debug=0; //debug level -- 2.47.3