IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 37042


Ignore:
Timestamp:
Jul 17, 2014, 10:15:41 AM (12 years ago)
Author:
eugene
Message:

better handling for slow links

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libkapa/src/KapaOpen.c

    r36833 r37042  
    11# include "kapa_internal.h"
     2
     3// kapa connection timeout is N_RETRY * 10000 usec
     4# define N_RETRY 2000
    25
    36# define MY_PORT 2500
     
    912static int *VALID = NULL;
    1013
    11 char *_parse_nextword (char *string);
    1214int KapaLaunchCommand (char *line);
    1315
     
    283285  }
    284286
    285 # define NTRY 1000
     287  INITTIME;
     288
    286289  Ntry = 0;
    287   while (Ntry < NTRY) {
     290  while (Ntry < N_RETRY) {
    288291    sock = KapaClientSocket ("localhost");
    289292    if (sock != -1) break;
     
    308311  }
    309312
    310   if (sock < 0) return (-1);
     313  if (sock < 0) {
     314    MARKTIME ("failed to connect to kapa after %f seconds\n", dtime);
     315    int killStatus = kill (pid, SIGKILL);
     316    if (killStatus) {
     317      perror ("failed to kill process");
     318    }
     319    int waitStatus = waitpid (pid, NULL, 0);
     320    if (waitStatus == pid) {
     321      fprintf (stderr, "harvested process %d\n", pid);
     322    } else if (waitStatus < 0) {
     323      fprintf (stderr, "failed to harvest process %d\n", pid);
     324    } else if (waitStatus == 0) {
     325      fprintf (stderr, "process not exited: %d\n", pid);
     326    } else {
     327      fprintf (stderr, "odd exit status: %d vs pid %d\n", waitStatus, pid);
     328    }
     329    return (-1);
     330  }
     331
    311332  return (sock);
    312333}
     
    350371  fcntl (InitSocket, F_SETFL, O_NONBLOCK);
    351372
    352 # define NTRY 1000
     373  INITTIME;
     374
    353375  Ntry = 0;
    354   while (Ntry < NTRY) {
     376  while (Ntry < N_RETRY) {
    355377    fd = accept (InitSocket, (struct sockaddr *)&Address, &AddressLength);
    356378    if (fd != -1) break;
     
    372394  }
    373395
    374   if (fd < 0) return (-1);
     396  if (fd < 0) {
     397    MARKTIME ("failed to connect to kapa after %f seconds\n", dtime);
     398    kill (pid, SIGKILL);
     399    waitpid (pid, NULL, WNOHANG);
     400    return (-1);
     401  }
    375402
    376403  // the client uses a BLOCKing socket by default
     
    414441  done = FALSE;
    415442  while (!done) {
    416     q = _parse_nextword (p);
     443    q = parse_nextword (p);
    417444    if (q && *q) {
    418445      argv[i] = strncreate (p, q - p);
Note: See TracChangeset for help on using the changeset viewer.