]> SAFE projects GIT repository - jmp/mailleur/commitdiff
Detecting if remote connection just vanish
authorJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 1 Aug 2024 18:53:18 +0000 (14:53 -0400)
committerJean-Marc Pigeon (Delson) <jmp@safe.ca>
Thu, 1 Aug 2024 18:53:18 +0000 (14:53 -0400)
lib/gestcp.c
lib/gestcp.h
lib/modrec.c

index a4a3db64fb92de67ffbc79d83b33cefdb5c52ae9..d6cd0494522e6b3a11576ccb579eaada66343d10 100644 (file)
@@ -29,17 +29,34 @@ static  _Bool modopen;          //boolean module open/close
 /*      unable to send char return -1;                  */
 /*                                                      */
 /********************************************************/
-PUBLIC int tcp_fprintf(CONTYP *contact,const char *format,...)
+PUBLIC int tcp_write(CONTYP *contact,char *buffer,int parnum)
 
 {
 int sent;
-va_list args;
+int got;
+char zone[10];
 
-sent=0;
-va_start(args,format);
-sent=vdprintf(contact->channel,format,args);
-//(void) fdatasync(contact->channel);
-va_end(args);
+sent=-1;
+(void) strcpy(zone,"??");
+got=recv(contact->channel,zone,0,MSG_PEEK);
+switch (got) {
+  case -1       :
+    if (errno==EWOULDBLOCK)
+      errno=EAGAIN;
+    switch (errno) {
+      case EAGAIN       :
+        sent=send(contact->channel,buffer,parnum,MSG_DONTWAIT);
+        break;
+      default           :
+        (void) fprintf(stderr,"Got '%02d' error=<%s> (errno='%d')\n",
+                                     got,strerror(errno),errno);
+        break;
+      }
+    break;
+  default       :
+    (void) fprintf(stderr,"Got '%02d' zone=<%s>\n",got,zone);
+    break;
+  }
 return sent;
 }
 /*
index 9ce95779db900befc77872692eb6f0be34dba4a8..401026529f1387cd93e6a82b1bf9fc3655c21f89 100644 (file)
@@ -18,10 +18,7 @@ typedef struct  {
         }CONTYP;
 
 //Transmit formated data to the contact channel
-extern int tcp_fprintf(CONTYP *contact,const char *format,...);
-
-//Wait for an input coming from the contact channel
-extern int *tcp_fscanf(CONTYP *contact,const char *format,...);
+extern int tcp_write(CONTYP *contact,char *buffer,int parnum);
 
 //wait for an incoming contact
 extern CONTYP *tcp_getcontact(SOCTYP *binding);
index 92168fe60183e1cb75c6d5c4934b1e4045dda7c0..ec667e8a2ead3ee9115b04f0f55bcd5d96203170 100644 (file)
@@ -32,7 +32,7 @@ void docontact(SOCTYP *binding,int pos)
 
 {
 #define OPEP    "modrec.c:contact"
-#define TESTL   4
+#define TESTL   30
 
 CONTYP *contact;
 int phase;
@@ -57,8 +57,17 @@ while (proceed==true) {
     case 3      :       //do contact
       printf("Client channel=%d (pid=%d)\n",contact->channel,getpid());
       for (int i=0;i<TESTL;i++) {
-        (void) dprintf(contact->channel,"Remote pid=%d iter=%d/%d\n",
-                        getpid(),i,TESTL);
+        int sent;
+        char buffer[100];
+        
+        printf("send string\n");
+        sprintf(buffer,"Remote pid=%d iter=%d/%d\n",getpid(),i,TESTL);
+        sent=tcp_write(contact,buffer,strlen(buffer));
+        printf("string sent '%d'\n",sent);
+        if (sent<0) {
+          (void) rou_alert(0,"%s, Unable to send data to remote",OPEP);
+          break;
+          }
         (void) sleep(1);
         }
       break;