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