else {
int flags;
+ (void) rou_alert(0,"JMPDBG binding->handle '%d'",binding->handle);
if ((flags=fcntl(contact,F_GETFL,0))<0)
(void) rou_core_dump("%s Unable to get socket descripteur (error='%s')",
OPEP,strerror(errno));
}
break;
case 2 : //listening on the handle
+ (void) soc_setlinger(binding->handle);
+ (void) soc_getlinger(binding->handle,"waitlisten");
+ break;
+ case 3 : //listening on the handle
fd_set reading;
struct timeval relax;
int status;
case -1 : //got a wrong return
switch (errno) {
case EINTR : //Received a signal, get out! fast!
- (void) rou_alert(0,"JMPDBG select received a signal!");
+ (void) fprintf(stderr,"JMPDBG pid='%05d select received a signal!\n",
+ getpid());
phase=999;
break;
default : //Unexpected error?
break;
}
phase++;
- (void) rou_alert(0,"JMPDB waitlisten contat='%d' phase='%d'",contact,phase);
+ //(void) rou_alert(0,"JMPDB waitlisten contat='%d' phase='%d'",contact,phase);
}
return contact;
#undef OPEP
sent=0;
va_start(args,format);
sent=vdprintf(contact->channel,format,args);
+//(void) fdatasync(contact->channel);
va_end(args);
return sent;
}
proceed=false;
break;
}
- (void) rou_alert(0,"JMPDB tcp_getcontact contat='%p' phase='%d'",contact,phase);
+ //(void) rou_alert(0,"JMPDBG tcp_getcontact contat='%p' phase='%d'",contact,phase);
phase++;
}
return contact;
case 2 : //do contact
for (int i=0;i<TESTL;i++) {
int sent;
+ char tmpbuf[100];
- (void) sleep(2);
if ((reload==true)||(hangup==true))
break;
if (prc_checkprocess(getppid())==false)
break;
- sent=tcp_fprintf(contact,"JMPDBG pid=%d iter=%d/%d\n",getpid(),i,TESTL);
+ sent=tcp_fprintf(contact,"Remote pid=%d iter=%d/%d\n",getpid(),i,TESTL);
if (sent<0) {
(void) rou_alert(0,"JMPDBG tcp_fprintf error <%s>",strerror(errno));
break;
}
+ (void) read(contact->channel,tmpbuf,sizeof(tmpbuf));
+ (void) sleep(2);
}
break;
case 3 : //close contact
for (int i=0;i<binding->iteration;i++) {
if (binding->childs[i]!=(pid_t)0)
continue;
+ (void) soc_getlinger(binding->handle,"before fork");
switch(binding->childs[i]=fork()) {
case -1 :
(void) rou_alert(0,"%s, Unable to start process to "
break;
case 0 : //the dispatched process
(void) closelog();
- (void) openlog("Contact",LOG_PID,LOG_DAEMON);
+ (void) openlog("Contact",LOG_NDELAY|LOG_PID,LOG_DAEMON);
(void) docontact(binding); //waiting, handling remote contact
(void) rou_alert(0,"Contact Exiting: %s-%s",appname,rou_getversion());
(void) sleep(1); //avoiding avalanche
+ (void) closelog();
(void) exit(0);
break;
default :
break;
case 1 : //check need to dispatch a process
while (*bindings!=(SOCTYP *)0) {
+ (void) soc_getlinger((*bindings)->handle,"before displatching");
(void) dispatching(*bindings);
bindings++;
}
_Bool proceed;
bindings=(SOCTYP **)0;
-bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.25","2525",1);
-//bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.26","2626",3);
+bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.25","2525",2);
+//bindings=soc_mkbindinf(bindings,pro_smtp,"127.0.0.26","2626",1);
phase=0;
proceed=true;
while (proceed==true) {
phase=0;
proceed=true;
while (proceed==true) {
+ if (handle>=0) {
+ char bigre[50];
+
+ (void) sprintf(bigre,"Phase='%02d'",phase);
+ (void) soc_getlinger(handle,bigre);
+ }
switch (phase) {
case 0 : //lets get a socket
if ((handle=socket(ai->ai_family,ai->ai_socktype,ai->ai_protocol))<0) {
if (setsockopt(handle,SOL_SOCKET,SO_LINGER,&slg,sizeof(slg))<0) {
(void) rou_alert(0,"%s Unable to set socket option "
"SO_LINGER for <%s> (error='%s')",
- OPEP,ai->ai_canonname,strerror(errno));
+ OPEP,strerror(errno));
phase=999; //trouble cleanup phase
}
break;
case 4 : /*getting socket option */
+ (void) soc_getlinger(handle,"binhandle");
if ((flags=fcntl(handle,F_GETFL,0))<0) {
(void) rou_alert(0,"%s Unable to set socket descriptor "
"for <%s> (error='%s')",
}
break;
case 6 : //getting socket option
+ (void) soc_getlinger(handle,"before bind");
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));
}
break;
case 7 : /*preparing listen */
+ (void) soc_getlinger(handle,"after bind");
if (listen(handle,5)<0) {
(void) rou_alert(0,"%s Unable to listen on IP/port <%s/%s> (error='%s')",
OPEP,ai->ai_canonname,binding->port,strerror(errno));
}
break;
case 8 : /*reporting listen */
+ (void) soc_getlinger(handle,"after listen");
(void) rou_alert(1,"Now Listening on IP/PORT <%s/%s>",
ai->ai_canonname,binding->port);
proceed=false; //evrything fine no need to go further
}
(void) free(buf);
(void) rou_alert(0,"JMPDBG got handle channel='%d'",handle);
+(void) soc_getlinger(handle,"exiting from bindhandle");
return handle;
#undef OPEP
}
return bindings;
}
/*
+\f
+*/
+/********************************************************/
+/* */
+/* Procedure to set set the linger mode on the */
+/* socket device. */
+/* return -1 if trouble. */
+/* */
+/********************************************************/
+PUBLIC int soc_setlinger(int socket)
+
+{
+#define OPEP "unisoc.c:soc_setlinger"
+#define BFSZ 30
+
+int status;
+int flags;
+char *buf;
+struct linger slg;
+
+status=-1;
+slg.l_onoff=true;
+slg.l_linger=0;
+buf=calloc(BFSZ,sizeof(char));
+flags=fcntl(socket,F_GETFL,0);
+(void) fcntl(socket,F_SETFL,flags|O_NONBLOCK|O_ASYNC);
+(void) setsockopt(socket,SOL_SOCKET,SO_REUSEADDR,buf,BFSZ*sizeof(char));
+(void) setsockopt(socket,SOL_SOCKET,SO_REUSEPORT,buf,BFSZ*sizeof(char));
+status=setsockopt(socket,SOL_SOCKET,SO_LINGER,&slg,sizeof(slg));
+if (status<0)
+ (void) rou_alert(0,"%s Unable to set socket option "
+ "SO_LINGER for <%s> (error='%s' bug?)",
+ OPEP,strerror(errno));
+(void) free(buf);
+return status;
+#undef OPEP
+}
+/*
^L
*/
/********************************************************/
break;
case 3 : //binding socket
soc=bindhandle(tobind,binding);
- (void) freeaddrinfo(tobind);
+ (void) soc_getlinger(soc,"result from bindhandle");
+ //(void) freeaddrinfo(tobind); JMPDBG ALARM
break;
default : //SAFE Guard
proceed=false;
}
phase++;
}
+(void) soc_getlinger(soc,"exiting from soc_onelisten");
return soc;
#undef OPEP
}
case 2 : //binding on all interface
ready=true;
while (*bindings!=(SOCTYP *)0) {
- (*bindings)->handle=soc_onelisten(*bindings);
+ int soc;
+
+ soc=soc_onelisten(*bindings);
+ (void) soc_getlinger(soc,"after onelisten");
+ (*bindings)->handle=soc;
+ (void) soc_getlinger((*bindings)->handle,"after binding onelisten");
if ((*bindings)->handle<0)
ready=false; //Trouble?
+ else
+ (void) soc_getlinger((*bindings)->handle,"mullisten");
bindings++;
}
break;
}
#undef OPEP
}
+//temporary JMPDBG
+void soc_getlinger(int socket,char *inf)
+
+{
+socklen_t len;
+struct linger slg;
+
+if (getsockopt(socket,SOL_SOCKET,SO_LINGER,&slg,&len)<0)
+ (void) rou_alert(0,"JMPDBG LISTEN trouble (error='%s')",strerror(errno));
+(void) rou_alert(0,"JMPDBG [%s] get socket='%d' linger.onoff='%d', "
+ "timeout linger='%d'",
+ inf,socket,slg.l_onoff,slg.l_linger);
+}
/*
^L
*/