From: Jean-Marc Pigeon (Delson) Date: Sat, 13 Jul 2024 21:01:09 +0000 (-0400) Subject: Adding module gestcp X-Git-Tag: tag-0.3~7 X-Git-Url: https://jmp-git.ovh.safe.ca/?a=commitdiff_plain;h=589501935b73cab267e8694cfb911429a1f8d341;p=jmp%2Fmailleur Adding module gestcp --- diff --git a/lib/Makefile b/lib/Makefile index 21649ac..c1066dc 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -17,6 +17,7 @@ clean : #-------------------------------------------------------------------- OBJS= \ modrec.o \ + gestcp.o \ unipar.o uniprc.o unisig.o unisoc.o \ subrou.o @@ -30,8 +31,13 @@ modrec.o: \ uniprc.h \ unisig.h \ unisoc.h \ + gestcp.h \ modrec.h modrec.c +gestcp.o: \ + subrou.h \ + gestcp.h gestcp.c + unipar.o: \ subrou.h \ unipar.h unipar.c @@ -51,6 +57,12 @@ unisoc.o: \ subrou.o: \ subrou.h subrou.c +gestcp.h: \ + unisoc.h \ + +uniprc.h: \ + subrou.h \ + #-------------------------------------------------------------------- toremake: Makefile diff --git a/lib/gestcp.c b/lib/gestcp.c new file mode 100644 index 0000000..67db061 --- /dev/null +++ b/lib/gestcp.c @@ -0,0 +1,86 @@ +// vim: smarttab tabstop=8 shiftwidth=2 expandtab +/********************************************************/ +/* */ +/* Module for signal handling level */ +/* */ +/********************************************************/ +#include +#include +#include +#include + +#include "subrou.h" +#include "gestcp.h" + +static _Bool modopen; //boolean module open/close +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to wait for a remote client. */ +/* return all reference to the established contact.*/ +/* */ +/********************************************************/ +PUBLIC CONTYP *tcp_getcontact(SOCTYP *binding) + +{ +CONTYP *contact; + +contact=(CONTYP *)0; +return contact; +} +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to wait for a remote client. */ +/* return all reference to contact. */ +/* */ +/********************************************************/ +PUBLIC CONTYP *tcp_dropcontact(CONTYP *contact) + +{ +return contact; +} +/* +^L +*/ +/********************************************************/ +/* */ +/* Procedure to "open/close" module and do */ +/* homework purpose */ +/* return zero if everything right */ +/* */ +/********************************************************/ +PUBLIC int tcp_modegestcp(_Bool mode) + +{ +#define OPEP "unisig.c:sig_modeunisig" + +int status; + +status=0; +if (mode!=modopen) { + (void) soc_modeunisoc(mode); + switch ((int)mode) { + case true : + (void) rou_modesubrou(mode); + (void) soc_modeunisoc(mode); + break; + case false : + (void) soc_modeunisoc(mode); + (void) rou_modesubrou(mode); + break; + default : + (void) fprintf(stderr,"Calling %s with wrong mode='%d' (Bug?!):", + OPEP,(int)mode); + status=-1; + break; + } + modopen=mode; + } +return status; +#undef OPEP +} diff --git a/lib/gestcp.h b/lib/gestcp.h new file mode 100644 index 0000000..0cc20ef --- /dev/null +++ b/lib/gestcp.h @@ -0,0 +1,27 @@ +// vim: smarttab tabstop=8 shiftwidth=2 expandtab +/************************************************/ +/* */ +/* Unit level to handle TCP communication */ +/* */ +/************************************************/ +#ifndef GESTCP +#define GESTCP + +#include + +#include "unisoc.h" + +typedef struct { + void *ptr; //JMPDBG + }CONTYP; + +//wait for an incoming contact +extern CONTYP *tcp_getcontact(SOCTYP *binding); + +//drop contact established by remote +extern CONTYP *tcp_dropcontact(CONTYP *contact); + +//homework to be done before starting/stopping module. +extern int tcp_modegestcp(_Bool mode); + +#endif diff --git a/lib/modrec.c b/lib/modrec.c index 17ce742..e691a82 100644 --- a/lib/modrec.c +++ b/lib/modrec.c @@ -14,6 +14,7 @@ #include "uniprc.h" #include "unisig.h" #include "unisoc.h" +#include "gestcp.h" #include "modrec.h" static _Bool modopen; //boolean module open/close @@ -22,21 +23,41 @@ static _Bool modopen; //boolean module open/close */ /********************************************************/ /* */ -/* kleenex procedure */ +/* procedure to detect and accept a contact from */ +/* a remote TCP connection. */ /* */ /********************************************************/ -static void kludge(SOCTYP *binding,int attend) +void contact(SOCTYP *binding) { -for (int i=0;i", - attend-i,binding->ip,binding->port); - (void) sleep(1); - if ((hangup==true)||(reload==true)){ - (void) rou_alert(0,"JMPDBG process terminated"); - break; +#define OPEP "modrec.c:contact" + +CONTYP *contact; +int phase; +_Bool proceed; + +contact=(CONTYP *)0; +phase=0; +proceed=true; +while (proceed==true) { + switch (phase) { + case 0 : //do we have a contact + if ((contact=tcp_getcontact(binding))==(CONTYP *)0) { + phase=999; //no going further + } + break; + case 1 : //do contact + (void) sleep(40); //JMPDBG + break; + case 2 : //close contact + contact=tcp_dropcontact(contact); + break; + default : //SAFE guard + break; } + phase++; } +#undef OPEP } /* @@ -69,11 +90,8 @@ while (proceed==true) { } } break; - case 1 : //dispating need process + case 1 : //dispating need process for (int i=0;iiteration;i++) { - int attend; - - attend=(random()%60)+10; if (binding->childs[i]!=(pid_t)0) continue; switch(binding->childs[i]=fork()) { @@ -82,9 +100,9 @@ while (proceed==true) { "handle <%s:%s> socket (config?)", OPEP,binding->ip,binding->port); break; - case 0 : //the dispatched process - (void) kludge(binding,attend); - (void) sleep(1); //avoiding avalanche + case 0 : //the dispatched process + (void) contact(binding); //waiting, handling remote contact + (void) sleep(1); //avoiding avalanche (void) exit(0); break; default : @@ -265,8 +283,10 @@ if (mode!=modopen) { (void) prc_modeuniprc(mode); (void) sig_modeunisig(mode); (void) soc_modeunisoc(mode); + (void) tcp_modegestcp(mode); break; case false : + (void) tcp_modegestcp(mode); (void) soc_modeunisoc(mode); (void) sig_modeunisig(mode); (void) prc_modeuniprc(mode);