OBJS= \
modrec.o \
gestcp.o \
+ devsoc.o \
unieml.o \
- unipar.o uniprc.o unisig.o unisoc.o \
+ unipar.o uniprc.o unisig.o \
subrou.o
objs : $(OBJS)
subrou.h \
uniprc.h \
unisig.h \
- unisoc.h \
+ devsoc.h \
gestcp.h \
modrec.h modrec.c
unisig.h \
gestcp.h gestcp.c
+devsoc.o: \
+ subrou.h \
+ uniprc.h \
+ devsoc.h devsoc.c
+
unieml.o: \
unieml.h unieml.c
subrou.h \
unisig.h unisig.c
-unisoc.o: \
- subrou.h \
- unisoc.h unisoc.c
-
subrou.o: \
subrou.h subrou.c
gestcp.h: \
- unisoc.h \
+ devsoc.h \
uniprc.h: \
subrou.h \
#include <unistd.h>
#include "subrou.h"
-#include "unisoc.h"
+#include "uniprc.h"
+#include "devsoc.h"
//Need to have GNU_SOURCE define within CFLAGS
#ifdef AI_ALL
#define HINTFLG AI_CANONNAME
#endif
+typedef struct {
+ PROTYP proto; //Connexion protocol type
+ char *ip; //Binding IP //IPV4 or IPV6
+ char *port; //Binding Port
+ time_t lasttry; //successful binding last time
+ int iteration; //number of soc slot used on the IP
+ int handle; //connexion handle
+ }SOCTYP;
static _Bool modopen; //module open/close status
/*
/* */
/* */
/********************************************************/
-static SOCTYP *freebinding(SOCTYP *binding)
+static SOCPTR *freebinding(SOCPTR *socptr)
{
-if (binding!=(SOCTYP *)0) {
- binding->port=rou_freestr(binding->port);
- binding->ip=rou_freestr(binding->ip);
- (void) free(binding);
- binding=(SOCTYP *)0;
+if (socptr!=(SOCPTR *)0) {
+ register SOCTYP *soc;
+
+ soc=(SOCTYP *)socptr;
+ soc->port=rou_freestr(soc->port);
+ soc->ip=rou_freestr(soc->ip);
+ (void) free(soc);
+ socptr=(SOCPTR *)0;
}
-return binding;
+return socptr;
}
/*
\f
/* address and return the linked handle */
/* */
/********************************************************/
-static int bindhandle(struct addrinfo *ai,SOCTYP *binding)
+static int bindhandle(struct addrinfo *ai,SOCTYP *soc)
{
#define OPEP "unisoc.c:bindhandle,"
server_addr.sin_port = htons(2525);
if (bind(handle,ai->ai_addr,ai->ai_addrlen)<0) {
(void) rou_alert(0,"%s Unable to bind on IP/port <%s/%s> (error='%s')",
- OPEP,ai->ai_canonname,binding->port,strerror(errno));
+ OPEP,ai->ai_canonname,soc->port,strerror(errno));
phase=999; //trouble cleanup phase
}
break;
*/
/********************************************************/
/* */
-/* Procedure fine the hostname related to an */
-/* address, if local is true return the local */
-/* hostname. */
-/* if trouble, return a NULL pointer. */
+/* Procedure to free memory used by a bind */
+/* definition. */
/* */
/********************************************************/
-PUBLIC char *soc_getaddrname(int handle,_Bool local)
+PUBLIC SOCPTR **soc_freebindinf(SOCPTR **socptr)
{
-#define OPEP "unisoc.c:soc_getaddrname"
-
-char *name;
-struct sockaddr connip;
-socklen_t taille;
-int status;
-char host[NI_MAXHOST];
+if (socptr!=(SOCPTR **)0) {
+ register SOCTYP **socs;
+ int i;
-name=(char *)0;
-taille=sizeof(connip);
-if (local==true) {
- if ((status=getsockname(handle,&connip,&taille))==0) {
- if (getnameinfo(&connip,taille,host,sizeof(host),(char *)0,0,NI_NAMEREQD)==0)
- name=strdup(host);
- }
- }
-else {
- if ((status=getpeername(handle,&connip,&taille))==0) {
- if (getnameinfo(&connip,taille,host,sizeof(host),(char *)0,0,NI_NUMERICHOST)==0)
- name=strdup(host);
+ socs=(SOCTYP **)socptr;
+ for (i=0;socs[i]!=(SOCTYP *)0;i++) {
+ socs[i]=freebinding(socs[i]);
}
+ (void) free(socs);
+ socptr=(SOCPTR **)0;
}
-if (status<0) {
- switch (errno) {
- case ENOTCONN : //other side just vanished
- break;
- default :
- (void) rou_alert(0,"%s, Unable to find reverse (local=%d, error=<%s>)",
- OPEP,local,strerror(errno));
- break;
- }
- }
-return name;
-#undef OPEP
+return socptr;
}
/*
\f
*/
/********************************************************/
/* */
-/* Procedure to free memory used by a bind */
+/* Procedure to set memory used by a bin */
/* definition. */
/* */
/********************************************************/
-PUBLIC SOCTYP **soc_freebindinf(SOCTYP **bindref)
+PUBLIC SOCPTR **soc_mkbindinf(SOCPTR **socptr,PROTYP proto,
+ const char *ip,const char *port,int iteration)
{
-if (bindref!=(SOCTYP **)0) {
- int i;
+SOCTYP *soc;
- for (i=0;bindref[i]!=(SOCTYP *)0;i++) {
- bindref[i]=freebinding(bindref[i]);
- }
- (void) free(bindref);
- bindref=(SOCTYP **)0;
- }
-return bindref;
+soc=(SOCTYP *)calloc(1,sizeof(SOCTYP));
+soc->proto=proto;
+soc->ip=strdup(ip);
+soc->port=strdup(port);
+soc->iteration=iteration;
+socptr=(SOCPTR **)rou_addlist((void **)socptr,(void *)soc);
+return socptr;
}
/*
-\f
+^L
*/
/********************************************************/
/* */
-/* Procedure to set memory used by a bin */
-/* definition. */
+/* Procedure to return the number of iterations */
+/* within socket definition. */
/* */
/********************************************************/
-PUBLIC SOCTYP **soc_mkbindinf(SOCTYP **bindings,PROTYP proto,
- const char *ip,const char *port,int iteration)
+PUBLIC int soc_getiterations(SOCPTR *socptr)
{
-SOCTYP *bininf;
+int iterations;
+SOCTYP *soc;
-bininf=(SOCTYP *)calloc(1,sizeof(SOCTYP));
-bininf->proto=proto;
-bininf->ip=strdup(ip);
-bininf->port=strdup(port);
-bininf->iteration=iteration;
-bindings=(SOCTYP **)rou_addlist((void **)bindings,(void *)bininf);
-return bindings;
+soc=(SOCTYP *)socptr;
+if (soc!=(SOCTYP *)0)
+ iterations=soc->iteration;
+return iterations;
}
/*
^L
/* socket handle */
/* */
/********************************************************/
-PUBLIC _Bool soc_openbinding(SOCTYP *binding)
+PUBLIC _Bool soc_openbinding(SOCPTR *socptr)
{
#define OPEP "unisoc.c:soc_openbinding"
_Bool done;
+SOCTYP *soc;
struct addrinfo hints;
struct addrinfo *tobind;
int phase;
_Bool proceed;
done=false;
+soc=(SOCTYP *)socptr;
(void) memset(&hints,'\000',sizeof(hints));
hints.ai_family=PF_UNSPEC;
hints.ai_flags=HINTFLG;
while (proceed==true) {
switch (phase) {
case 0 : //sanity check
- if (binding==(SOCTYP *)0) {
+ if (soc==(SOCTYP *)0) {
(void) rou_alert(0,"%s, socket binding reference is NULL (Bug!?)",OPEP);
phase=999; //no need to go further
}
break;
case 1 : //check if time to retry binding
- if ((binding->lasttry+5)>time((time_t)0))
+ if ((soc->lasttry+5)>time((time_t)0))
phase=999; //no need to go further
break;
case 2 : //to have the right address infp
int status;
- binding->lasttry=time((time_t *)0);
- if ((status=getaddrinfo(binding->ip,binding->port,&hints,&tobind))!=0) {
+ soc->lasttry=time((time_t *)0);
+ if ((status=getaddrinfo(soc->ip,soc->port,&hints,&tobind))!=0) {
(void) rou_alert(0,"%s, Unable to find a address about "
"IP:port '%s:%s' (error='%s')",
- binding->ip,binding->port,gai_strerror(status));
+ soc->ip,soc->port,gai_strerror(status));
phase=999; //no need to go further
}
break;
case 3 : //binding socket
- if ((binding->handle=bindhandle(tobind,binding))<0)
+ if ((soc->handle=bindhandle(tobind,soc))<0)
phase=999; //no need to go further
(void) freeaddrinfo(tobind);
break;
case 4 : //listening on socket
- if (listen(binding->handle,binding->iteration+4)<0) {
+ (void) prc_settitle("monitoring %02d contacts on %s:%s",
+ soc->iteration,soc->ip,soc->port);
+ if (listen(soc->handle,soc->iteration+4)<0) {
(void) rou_alert(0,"%s, Unable to listen at address "
"IP:port '%s:%s' (error='%s')",
- binding->ip,binding->port,strerror(errno));
- (void) close(binding->handle);
- binding->handle=-1;
+ soc->ip,soc->port,strerror(errno));
+ (void) close(soc->handle);
+ soc->handle=-1;
phase=999; //no need to go further
}
break;
/* Procedure to unbind from one socket. */
/* */
/********************************************************/
-PUBLIC void soc_closebinding(SOCTYP *binding)
+PUBLIC void soc_closebinding(SOCPTR *socptr)
{
#define OPEP "unisoc.c:soc_closebinding"
+SOCTYP *soc;
int phase;
_Bool proceed;
+soc=(SOCTYP *)socptr;
phase=0;
proceed=true;
while (proceed==true) {
switch (phase) {
case 0 : //sanity check
- if (binding==(SOCTYP *)0) {
+ if (soc==(SOCTYP *)0) {
(void) rou_alert(0,"%s binding pointer is NULL (Bug!?)",OPEP);
phase=999; //not going further
}
break;
case 1 : //check if socket already close
- if (binding->handle<0) {
+ if (soc->handle<0) {
phase=999; //yes, no need to go further
}
break;
case 2 : //closing the the socket
- if (close(binding->handle)<0)
+ if (close(soc->handle)<0)
(void) rou_alert(0,"%s Unable to close socket (Bug!?, error=<%s>)",
OPEP,strerror(errno));
- binding->handle=-1;
+ soc->handle=-1;
break;
default : //SAFE Guard
proceed=false;
/* return the handle */
/* */
/********************************************************/
-PUBLIC int soc_accept(SOCTYP *binding,SOCKADDR *addr)
+PUBLIC int soc_accept(SOCPTR *socptr,int pos)
{
#define OPEP "unisoc.c:soc_accept"
+
int newhandle;
-socklen_t taille;
+register SOCTYP *soc;
newhandle=-1;
-taille=sizeof(struct sockaddr);
-if ((newhandle=accept(binding->handle,addr,&taille))<0) {
- if (errno==EAGAIN)
- errno=EWOULDBLOCK;
- switch (errno) {
- case EWOULDBLOCK :
- (void) rou_alert(0,"%s Socket on IP/PORT <%s/%s> is in no_block mode "
- "(Bug?!, errno=<%s>)",
- OPEP,binding->ip,binding->port,strerror(errno));
- break;
- case EINVAL :
- (void) rou_alert(0,"%s Socket on IP/PORT <%s/%s> not available "
- "(Bug?!, errno=<%s>)",
- OPEP,binding->ip,binding->port,strerror(errno));
- break;
- case EINTR :
- (void) rou_alert(0,"%s Socket on IP/PORT <%s/%s> got a signal "
- "(errno=<%s>)",
- OPEP,binding->ip,binding->port,strerror(errno));
- break;
- default :
- (void) rou_alert(0,"%s Unexpected error on IP/PORT <%s/%s> (errno=<%s>)",
- OPEP,binding->ip,binding->port,strerror(errno));
+soc=(SOCTYP *)socptr;
+if (soc!=(SOCTYP *)0) {
+ (void) prc_settitle("Waiting contact (%02d/%02d) on %s:%s",
+ pos,soc->iteration,soc->ip,soc->port);
+ if ((newhandle=accept(soc->handle,(SOCKADDR *)0,(socklen_t *)0))<0) {
+ if (errno==EAGAIN)
+ errno=EWOULDBLOCK;
+ switch (errno) {
+ case EWOULDBLOCK :
+ (void) rou_alert(0,"%s Socket on IP/PORT <%s/%s> is in no_block mode "
+ "(Bug?!, errno=<%s>)",
+ OPEP,soc->ip,soc->port,strerror(errno));
break;
+ case EINVAL :
+ (void) rou_alert(0,"%s Socket on IP/PORT <%s/%s> not available "
+ "(Bug?!, errno=<%s>)",
+ OPEP,soc->ip,soc->port,strerror(errno));
+ break;
+ case EINTR :
+ (void) rou_alert(0,"%s Socket on IP/PORT <%s/%s> got a signal "
+ "(errno=<%s>)",
+ OPEP,soc->ip,soc->port,strerror(errno));
+ break;
+ default :
+ (void) rou_alert(0,"%s Unexpected error on IP/PORT <%s/%s> (errno=<%s>)",
+ OPEP,soc->ip,soc->port,strerror(errno));
+ break;
+ }
}
- }
-else {
- int flags;
+ else {
+ int flags;
- if ((flags=fcntl(newhandle,F_GETFL,0))<0)
- (void) rou_core_dump("%s, Unable to get socket descripteur on "
- "IP/PORT <%s/%s> (Bug? error=<%s>)",
- OPEP,binding->ip,binding->port,strerror(errno));
- if ((flags=fcntl(newhandle,F_SETFL,flags|O_NONBLOCK|O_ASYNC))<0)
- (void) rou_core_dump("%s, Unable to set socket descripteur on "
- "IP/PORT <%s/%s> (Bug? error=<%s>)",
- OPEP,binding->ip,binding->port,strerror(errno));
+ if ((flags=fcntl(newhandle,F_GETFL,0))<0)
+ (void) rou_core_dump("%s, Unable to get socket descripteur on "
+ "IP/PORT <%s/%s> (Bug? error=<%s>)",
+ OPEP,soc->ip,soc->port,strerror(errno));
+ if ((flags=fcntl(newhandle,F_SETFL,flags|O_NONBLOCK|O_ASYNC))<0)
+ (void) rou_core_dump("%s, Unable to set socket descripteur on "
+ "IP/PORT <%s/%s> (Bug? error=<%s>)",
+ OPEP,soc->ip,soc->port,strerror(errno));
+ }
}
return newhandle;
#undef OPEP
/* return zero if everything right */
/* */
/********************************************************/
-int soc_modeunisoc(_Bool mode)
+int soc_modedevsoc(_Bool mode)
{
#define OPEP "unidoc.c:soc_modeunisoc"
status=0;
if (mode!=modopen) {
- (void) rou_modesubrou(mode);
switch ((int)mode) {
case true :
+ (void) rou_modesubrou(mode);
+ (void) prc_modeuniprc(mode);
break;
case false :
+ (void) prc_modeuniprc(mode);
+ (void) rou_modesubrou(mode);
break;
default :
(void) fprintf(stderr,"Calling %s with wrong mode='%d' (Bug?!):",
/* to handle tcp Socket. */
/* */
/********************************************************/
-#ifndef UNISOC
-#define UNISOC
+#ifndef DEVSOC
+#define DEVSOC
#include <sys/socket.h>
#include <stdbool.h>
pro_unknwn //Protcole undefined
}PROTYP;
-typedef struct {
- PROTYP proto; //Connexion protocol type
- char *ip; //Binding IP //IPV4 or IPV6
- char *port; //Binding Port
- time_t lasttry; //successful binding last time
- int iteration; //number of soc slot used on the IP
- int handle; //connexion handle
- }SOCTYP;
-
-//procedure to get peer or local name related to a socket
-extern char *soc_getaddrname(int handle,_Bool local);
+//reference to a socket definition
+typedef void SOCPTR;
//procedure to free all memory used by a TCP socket
//definition (once closed)
-extern SOCTYP **soc_freebindinf(SOCTYP **bindref);
+extern SOCPTR **soc_freebindinf(SOCPTR **socptr);
//procedure to assign memory to be used by a TCP socket
//definition
-extern SOCTYP **soc_mkbindinf(SOCTYP **bindings,PROTYP proto,
+extern SOCPTR **soc_mkbindinf(SOCPTR **s,PROTYP proto,
const char *ip,const char *port,int iteration);
+//procedure to return the number of channel to open on the soc
+extern int soc_getiterations(SOCPTR *socptr);
+
//procedure to open ONE socket and return handle to socket
-extern _Bool soc_openbinding(SOCTYP *binding);
+extern _Bool soc_openbinding(SOCPTR *socptr);
//procedure to close ONE socket
-extern void soc_closebinding(SOCTYP *binding);
+extern void soc_closebinding(SOCPTR *socptr);
//procedure to wait and accept remote connexion
-extern int soc_accept(SOCTYP *binding,SOCKADDR *addr);
+extern int soc_accept(SOCPTR *socptr,int pos);
//homework to be done before starting/stopping module.
-extern int soc_modeunisoc(_Bool mode);
+extern int soc_modedevsoc(_Bool mode);
#endif
static _Bool modopen; //boolean module open/close
/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to find the hostname related to an */
+/* socket, if local is true return the local */
+/* hostname else return the remote PID. */
+/* if trouble, return a NULL pointer. */
+/* */
+/********************************************************/
+static char *getaddrname(int handle,_Bool local)
+
+{
+#define OPEP "gestcp.c:soc_getaddrname"
+
+char *name;
+
+struct sockaddr connip;
+socklen_t taille;
+int status;
+char host[NI_MAXHOST];
+
+name=(char *)0;
+taille=sizeof(connip);
+status=-1;
+if (local==true) {
+ if ((status=getsockname(handle,&connip,&taille))==0) {
+ if (getnameinfo(&connip,taille,host,sizeof(host),(char *)0,0,NI_NAMEREQD)==0)
+ name=strdup(host);
+ }
+ }
+else {
+ if ((status=getpeername(handle,&connip,&taille))==0) {
+ if (getnameinfo(&connip,taille,host,sizeof(host),(char *)0,0,NI_NUMERICHOST)==0)
+ name=strdup(host);
+ }
+ }
+if (status<0) {
+ switch (errno) {
+ case ENOTCONN : //other side just vanished
+ break;
+ default :
+ (void) rou_alert(0,"%s, Unable to find reverse (local=%d, error=<%s>)",
+ OPEP,local,strerror(errno));
+ break;
+ }
+ }
+return name;
+#undef OPEP
+}
+/*
^L
*/
/********************************************************/
/* Procedure to free memory used by contact */
/* */
/********************************************************/
-PUBLIC CONTYP *tcp_freecontact(CONTYP *contact)
+static CONTYP *freecontact(CONTYP *contact)
{
+#define OPEP "gesttcp.c:freecontact"
+
if (contact!=(CONTYP *)0) {
- if (contact->channel>=0)
- (void) close(contact->channel);
+ if (contact->channel>=0) {
+ if (close(contact->channel)<0) {
+ (void) rou_alert(0,"%s unable to close channel properly (errno=<%s>)",
+ OPEP,strerror(errno));
+ }
+ }
if (contact->peerip!=(char *)0)
(void) free(contact->peerip);
if (contact->locname!=(char *)0)
contact=(CONTYP *)0;
}
return contact;
+#undef OPEP
}
/*
^L
/* return all reference to the established contact.*/
/* */
/********************************************************/
-PUBLIC CONTYP *tcp_getcontact(SOCTYP *binding)
+PUBLIC CONTYP *tcp_getcontact(SOCPTR *socptr,int pos)
{
#define OPEP "gestcp.c:tcp_getcontact"
CONTYP *contact;
-SOCKADDR addr;
int phase;
_Bool proceed;
-contact=calloc(1,sizeof(CONTYP));
-contact->binding=binding;
+contact=(CONTYP *)0;
phase=0;
proceed=true;
while (proceed==true) {
switch (phase){
case 0 : //check for binding
- if (binding==(SOCTYP *)0) {
- (void) rou_alert(0,"%s binding pointer is NULL (Bug!?)",OPEP);
+ if (socptr==(SOCPTR *)0) {
+ (void) rou_alert(0,"%s socket pointer is NULL (Bug!?)",OPEP);
phase=999; //not going further
}
break;
case 1 : //waiting from contact
- if ((contact->channel=soc_accept(binding,&addr))<0) {
+ contact=calloc(1,sizeof(CONTYP));
+ contact->socptr=socptr;
+ if ((contact->channel=soc_accept(socptr,pos))<0) {
(void) rou_alert(0,"%s Unable to open contact",OPEP);
- contact=tcp_freecontact(contact);
+ contact=freecontact(contact);
phase=999; //no contact
}
break;
case 2 : //check socket components
- contact->locname=soc_getaddrname(contact->channel,true);
- contact->peerip=soc_getaddrname(contact->channel,false);
+ contact->locname=getaddrname(contact->channel,true);
+ contact->peerip=getaddrname(contact->channel,false);
if ((contact->locname==(char *)0)||(contact->peerip==(char *)0)) {
(void) rou_alert(0,"%s Unable to establish contact entities",OPEP);
- contact=tcp_freecontact(contact);
+ contact=freecontact(contact);
phase=999; //no identity
}
break;
rou_ascsysstamp(time((time_t *)0)),CRLF);
if (tcp_write(contact,signon,strlen(signon))<0) {
(void) rou_alert(0,"%s Unable to send signon to remote",OPEP);
- contact=tcp_freecontact(contact);
+ contact=freecontact(contact);
phase=999; //no contact
}
#undef FMT
}
break;
case 1 : //properly closing remote contact
+ (void) rou_alert(0,"Contact with IP=<%s> Exiting",contact->peerip);
if (shutdown(contact->channel,SHUT_RDWR)<0) {
switch (errno) {
case ENOTCONN : //already disconnect by other side!
break;
}
}
- if (close(contact->channel)<0) {
- (void) rou_alert(0,"%s unable to close channel properly (errno=<%s>)",
- OPEP,strerror(errno));
- }
break;
case 2 : //freeing contact memory
- (void) free(contact);
- contact=(CONTYP *)0;
+ contact=freecontact(contact);
break;
default : //SAFE guard
proceed=false;
status=0;
if (mode!=modopen) {
- (void) soc_modeunisoc(mode);
switch ((int)mode) {
case true :
(void) rou_modesubrou(mode);
- (void) soc_modeunisoc(mode);
(void) sig_modeunisig(mode);
(void) prc_modeuniprc(mode);
(void) eml_modeunieml(mode);
+ (void) soc_modedevsoc(mode);
break;
case false :
+ (void) soc_modedevsoc(mode);
(void) eml_modeunieml(mode);
(void) sig_modeunisig(mode);
(void) prc_modeuniprc(mode);
- (void) soc_modeunisoc(mode);
(void) rou_modesubrou(mode);
break;
default :
#include <stdbool.h>
-#include "unisoc.h"
+#include "devsoc.h"
typedef struct {
int channel; //exchange channel handle
char *locname; //socket local hostname
char *peerip; //socket remote peer IP
- SOCKADDR addr; //remote address (see getnameinfo)
- SOCTYP *binding;//established contact context
+ SOCPTR *socptr; //established contact context
}CONTYP;
//procedure to free contact
extern int tcp_write(CONTYP *contact,char *buffer,int parnum);
//wait for an incoming contact
-extern CONTYP *tcp_getcontact(SOCTYP *binding);
+extern CONTYP *tcp_getcontact(SOCPTR *socptr,int pos);
//drop contact established by remote
extern CONTYP *tcp_dropcontact(CONTYP *contact);
#include "subrou.h"
#include "uniprc.h"
#include "unisig.h"
-#include "unisoc.h"
+#include "devsoc.h"
#include "gestcp.h"
#include "modrec.h"
/* a remote TCP connection. */
/* */
/********************************************************/
-void docontact(SOCTYP *binding,int pos)
+void docontact(SOCPTR *socptr,int pos)
{
#define OPEP "modrec.c:contact"
proceed=true;
while (proceed==true) {
switch (phase) {
- case 0 : //display waiting contact
- (void) prc_settitle("Waiting contact (%02d/%02d) on %s:%s",
- pos,binding->iteration,binding->ip,binding->port);
- break;
- case 1 : //do we have a contact
- if ((contact=tcp_getcontact(binding))==(CONTYP *)0)
+ case 0 : //waiting contact
+ if ((contact=tcp_getcontact(socptr,pos))==(CONTYP *)0)
phase=999; //No contact!
break;
- case 2 : //forking process
+ case 1 : //forking process
printf("New client connected: %d\n",contact->channel);
break;
- case 3 : //do contact
+ case 2 : //do contact
printf("Client channel=%d (pid=%d)\n",contact->channel,getpid());
for (int i=0;i<TESTL;i++) {
int sent;
(void) sleep(1);
}
break;
- case 4 : //connection terminated
- (void) rou_alert(0,"Contact IP/PORT=<%s/%s> Exiting",
- binding->ip,binding->port);
+ case 3 : //connection terminated
contact=tcp_dropcontact(contact);
break;
default : //SAFE guard
/* Procedure to activate child process if necessary*/
/* */
/********************************************************/
-static void setready(SOCTYP *binding)
+static void setready(SOCPTR *socptr)
{
#define OPEP "modrec.c:setready"
-pid_t *childs;
int maxretry;
+pid_t *childs;
+int iterations;
int phase;
_Bool proceed;
-childs=(pid_t *)calloc(binding->iteration,sizeof(pid_t));
maxretry=5;
+childs=(pid_t *)0;
+iterations=soc_getiterations(socptr);
phase=0;
proceed=true;
while (proceed==true) {
- //(void) fprintf(stderr,"setready phase='%d'\n",phase);
switch (phase) {
case 0 : //empty phase
+ if (iterations>0)
+ childs=(pid_t *)calloc(iterations,sizeof(pid_t));
+ else
+ proceed=false; //Empty Soc!?!
break;
case 1 : //check need to dispatch a process
- for (int i=0;i<binding->iteration;i++) {
+ for (int i=0;i<iterations;i++) {
(void) prc_nozombie();
if (prc_checkprocess(childs[i])==true)
continue;
(void) sleep(1); //Weathering the storm
break;
case 0 : //Child process itself
- (void) docontact(binding,i+1);
+ (void) free(childs);
+ (void) docontact(socptr,i+1);
(void) exit(0);
break;
default : //Main process
phase=0; //lets continue to check childs
break;
default : //SAFE Guard
- (void) prc_killchilds(childs,binding->iteration,maxretry);
+ (void) prc_killchilds(childs,iterations,maxretry);
+ (void) free(childs);
proceed=false;
break;
}
phase++;
}
-(void) free(childs);
#undef OPEP
}
/*
/* Procedure to start a binding+waiting process */
/* */
/********************************************************/
-PUBLIC void startwaiter(SOCTYP *binding,int offset)
+PUBLIC void startwaiter(SOCPTR *socptr,int offset)
{
#define OPEP "moderec.c:startwaiter"
switch (phase) {
case 0 : //Opening logs
(void) openlog(appname,LOG_NDELAY|LOG_PID,LOG_DAEMON);
- (void) prc_settitle("Daemon Waiting on %s:%s (Num of channels='%02d')",
- binding->ip,binding->port,binding->iteration);
break;
case 1 : //binding on channel
- if (soc_openbinding(binding)==false) {
- (void) rou_alert(0,"%s Aborting binding on <%s:%s> (config?)",
- OPEP,binding->ip,binding->port);
+ if (soc_openbinding(socptr)==false) {
+ (void) rou_alert(0,"%s Aborting binding (config?)",OPEP);
phase=999; //no need to go further
}
break;
case 2 : //waiting
(void) rou_alert(0,"JMPDBG waiter starting");
- (void) setready(binding);
+ (void) setready(socptr);
(void) rou_alert(0,"JMPDBG waiter exiting");
break;
case 3 : //stop binding
- (void) soc_closebinding(binding);
+ (void) soc_closebinding(socptr);
break;
default : //SAFE Guard
(void) closelog();
pid_t *childs;
int nbrbind;
-SOCTYP **bindings;
+SOCPTR **bindings;
int phase;
_Bool proceed;
childs=(pid_t)0;
-bindings=(SOCTYP **)0;
+bindings=(SOCPTR **)0;
bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.1","2525",3);
bindings=soc_mkbindinf(bindings,pro_smtp,"192.219.254.70","2525",3);
bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.26","2626",1);
(void) rou_modesubrou(mode);
(void) prc_modeuniprc(mode);
(void) sig_modeunisig(mode);
- (void) soc_modeunisoc(mode);
+ (void) soc_modedevsoc(mode);
(void) tcp_modegestcp(mode);
break;
case false :
(void) tcp_modegestcp(mode);
- (void) soc_modeunisoc(mode);
+ (void) soc_modedevsoc(mode);
(void) sig_modeunisig(mode);
(void) prc_modeuniprc(mode);
(void) rou_modesubrou(mode);
//version definition
#define VERSION "0.3"
-#define RELEASE "15"
+#define RELEASE "16"
//Public variables
PUBLIC int debug=0; //debug level