ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/common/process.c
Revision: 2.10
Committed: Fri Apr 3 17:06:16 2020 UTC (4 years ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad5R3
Changes since 2.9: +1 -3 lines
Log Message:
Added input ray queue for more efficient batch processing

File Contents

# Content
1 #ifndef lint
2 static const char RCSid[] = "$Id: process.c,v 2.9 2020/02/28 05:18:49 greg Exp $";
3 #endif
4 /*
5 * Routines to communicate with separate process via dual pipes
6 *
7 * External symbols declared in standard.h
8 */
9
10 #include "copyright.h"
11
12 #include "rtprocess.h"
13
14 /*
15
16 The functions open_process() and close_process() exist in
17 (currently) two versions, which are found in the files:
18
19 win_process.c
20 unix_process.c
21
22 */
23
24 int
25 process( /* process data through pd */
26 SUBPROC *pd,
27 char *recvbuf, char *sendbuf,
28 int nbr, int nbs
29 )
30 {
31 if (!(pd->flags & PF_RUNNING))
32 return(-1);
33 if (writebuf(pd->w, sendbuf, nbs) < nbs)
34 return(-1);
35 return(readbuf(pd->r, recvbuf, nbr));
36 }
37
38
39
40 int
41 readbuf( /* read all of requested buffer */
42 int fd,
43 char *bpos,
44 int siz
45 )
46 {
47 int cc = 0, nrem = siz;
48 retry:
49 while (nrem > 0 && (cc = read(fd, bpos, nrem)) > 0) {
50 bpos += cc;
51 nrem -= cc;
52 }
53 if (cc < 0) {
54 #ifndef BSD
55 if (errno == EINTR) /* we were interrupted! */
56 goto retry;
57 #endif
58 return(cc);
59 }
60 return(siz-nrem);
61 }
62
63
64 int
65 writebuf( /* write all of requested buffer */
66 int fd,
67 char *bpos,
68 int siz
69 )
70 {
71 int cc = 0, nrem = siz;
72 retry:
73 while (nrem > 0 && (cc = write(fd, bpos, nrem)) > 0) {
74 bpos += cc;
75 nrem -= cc;
76 }
77 if (cc < 0) {
78 #ifndef BSD
79 if (errno == EINTR) /* we were interrupted! */
80 goto retry;
81 #endif
82 return(cc);
83 }
84 return(siz-nrem);
85 }