ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/rholo4.c
(Generate patch)

Comparing ray/src/hd/rholo4.c (file contents):
Revision 3.3 by gregl, Tue Nov 4 09:58:24 1997 UTC vs.
Revision 3.8 by gregl, Wed Nov 26 20:14:43 1997 UTC

# Line 18 | Line 18 | static char SCCSid[] = "$SunId$ SGI";
18  
19   static int      inp_flags;
20   static int      dpd[3];
21 < static int      pipesiz;
21 > static FILE     *dpout;
22  
23  
24   disp_open(dname)                /* open the named display driver */
25   char    *dname;
26   {
27 <        char    dpath[128], *com[2];
27 >        char    dpath[128], *com[3];
28          int     i;
29  
30   #ifdef DEVPATH
# Line 32 | Line 32 | char   *dname;
32   #else
33          sprintf(dpath, "dev/%s%s", dname, HDSUF);
34   #endif
35 <        com[0] = dpath; com[1] = NULL;
36 <        pipesiz = open_process(dpd, com);
37 <        if (pipesiz <= 0)
35 >        com[0] = dpath; com[1] = froot; com[2] = NULL;
36 >        i = open_process(dpd, com);
37 >        if (i <= 0)
38                  error(USER, "cannot start display process");
39 +        if ((dpout = fdopen(dup(dpd[1]), "w")) == NULL)
40 +                error(SYSTEM, "cannot associate FILE with display pipe");
41          inp_flags = 0;
42                                  /* write out hologram grids */
43          for (i = 0; hdlist[i] != NULL; i++)
44                  disp_result(DS_ADDHOLO, sizeof(HDGRID), (char *)hdlist[i]);
45 +        disp_flush();
46   }
47  
48  
49   disp_packet(p)                  /* display a packet */
50 < register PACKET *p;
50 > register PACKHEAD       *p;
51   {
52 <        disp_result(DS_BUNDLE, sizeof(PACKHEAD) + p->nr*sizeof(RAYVAL),
50 <                        (char *)p);
52 >        disp_result(DS_BUNDLE, packsiz(p->nr), (char *)p);
53   }
54  
55  
# Line 58 | Line 60 | int    block;
60          int     n;
61          char    *buf = NULL;
62  
63 <        if (pipesiz <= 0)
63 >        if (dpout == NULL)
64                  return(-1);
65 +                                        /* flush display output */
66 +        disp_flush();
67                                          /* check read blocking */
68          if (block != (inp_flags == 0)) {
69                  inp_flags = block ? 0 : FNONBLK;
# Line 96 | Line 100 | int    block;
100                  disp_result(DS_STARTIMM, 0, NULL);
101                  bundle_set(BS_NEW, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
102                  disp_result(DS_ENDIMM, 0, NULL);
103 +                disp_flush();
104                  break;
105          case DR_ADDSET:
106                  if (msg.nbytes % sizeof(PACKHEAD))
# Line 103 | Line 108 | int    block;
108                  disp_result(DS_STARTIMM, 0, NULL);
109                  bundle_set(BS_ADD, (PACKHEAD *)buf, msg.nbytes/sizeof(PACKHEAD));
110                  disp_result(DS_ENDIMM, 0, NULL);
111 +                disp_check(0);          /* hack -- delete usu. follows add */
112                  break;
113          case DR_DELSET:
114                  if (msg.nbytes % sizeof(PACKHEAD))
# Line 119 | Line 125 | int    block;
125                  if (msg.nbytes)
126                          error(INTERNAL, "bad DR_SHUTDOWN from display process");
127                  return(0);              /* zero return signals shutdown */
128 +        case DR_NOOP:
129 +                break;
130          default:
131                  error(INTERNAL, "unrecognized request from display process");
132          }
# Line 137 | Line 145 | disp_close()                   /* close our display process */
145   {
146          int     rval;
147  
148 <        if (pipesiz <= 0)
148 >        if (dpout == NULL)
149                  return(-1);
150          disp_result(DS_SHUTDOWN, 0, NULL);
151 <        pipesiz = 0;
151 >        fclose(dpout);
152 >        dpout = NULL;
153          return(close_process(dpd));
154   }
155  
156  
157 < disp_result(type, nbytes, p)    /* send result message to display process */
157 > disp_result(type, nbytes, p)    /* queue result message to display process */
158   int     type, nbytes;
159   char    *p;
160   {
152        struct iovec    iov[2];
161          MSGHEAD msg;
154        int     n;
162  
163 <        if (pipesiz <= 0)
163 >        if (dpout == NULL)
164                  return;
165          msg.type = type;
166          msg.nbytes = nbytes;
167 <        if (nbytes == 0 || sizeof(MSGHEAD)+nbytes > pipesiz) {
168 <                do
169 <                        n = write(dpd[1], (char *)&msg, sizeof(MSGHEAD));
170 <                while (n < 0 && errno == EINTR);
171 <                if (n != sizeof(MSGHEAD))
172 <                        goto writerr;
173 <                if (nbytes > 0) {
174 <                        n = writebuf(dpd[1], p, nbytes);
175 <                        if (n != nbytes)
176 <                                goto writerr;
170 <                }
171 <                return;
172 <        }
173 <        iov[0].iov_base = (char *)&msg;
174 <        iov[0].iov_len = sizeof(MSGHEAD);
175 <        iov[1].iov_base = p;
176 <        iov[1].iov_len = nbytes;
177 <        do
178 <                n = writev(dpd[1], iov, 2);
179 <        while (n < 0 && errno == EINTR);
180 <        if (n == sizeof(MSGHEAD)+nbytes)
181 <                return;
182 < writerr:
183 <        error(SYSTEM, "write error in disp_result");
167 >        fwrite((char *)&msg, sizeof(MSGHEAD), 1, dpout);
168 >        if (nbytes > 0)
169 >                fwrite(p, 1, nbytes, dpout);
170 > }
171 >
172 >
173 > disp_flush()                    /* flush output to display */
174 > {
175 >        if (fflush(dpout) < 0)
176 >                error(SYSTEM, "error writing to the display process");
177   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines