IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36740


Ignore:
Timestamp:
May 10, 2014, 2:44:40 PM (12 years ago)
Author:
eugene
Message:

catch the case where KapaClient connects to the wrong server

Location:
branches/eam_branches/ipp-20140423/Ohana/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20140423/Ohana/src/kapa2/src/CheckPipe.c

    r29938 r36740  
    11# include "Ximage.h"
     2# include <errno.h>
    23# define STRCONST(A) ((int)(0x1000000*A[0] + 0x10000*A[1] + 0x100*A[2] + 0x1*A[3]))
    34
     
    4142  word[4] = 0;
    4243  switch (status) {
    43   case -1:                          /* no input from pipe: continue */
    44     return (TRUE);
     44  case -1:
     45    if (errno == EAGAIN) {
     46      /* no input from pipe: continue */
     47      return (TRUE);
     48    }
     49    perror ("exiting due to problem with socket connection in CheckPipe");
     50    return (FALSE);
    4551    break;
    4652
  • branches/eam_branches/ipp-20140423/Ohana/src/libkapa/src/KapaOpen.c

    r35761 r36740  
    218218  // apparently, I can connect on someone else's port (eg GoogleTalkPlugin)
    219219  // do a simple handshake before we set !NONBLOCK:
    220   char line[5];
    221   int Nout = read (InitSocket, line, 4);
    222   if (Nout != 4) {
    223     if (DEBUG) fprintf (stderr, "connection failed\n");
    224     close (InitSocket);
    225     return (-1);
    226   }
    227   if (strncmp (line, "KAPA", 4)) {
    228     if (DEBUG) fprintf (stderr, "connection to the wrong server\n");
    229     close (InitSocket);
    230     return (-1);
     220
     221  // ensure the socket is NONBLOCK first...
     222  fcntl (InitSocket, F_SETFL, O_NONBLOCK);
     223
     224  int Ntry = 0;
     225retry_message:
     226  {
     227    char line[5];
     228    int Nout = read (InitSocket, line, 4);
     229    if ((Nout == -1) && (errno == EAGAIN)) {
     230      Ntry ++;
     231      if (Ntry > 500) {
     232        if (DEBUG) fprintf (stderr, "handshake failure\n");
     233        close (InitSocket);
     234        return (-1);
     235      }
     236      goto retry_message;
     237    }
     238    if (Nout != 4) {
     239      if (DEBUG) fprintf (stderr, "connection failed\n");
     240      close (InitSocket);
     241      return (-1);
     242    }
     243    if (strncmp (line, "KAPA", 4)) {
     244      if (DEBUG) fprintf (stderr, "connection to the wrong server\n");
     245      close (InitSocket);
     246      return (-1);
     247    }
    231248  }
    232249
Note: See TracChangeset for help on using the changeset viewer.