- Timestamp:
- Jul 3, 2008, 10:26:51 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080421/Ohana/src/opihi/pcontrol/PclientCommand.c
r16590 r18424 1 1 # include "pcontrol.h" 2 # define PCLIENT_TIMEOUT 50002 # define PCLIENT_TIMEOUT 100 3 3 4 int PclientCommand (Host *host, char *command, char *response, IOBuffer *buffer) { 4 // send a command and check for errors; ignore output 5 int PclientCommand (Host *host, char *command, char *response, HostResp response_state) { 5 6 6 int i;7 7 int status; 8 char *line;9 struct timespec request, remain;10 8 11 9 ASSERT (host != NULL, "host missing"); 12 ASSERT (buffer != NULL, "buffer missing");13 10 ASSERT (command != NULL, "command missing"); 14 ASSERT (response != NULL, "response missing");15 16 /* avoid blocking on read, test every 100 usec, up to 50 msec */17 request.tv_sec = 0;18 request.tv_nsec = 100000;19 11 20 12 // flush the stdout and stderr buffers here 21 ReadtoIOBuffer (buffer, host[0].stdout_fd); 22 FlushIOBuffer (buffer); 23 ReadtoIOBuffer (buffer, host[0].stderr_fd); 24 FlushIOBuffer (buffer); 13 // recycle comms_buffer to minimize page thrashing 14 ReadtoIOBuffer (&host[0].comms_buffer, host[0].stdout_fd); 15 FlushIOBuffer (&host[0].comms_buffer); 16 ReadtoIOBuffer (&host[0].comms_buffer, host[0].stderr_fd); 17 FlushIOBuffer (&host[0].comms_buffer); 25 18 26 19 /* send command to client (adding on \n) */ … … 33 26 } 34 27 28 // prepare host to accept response 29 host[0].response_state = response_state; 30 host[0].response = response; 31 FlushIOBuffer (&host[0].comms_buffer); 32 33 // fprintf (stderr, "command: %s\n", command); 34 35 return (PCLIENT_GOOD); 36 } 37 38 // check for response; message must end with specified string. 39 // accumulate the response in the buffer 40 int PclientResponse (Host *host, char *response, IOBuffer *buffer) { 41 42 int i; 43 int status; 44 char *line; 45 struct timespec request, remain; 46 47 ASSERT (response != NULL, "response missing"); 48 ASSERT (buffer != NULL, "buffer missing"); 49 50 /* avoid blocking very long on read, test every 100 usec, up to 0.1 sec */ 51 request.tv_sec = 0; 52 request.tv_nsec = 100000; 53 35 54 /* watch for response - wait up to 1 second */ 36 55 line = NULL; 37 56 status = -1; 57 58 // how long does each cycle really take? 38 59 for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (line == NULL); i++) { 39 60 status = ReadtoIOBuffer (buffer, host[0].stdout_fd); … … 45 66 return (PCLIENT_DOWN); 46 67 } 68 if (line == NULL) return (PCLIENT_HUNG); 47 69 if (status == -1) return (PCLIENT_HUNG); 48 /* gprint (GP_ERR, "buffer.buffer: %s\n", buffer[0].buffer); */ 70 71 // fprintf (stderr, "response: %s\n", buffer[0].buffer); 72 49 73 return (PCLIENT_GOOD); 50 74 } 51 75 52 76 /* memstr returns a view, not an allocated string : don't free */ 77 /* ReadtoIOBuffer returns : 78 0 - pipe closed 79 -1 - no more data in pipe, data not ready 80 -2 - serious error reading from pipe 81 >0 - data read from pipe 82 */
Note:
See TracChangeset
for help on using the changeset viewer.
