--- /dev/null
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/********************************************************/
+/* */
+/* Module for signal handling level */
+/* */
+/********************************************************/
+#include <sys/wait.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#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
+}
--- /dev/null
+// vim: smarttab tabstop=8 shiftwidth=2 expandtab
+/************************************************/
+/* */
+/* Unit level to handle TCP communication */
+/* */
+/************************************************/
+#ifndef GESTCP
+#define GESTCP
+
+#include <stdbool.h>
+
+#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
#include "uniprc.h"
#include "unisig.h"
#include "unisoc.h"
+#include "gestcp.h"
#include "modrec.h"
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++) {
- (void) prc_settitle("Kluge for %d seconds, ip:port=<%s:%s>",
- 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
}
/*
\f
}
}
break;
- case 1 : //dispating need process
+ case 1 : //dispating need process
for (int i=0;i<binding->iteration;i++) {
- int attend;
-
- attend=(random()%60)+10;
if (binding->childs[i]!=(pid_t)0)
continue;
switch(binding->childs[i]=fork()) {
"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 :
(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);