Annotation of OpenXM/src/gnuplot/plot.c.diff, Revision 1.3
1.3 ! ohara 1: $OpenXM: OpenXM/src/gnuplot/plot.c.diff,v 1.2 2000/02/01 10:24:12 maekawa Exp $
1.1 maekawa 2:
1.3 ! ohara 3: *** plot.c.orig Sat Jan 22 23:15:59 2000
! 4: --- plot.c Tue Mar 21 03:41:44 2000
! 5: ***************
! 6: *** 42,47 ****
! 7: --- 42,64 ----
! 8: #include "fnproto.h"
! 9: #include <setjmp.h>
! 10:
! 11: + /* TAKAYAMA Nobuki */
! 12: + #include <sys/types.h>
! 13: + #include <sys/socket.h>
! 14: + #include <sys/time.h>
! 15: + #include <netinet/in.h>
! 16: + #include <netdb.h>
! 17: +
! 18: + FILE *openTCP __P((char *));
! 19: +
! 20: + int socketConnect __P((char *, int));
! 21: + int socketOpen __P((char *, int));
! 22: + int socketAccept __P((int));
! 23: +
! 24: + int oxSocketSelect0 __P((int, int));
! 25: + int oxSocketMultiSelect __P((int *, int, int, int *));
! 26: + /* END */
! 27: +
! 28: #if defined(MSDOS) || defined(DOS386) || defined(__EMX__)
! 29: # include <io.h>
! 30: #endif
! 31: ***************
! 32: *** 321,326 ****
! 33: --- 338,344 ----
! 34: int argc;
! 35: char **argv;
! 36: {
! 37: + FILE *fp;
! 38: #ifdef LINUXVGA
! 39: LINUX_setup();
! 40: #endif
! 41: ***************
! 42: *** 527,534 ****
! 43:
! 44: /* interactive = FALSE; */ /* should this be here? */
! 45:
! 46: ! } else
! 47: ! load_file(fopen(*argv, "r"), *argv, FALSE);
! 48: }
! 49: #ifdef _Windows
! 50: if (noend) {
! 51: --- 545,556 ----
! 52:
! 53: /* interactive = FALSE; */ /* should this be here? */
! 54:
! 55: ! } else {
! 56: ! fp = openTCP(*argv);
! 57: ! load_file(fp, *argv, FALSE);
! 58: ! fprintf(stderr, "gnuplot : EOF or there was an error"
! 59: ! "in the input stream.\n");
! 60: ! }
! 61: }
! 62: #ifdef _Windows
! 63: if (noend) {
! 64: ***************
! 65: *** 725,727 ****
! 66: --- 747,1053 ----
! 67: return 0;
! 68: }
! 69: #endif
! 70: +
! 71: + /*
! 72: + * TAKAYAMA Nobuki
! 73: + */
! 74: + FILE *
! 75: + openTCP(name)
! 76: + char *name;
! 77: + {
! 78: + FILE *fp;
! 79: + int fd, port, reverse = 0;
! 80: +
! 81: + fprintf(stderr, "openTCP port number : %s\n", name);
! 82: +
! 83: + if (name[0] == 'r') {
! 84: + fprintf(stderr, "openTCP : trying to reverse connetion.\n");
! 85: + reverse = 1;
! 86: + sscanf(&name[1], "%d", &port);
! 87: + } else {
! 88: + sscanf(name, "%d", &port);
! 89: + }
! 90: +
! 91: + if (reverse) {
! 92: + fd = socketConnect("localhost", port);
! 93: + fprintf(stderr, "socketConnect is succeded: fd = %d.", fd);
! 94: + } else {
! 95: + fprintf(stderr, "Port number is %d.\n", port);
! 96: + fd = socketOpen("localhost", port);
! 97: + fprintf(stderr, "socketOpen is succeded: fd = %d.", fd);
! 98: + fd = socketAccept(fd);
! 99: + }
! 100: +
! 101: + fprintf(stderr, "\n Port %d : Connected.\n", port);
! 102: + fp = fdopen(fd, "r");
! 103: +
! 104: + return(fp);
! 105: + }
! 106: +
! 107: + #define READBUFSIZE 10000
! 108: +
! 109: + int OpenedSocket = 0, Quiet = 0;
! 110: +
! 111: + int
! 112: + socketConnect(serverName, portNumber)
! 113: + char *serverName;
! 114: + int portNumber;
! 115: + {
! 116: + struct hostent *servhost;
! 117: + struct sockaddr_in serv;
! 118: + int socketid, on;
! 119: +
! 120: + if ((servhost = gethostbyname(serverName)) == NULL) {
! 121: + fprintf(stderr, "Bad server name.\n\n");
! 122: + return (-1);
! 123: + }
! 124: +
! 125: + bzero((void *)&serv, sizeof(serv));
! 126: + serv.sin_family = AF_INET;
! 127: + serv.sin_port = htons(portNumber);
! 128: + bcopy(servhost->h_addr, (void *)&serv.sin_addr, servhost->h_length);
! 129: +
! 130: + if ((socketid = socket(AF_INET, SOCK_STREAM, 0)) <0) {
! 131: + fprintf(stderr, "Socket allocation is failed.\n\n");
! 132: + return (-1);
! 133: + }
! 134: +
! 135: + #if 0 /* XXX */
! 136: + on = 1;
! 137: + setsockopt(socketid, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
! 138: + #endif
! 139: +
! 140: + if (!Quiet) {
! 141: + fprintf(stderr, "Trying to connect port %d, ip=%x\n",
! 142: + ntohs(serv.sin_port), serv.sin_addr);
! 143: + }
! 144: +
! 145: + if (connect(socketid, (struct sockaddr *)&serv, sizeof(serv)) == -1) {
! 146: + fprintf(stderr, "cannot connect\n");
! 147: + return (-1);
! 148: + }
! 149: +
! 150: + if (!Quiet)
! 151: + fprintf(stderr, "connected.\n");
! 152: +
! 153: + return(socketid);
! 154: + }
! 155: +
! 156: + int
! 157: + socketOpen(serverName, portNumber)
! 158: + char *serverName;
! 159: + int portNumber;
! 160: + {
! 161: + static struct hostent *servhost;
! 162: + static struct sockaddr_in serv;
! 163: + static int s_wait;
! 164: + static int on;
! 165: + extern int errno;
! 166: + int tt;
! 167: +
! 168: + fprintf(stderr, "Hello from open. serverName is %s "
! 169: + "and portNumber is %d\n", serverName, portNumber);
! 170: +
! 171: + if ((servhost = gethostbyname(serverName)) == NULL) {
! 172: + fprintf(stderr, "Bad server name.\n");
! 173: + return (-1);
! 174: + }
! 175: +
! 176: + bzero((void *)&serv, sizeof(serv));
! 177: + serv.sin_family = AF_INET;
! 178: + serv.sin_port = htons(portNumber);
! 179: + bcopy(servhost->h_addr, &serv.sin_addr, servhost->h_length);
! 180: +
! 181: + if ((s_wait = socket(AF_INET,SOCK_STREAM, 0)) < 0) {
! 182: + fprintf(stderr, "Socket allocation is failed.\n");
! 183: + return (-1);
! 184: + }
! 185: +
! 186: + on = 1;
! 187: + setsockopt(s_wait, SOL_SOCKET,SO_REUSEADDR, &on, sizeof(on));
! 188: +
! 189: + /* important */
! 190: + if ((tt = bind(s_wait, (struct sockaddr *)&serv, sizeof(serv))) == -1) {
! 191: + fprintf(stderr, "bind error. Error no is %d. "
! 192: + "See /usr/include/sys/errno.h. "
! 193: + "(asm/errno.h)\n", errno);
! 194: + fprintf(stderr, "cannot bind\n");
! 195: + return (-1);
! 196: + }
! 197: +
! 198: + #if 0 /* XXX */
! 199: + printf("bind returns %d\n", tt);
! 200: + #endif
! 201: +
! 202: + tt = sizeof(serv);
! 203: + if (getsockname(s_wait, (struct sockaddr *)&serv, &tt) < 0) {
! 204: + fprintf(stderr, "getsockname error. Error no is %d. "
! 205: + "See /usr/include/sys/errno.h "
! 206: + "(asm/errno.h).\n", errno);
! 207: + fprintf(stderr, "cannot getsockname\n");
! 208: + return (-1);
! 209: + }
! 210: +
! 211: + if (listen(s_wait, 1) < 0) {
! 212: + fprintf(stderr, "Listen failed\n");
! 213: + return (-1);
! 214: + }
! 215: +
! 216: + fprintf(stderr, "Done the initialization. "
! 217: + "port =%d\n", ntohs(serv.sin_port));
! 218: + OpenedSocket = ntohs(serv.sin_port);
! 219: +
! 220: + return (s_wait);
! 221: + }
! 222: +
! 223: + int
! 224: + socketAccept(snum)
! 225: + int snum;
! 226: + {
! 227: + int s, news;
! 228: +
! 229: + s = snum;
! 230: +
! 231: + fprintf(stderr, "Trying to accept... ");
! 232: + fflush(stderr);
! 233: +
! 234: + if ((news = accept(s, NULL, NULL)) < 0) {
! 235: + fprintf(stderr, "Error in accept.\n");
! 236: + return (-1);
! 237: + }
! 238: +
! 239: + fprintf(stderr, "Accepted.\n");
! 240: + fflush(stderr);
! 241: +
! 242: + if (close(s) < 0) {
! 243: + fprintf(stderr, "Error in closing the old socket.\n");
! 244: + return (-1);
! 245: + }
! 246: +
! 247: + return(news);
! 248: + }
! 249: +
! 250: + int
! 251: + oxSocketSelect0(fd, t)
! 252: + int fd, t;
! 253: + {
! 254: + fd_set readfds;
! 255: + struct timeval timeout;
! 256: + int debug = 0;
! 257: + extern int errno;
! 258: +
! 259: + FD_ZERO(&readfds);
! 260: + FD_SET(fd, &readfds);
! 261: + timeout.tv_sec = 0;
! 262: + timeout.tv_usec = (long)t;
! 263: +
! 264: + if (t >= 0) {
! 265: + if (debug) {
! 266: + printf("select t >= 0 for fd = %d\n", fd);
! 267: + fflush(NULL);
! 268: + }
! 269: +
! 270: + /* It must be fd + 1!, Not fd. */
! 271: + if (select(fd + 1, &readfds, NULL, NULL, &timeout) < 0) {
! 272: + fprintf(stderr, "select (non-block) error. "
! 273: + "Error no is %d. "
! 274: + "See /usr/include/sys/errno.h "
! 275: + "(asm/errno.h).\n", errno);
! 276: + fprintf(stderr, "oxSocketSelect0() : select failed.\n");
! 277: + return (0);
! 278: + }
! 279: +
! 280: + if (debug) {
! 281: + printf("Return from select t >= 0 for fd = %d\n", fd);
! 282: + fflush(NULL);
! 283: + }
! 284: + } else {
! 285: + /* block */
! 286: + if (select(fd + 1, &readfds, NULL, NULL, NULL) < 0) {
! 287: + fprintf(stderr, "select (block) error. "
! 288: + "Error no is %d. "
! 289: + "See /usr/include/sys/errno.h "
! 290: + "(asm/errno.h).\n", errno);
! 291: + fprintf(stderr, "socketSelect0() : select failed.\n");
! 292: + return (0);
! 293: + }
! 294: + }
! 295: +
! 296: + if (FD_ISSET(fd, &readfds)) {
! 297: + return(1);
! 298: + } else {
! 299: + return(0);
! 300: + }
! 301: + }
! 302: +
! 303: + int
! 304: + oxSocketMultiSelect(sid, size, t, result)
! 305: + int sid[], size, t, result[];
! 306: + {
! 307: + fd_set readfds;
! 308: + struct timeval timeout;
! 309: + int i, fd, p, isdata = 0;
! 310: + extern int errno;
! 311: +
! 312: + FD_ZERO(&readfds);
! 313: + timeout.tv_sec = 0;
! 314: + timeout.tv_usec = (long)t;
! 315: +
! 316: + fd = 0;
! 317: +
! 318: + for (i = 0 ; i < size ; i++) {
! 319: + if (sid[i] >= 0) {
! 320: + p = sid[i];
! 321: + if (p > fd)
! 322: + fd = p;
! 323: + FD_SET(p,&readfds);
! 324: + #if 0 /* XXX */
! 325: + printf("p = %d, fd=%d", p, fd);
! 326: + #endif
! 327: + }
! 328: + }
! 329: +
! 330: + #if 0 /* XXX */
! 331: + printf("MultiSelect..\n");
! 332: + fflush(NULL);
! 333: + #endif
! 334: +
! 335: + if (t >= 0) {
! 336: + /* It must be fd + 1!, Not fd. */
! 337: + if (select(fd + 1, &readfds, NULL, NULL, &timeout) < 0) {
! 338: + fprintf(stderr, "Select error. Error no is %d. "
! 339: + "See /usr/include/sys/errno.h "
! 340: + "(asm/errno.h).\n", errno);
! 341: + fprintf(stderr, "oxSocketMultiSelect() : "
! 342: + "select failed.\n");
! 343: + return (0);
! 344: + }
! 345: + } else {
! 346: + /* block */
! 347: + if (select(fd + 1, &readfds, NULL, NULL, NULL) < 0) {
! 348: + fprintf(stderr, "Select error. Error no is %d. "
! 349: + "See /usr/include/sys/errno.h "
! 350: + "(asm/errno.h).\n", errno);
! 351: + fprintf(stderr, "oxSocketMultiSelect() : "
! 352: + "(block) select failed.\n");
! 353: + return (0);
! 354: + }
! 355: + }
! 356: +
! 357: + #if 0 /* XXX */
! 358: + printf("Done. MultiSelect.\n");
! 359: + fflush(NULL);
! 360: + #endif
! 361: +
! 362: + for (i = 0 ; i < size ; i++) {
! 363: + p = sid[i];
! 364: + if ((sid[i] >= 0) && FD_ISSET(p, &readfds)) {
! 365: + result[i] = 1;
! 366: + isdata = 1;
! 367: + } else {
! 368: + result[i] = 0;
! 369: + }
! 370: + }
! 371: +
! 372: + return (isdata);
! 373: + }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>