From b7b749b47edcd97e303637f43c1646261ed8cf49 Mon Sep 17 00:00:00 2001 From: "Jean-Marc Pigeon (Delson)" Date: Thu, 27 Mar 2025 20:20:54 -0400 Subject: [PATCH] Neww to check pool verssus ppoll and waitchar --- Makefile | 19 ++++--- app/feeder.c | 124 ++++++++++++++++++++++++++++++++++++++++---- data-tst/feed00.tst | 10 ++++ lib/devsoc.c | 5 +- lib/modrec.c | 3 +- lib/subrou.c | 2 +- 6 files changed, 144 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 786724c..f11c195 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,7 @@ LOCKDIR = $(TESTDIR)/var/run/$(APPNAME) TESTDIR = $(CURDIR)/test_area TESTIP = 127.127.10.25 TESTPORT= 1025 +TESTITER= 3 #-------------------------------------------------------------------- #testing feed FEEDPAR = \ @@ -41,10 +42,10 @@ FEEDPAR = \ onefeed : debug @ bin/feeder \ - -d 3 \ + -d3 \ $(TESTIP) \ $(TESTPORT) \ - $(TESTDIR)/$(DATATST)/feed00.tst + $(DATATST)/feed00.tst #direct test tstfeed : debug @@ -61,14 +62,20 @@ dbgfeed : debug EMLPAR = \ -r $(TESTDIR) \ -d 3 \ - :$(TESTIP):$(TESTPORT) \ + :$(TESTIP):$(TESTPORT): + +onercvr : debug + @ echo "starting $@" + @ bin/emlrcvr \ + -f \ + $(EMLPAR) emlrcvr : clean debug newtest #starting email receiver @ echo @ echo "--------------" @ echo "starting $@" @ $(TESTDIR)/$(SBINDIR)/$@ \ - $(EMLPAR) + $(EMLPAR)$(TESTITER) @ echo "--------------" valrcvr : clean debug newtest #valgring of emlrcvr @@ -84,9 +91,9 @@ valrcvr : clean debug newtest #valgring of emlrcvr # --track-origins=yes \ # --trace-children=no \ -dbgrcvr : clean debug newtest #debugging emlrcvr +dbgrcvr : debug #debugging emlrcvr @ gdb --args \ - $(TESTDIR)/$(SBINDIR)/emlrcvr \ + bin/emlrcvr \ -f \ $(EMLPAR) diff --git a/app/feeder.c b/app/feeder.c index 06287c2..bdd8a5f 100644 --- a/app/feeder.c +++ b/app/feeder.c @@ -49,34 +49,131 @@ static void usage(const char *name) */ /********************************************************/ /* */ -/* Scanning one line from test file */ +/* Reporting a problem with parsing test */ +/* */ +/********************************************************/ +static void report(int numline,char *line,char *trouble) + + +{ +(void) fprintf(stdout,"line %d %s\n",numline,trouble); +(void) fprintf(stdout,"\t'%s'\n",line); +} +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to send a line to remote */ +/* */ +/********************************************************/ +static void dooutgoing(SOCPTR *socptr,char *line) + +{ +(void) soc_writebuffer(socptr,line,strlen(line)); +(void) soc_writebuffer(socptr,"\r\n",2); +(void) fprintf(stdout,"JMPDBG sending <%s>\n",line); +} +/* + +*/ +/********************************************************/ +/* */ +/* Procedure to compare incoming data with expected*/ /* */ /********************************************************/ -static _Bool scanline(SOCPTR *socptr,char *line) +static _Bool doincoming(SOCPTR *socptr,int numline,char *line) { +#define OPEP "tstfeed.c:doincoming" _Bool status; +char *received; +TIMESPEC attend; int phase; _Bool proceed; status=false; +received=(char *)0; +attend.tv_sec=2; +attend.tv_nsec=0; +phase=0; +proceed=true; +while (proceed==true) { + (void) fprintf(stdout,"JMPDBG %s, phase='%d'\n",OPEP,phase); + switch (phase) { + case 0 : //check for character + switch (soc_waitforchar(socptr,&attend)) { + case -1 : + (void) fprintf(stdout,"JMPDBG wait =-1\n"); + phase=999; + break; + case 0 : + (void) fprintf(stdout,"JMPDBG wait =0\n"); + phase=999; + break; + default : + break; + } + break; + case 1 : //get available character + break; + case 2 : //get avail character + if (soc_getnextline(socptr,&received)>0) { + (void) fprintf(stdout,"Remote say <%s>\n",received); + received=rou_freestr(received); + status=true; + } + break; + default : //SAFE Guard + proceed=false; + break; + } + phase++; + } +return status; +} +/* + +*/ +/********************************************************/ +/* */ +/* Scanning one line from test file */ +/* */ +/********************************************************/ +static _Bool scanline(SOCPTR *socptr,int numline,char *line) + +{ +_Bool status; +int phase; +_Bool proceed; + +status=true; phase=0; proceed=true; +//(void) fprintf(stdout,"JMPDBG phase='%d' line=<%s>\n",phase,line); while (proceed==true) { - //(void) fprintf(stdout,"JMPDBG scanline phase='%d'\n",phase); switch (phase) { case 0 : //removing first space while ((line[0]==' ')||(line[0]=='\t')) (void) memmove(line,line+1,(strlen(line+1)+1)); break; case 1 : //discarding comment - if (line[0]=='#') { - status=true; - phase=999; //line is a comment no need to go further + switch (line[0]) { + case '#' : //line is comment + break; + case '<' : //incoming expected + status=doincoming(socptr,numline,line); + break; + case '>' : //incoming expected + (void) dooutgoing(socptr,line+1); + break; + default : //Unexpected + line[1]='\000'; + (void) report(numline,line,"unexpected directive"); + status=false; + break; } break; - case 2 : //checking line - break; default : //SAFE Guard proceed=false; break; @@ -98,12 +195,15 @@ static _Bool scanonefile(SOCPTR *socptr,const char *filename) { _Bool status; FILE *fichier; +int numline; char line[200]; int phase; _Bool proceed; status=false; fichier=(FILE *)0; +numline=0; +(void) strcpy(line,""); phase=0; proceed=true; while (proceed==true) { @@ -119,7 +219,12 @@ while (proceed==true) { break; case 1 : //reading line; while (fgets(line,sizeof(line),fichier)!=(char *)0) { - if (scanline(socptr,line)==false) { + char *ptr; + + numline++; + while ((ptr=strrchr(line,'\n'))!=(char *)0) + *ptr='\000'; + if (scanline(socptr,numline,line)==false) { phase=999; //Trouble trouble exiting break; } @@ -204,6 +309,7 @@ _Bool proceed; status=0; params=(ARGTYP *)0; +foreground=true; numfile=0; phase=0; proceed=true; diff --git a/data-tst/feed00.tst b/data-tst/feed00.tst index f425c26..cbf95ed 100644 --- a/data-tst/feed00.tst +++ b/data-tst/feed00.tst @@ -1 +1,11 @@ #basic test to feed SMTP server +#Please update /etc/hosts with +#127.127.10.25 emlrcvr +##to have proper reverss-address within test +# # comment +# < incoming data +# > outgoing data +> +quit +handle=-1; //handle within sock not open if (openplain(newsoc)==false) //received a termination signal phase=999; //return a null socket @@ -816,6 +815,7 @@ soc=(SOCTYP *)socptr; phase=0; proceed=true; while (proceed==true) { + //(void) rou_alert(0,"JMPDBG %s phase='%d'",OPEP,phase); switch (phase) { case 0 : //sanity check if (soc==(SOCTYP *)0) { @@ -864,7 +864,7 @@ soc=(SOCTYP *)socptr; if (soc!=(SOCTYP *)0) { struct pollfd polling[1]; - polling[0].events=POLLIN|POLLPRI|POLLERR|POLLHUP; + polling[0].events=POLLIN|POLLPRI|POLLHUP; polling[0].revents=(short)0; switch (soc->modtls) { case true : @@ -934,6 +934,7 @@ while (proceed==true) { phase=999; //no need to go further } case 1 : //Do we have char available in carpile + (void) soc_receive(socptr); if (soc->carin==0) phase=999; //No char,no need to check for line break; diff --git a/lib/modrec.c b/lib/modrec.c index fe52337..ab63cc2 100644 --- a/lib/modrec.c +++ b/lib/modrec.c @@ -357,9 +357,10 @@ while (proceed==true) { } break; case 4 : //relax time - (void) sleep(2); if ((hangup==false)&&(reload==false)) phase=0; //Normal process, lets restart + else + (void) usleep(10000); break; case 5 : //we got a signal, kill all childs (void) prc_killchilds(childs,nbrbind,10); diff --git a/lib/subrou.c b/lib/subrou.c index 1ccf2eb..1a34411 100644 --- a/lib/subrou.c +++ b/lib/subrou.c @@ -21,7 +21,7 @@ //version definition #define VERSION "0.6" -#define RELEASE "20" +#define RELEASE "21" //Public variables PUBLIC int debug=0; //debug level -- 2.47.3