--- ray/src/hd/rholo4.c 1997/11/03 18:33:14 3.2 +++ ray/src/hd/rholo4.c 1997/11/20 11:40:11 3.6 @@ -18,13 +18,13 @@ static char SCCSid[] = "$SunId$ SGI"; static int inp_flags; static int dpd[3]; -static int pipesiz; +static FILE *dpout; disp_open(dname) /* open the named display driver */ char *dname; { - char dpath[128], *com[2]; + char dpath[128], *com[3]; int i; #ifdef DEVPATH @@ -32,24 +32,24 @@ char *dname; #else sprintf(dpath, "dev/%s%s", dname, HDSUF); #endif - com[0] = dpath; com[1] = NULL; - pipesiz = open_process(dpd, com); - if (pipesiz <= 0) + com[0] = dpath; com[1] = froot; com[2] = NULL; + i = open_process(dpd, com); + if (i <= 0) error(USER, "cannot start display process"); + if ((dpout = fdopen(dup(dpd[1]), "w")) == NULL) + error(SYSTEM, "cannot associate FILE with display pipe"); inp_flags = 0; /* write out hologram grids */ for (i = 0; hdlist[i] != NULL; i++) disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]); + disp_flush(); } disp_packet(p) /* display a packet */ -register PACKET *p; +register PACKHEAD *p; { - if (pipesiz <= 0) - return; - disp_result(DS_BUNDLE, sizeof(PACKHEAD) + p->nr*sizeof(RAYVAL), - (char *)p); + disp_result(DS_BUNDLE, packsiz(p->nr), (char *)p); } @@ -60,9 +60,11 @@ int block; int n; char *buf = NULL; - if (pipesiz <= 0) + if (dpout == NULL) return(-1); -restart: /* check read blocking */ + /* flush display output */ + disp_flush(); + /* check read blocking */ if (block != (inp_flags == 0)) { inp_flags = block ? 0 : FNONBLK; if (fcntl(dpd[0], F_SETFL, inp_flags) < 0) @@ -75,7 +77,7 @@ restart: /* check read blocking */ error(USER, "display process died"); if (errno != EAGAIN & errno != EINTR) goto readerr; - return(2); /* else acceptable failure */ + return(2); /* acceptable failure */ } if (msg.nbytes) { /* get the message body */ buf = (char *)malloc(msg.nbytes); @@ -98,6 +100,7 @@ restart: /* check read blocking */ disp_result(DS_STARTIMM, 0, NULL); bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); disp_result(DS_ENDIMM, 0, NULL); + disp_flush(); break; case DR_ADDSET: if (msg.nbytes % sizeof(PACKHEAD)) @@ -105,6 +108,7 @@ restart: /* check read blocking */ disp_result(DS_STARTIMM, 0, NULL); bundle_set(BS_ADD, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD)); disp_result(DS_ENDIMM, 0, NULL); + disp_flush(); break; case DR_DELSET: if (msg.nbytes % sizeof(PACKHEAD)) @@ -116,8 +120,7 @@ restart: /* check read blocking */ error(INTERNAL, "bad DR_ATTEN from display process"); /* send acknowledgement */ disp_result(DS_ACKNOW, 0, NULL); - block = 1; /* block on following request */ - goto restart; + return(disp_check(1)); /* block on following request */ case DR_SHUTDOWN: if (msg.nbytes) error(INTERNAL, "bad DR_SHUTDOWN from display process"); @@ -125,7 +128,7 @@ restart: /* check read blocking */ default: error(INTERNAL, "unrecognized request from display process"); } - if (msg.nbytes) + if (msg.nbytes) /* clean up */ free(buf); return(1); /* normal return value */ fcntlerr: @@ -140,42 +143,33 @@ disp_close() /* close our display process */ { int rval; - if (pipesiz <= 0) + if (dpout == NULL) return(-1); disp_result(DS_SHUTDOWN, 0, NULL); - pipesiz = 0; + fclose(dpout); + dpout = NULL; return(close_process(dpd)); } -disp_result(type, nbytes, p) /* send result message to display process */ +disp_result(type, nbytes, p) /* queue result message to display process */ int type, nbytes; char *p; { - struct iovec iov[2]; MSGHEAD msg; - int n; + if (dpout == NULL) + return; msg.type = type; msg.nbytes = nbytes; - if (nbytes == 0 || sizeof(MSGHEAD)+nbytes > pipesiz) { - n = write(dpd[1], (char *)&msg, sizeof(MSGHEAD)); - if (n != sizeof(MSGHEAD)) - goto writerr; - if (nbytes > 0) { - n = writebuf(dpd[1], p, nbytes); - if (n != nbytes) - goto writerr; - } - return; - } - iov[0].iov_base = (char *)&msg; - iov[0].iov_len = sizeof(MSGHEAD); - iov[1].iov_base = p; - iov[1].iov_len = nbytes; - n = writev(dpd[1], iov, 2); - if (n == nbytes+sizeof(MSGHEAD)) - return; -writerr: - error(SYSTEM, "write error in disp_result"); + fwrite((char *)&msg, sizeof(MSGHEAD), 1, dpout); + if (nbytes > 0) + fwrite(p, 1, nbytes, dpout); +} + + +disp_flush() /* flush output to display */ +{ + if (fflush(dpout) < 0) + error(SYSTEM, "error writing to the display process"); }