FreeCalypso > hg > freecalypso-tools
comparison loadtools/tpinterfb.c @ 649:141372e0d28f
fc-loadtool module refactoring: tpinterfb.c split out
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 02 Mar 2020 02:45:35 +0000 |
parents | |
children | 8d7dcfd9df53 |
comparison
equal
deleted
inserted
replaced
648:3229940734e5 | 649:141372e0d28f |
---|---|
1 /* | |
2 * This module contains functions for binary (as opposed to our usual ASCII) | |
3 * interfacing to loadagent. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <sys/time.h> | |
8 #include <sys/errno.h> | |
9 #include <stdio.h> | |
10 #include <string.h> | |
11 #include <strings.h> | |
12 #include <stdlib.h> | |
13 | |
14 extern int errno; | |
15 | |
16 extern int target_fd; | |
17 | |
18 collect_binblock_from_target(buf, expect_len, timeout) | |
19 u_char *buf; | |
20 unsigned expect_len; | |
21 { | |
22 fd_set fds; | |
23 struct timeval tv; | |
24 unsigned rcvd; | |
25 int cc; | |
26 | |
27 for (rcvd = 0; rcvd < expect_len; ) { | |
28 FD_ZERO(&fds); | |
29 FD_SET(target_fd, &fds); | |
30 tv.tv_sec = timeout; | |
31 tv.tv_usec = 0; | |
32 cc = select(target_fd+1, &fds, NULL, NULL, &tv); | |
33 if (cc < 0) { | |
34 if (errno == EINTR) | |
35 continue; | |
36 perror("select"); | |
37 return(-1); | |
38 } | |
39 if (cc < 1) { | |
40 fprintf(stderr, | |
41 "error: timeout waiting for binary block\n"); | |
42 return(-1); | |
43 } | |
44 cc = read(target_fd, buf + rcvd, expect_len - rcvd); | |
45 if (cc <= 0) { | |
46 perror("read after successful select"); | |
47 return(-1); | |
48 } | |
49 rcvd += cc; | |
50 } | |
51 return(0); | |
52 } |