=================================================================== RCS file: /home/cvs/OpenXM/src/oxc/oxc.c,v retrieving revision 1.8 retrieving revision 1.10 diff -u -p -r1.8 -r1.10 --- OpenXM/src/oxc/oxc.c 2000/12/14 03:14:01 1.8 +++ OpenXM/src/oxc/oxc.c 2000/12/16 01:52:32 1.10 @@ -1,5 +1,5 @@ /* -*- mode: C -*- */ -/* $OpenXM: OpenXM/src/oxc/oxc.c,v 1.7 2000/12/14 01:35:58 ohara Exp $ */ +/* $OpenXM: OpenXM/src/oxc/oxc.c,v 1.9 2000/12/15 03:34:43 ohara Exp $ */ #include #include @@ -34,13 +34,22 @@ int lf_oxc_open_main(char *cmd, short port) return pid; /* if error, pid == 0 */ } +#define MAX_RETRY 2000 + OXFILE *connection() { - OXFILE *oxfp = oxf_connect_active(remote_host, port); - if (oxfp != NULL) { - oxf_confirm_server(oxfp, password); - oxf_determine_byteorder_server(oxfp); + OXFILE *oxfp; + int counter = MAX_RETRY; + while((oxfp = oxf_connect_active(remote_host, port)) == NULL) { + if (--counter > 0) { + usleep(100); /* spends 100 micro seconds */ + }else { + fprintf(stderr, "oxc: cannot connect.\n"); + return NULL; + } } + oxf_confirm_server(oxfp, password); + oxf_determine_byteorder_server(oxfp); return oxfp; } @@ -78,8 +87,10 @@ int main(int argc, char *argv[]) char *myname = argv[0]; int oxlog = 0; int c; + int delay = 0; + char *delay_s = "0"; - while ((c = getopt(argc, argv, "c:p:h:x")) != -1) { + while ((c = getopt(argc, argv, "d:c:p:h:x")) != -1) { switch(c) { case 'h': remote_host = optarg; @@ -97,6 +108,10 @@ int main(int argc, char *argv[]) oxlog = 1; } break; + case 'd': + delay_s = optarg; + delay = atoi(optarg); + break; default: } } @@ -109,15 +124,13 @@ int main(int argc, char *argv[]) sprintf(port_s, "%d", port); } if (oxlog) { - execlp(xterm, xterm, "-e", myname, + execlp(xterm, xterm, "-e", myname, "-d", delay_s, "-h", remote_host, "-p", port_s, "-c", password, NULL); - fprintf(stderr, "oxc:: cannot exec \"%s oxc ...\"\n", xterm); } fprintf(stderr, "start connection!\n"); - if ((oxfp = connection()) == NULL) { - fprintf(stderr, "oxc: cannot connect.\n"); - }else { + usleep(delay); + if ((oxfp = connection()) != NULL) { fprintf(stderr, "oxc: oxfp = %p, fd = %d\n", oxfp, oxfp->fd); mathcap_init(20001006, "v2000.10.06", "oxc", basic0, NULL); sm(oxfp);