Changeset 17475 for trunk/Ohana/src/opihi/pcontrol/PclientCommand.c
- Timestamp:
- Apr 23, 2008, 11:35:39 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/pcontrol/PclientCommand.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/pcontrol/PclientCommand.c
r17474 r17475 1 1 # include "pcontrol.h" 2 # define PCLIENT_TIMEOUT 200002 # 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; 8 IOBuffer buffer; 10 9 11 10 ASSERT (host != NULL, "host missing"); 12 ASSERT (buffer != NULL, "buffer missing");13 11 ASSERT (command != NULL, "command missing"); 14 ASSERT (response != NULL, "response missing");15 16 /* avoid blocking on read, test every 100 usec, up to 2.0 sec */17 request.tv_sec = 0;18 request.tv_nsec = 100000;19 12 20 13 // 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);14 ReadtoIOBuffer (&buffer, host[0].stdout_fd); 15 FlushIOBuffer (&buffer); 16 ReadtoIOBuffer (&buffer, host[0].stderr_fd); 17 FlushIOBuffer (&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 return (PCLIENT_GOOD); 34 } 35 36 // check for response; message must end with specified string. 37 // accumulate the response in the buffer 38 int PclientResponse (Host *host, char *response, IOBuffer *buffer) { 39 40 int i; 41 int status; 42 char *line; 43 struct timespec request, remain; 44 45 ASSERT (response != NULL, "response missing"); 46 ASSERT (buffer != NULL, "buffer missing"); 47 48 /* avoid blocking very long on read, test every 100 usec, up to 0.1 sec */ 49 request.tv_sec = 0; 50 request.tv_nsec = 100000; 51 35 52 /* watch for response - wait up to 1 second */ 36 53 line = NULL; 37 54 status = -1; 38 55 56 // how long does each cycle really take? 39 57 for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (line == NULL); i++) { 40 58 status = ReadtoIOBuffer (buffer, host[0].stdout_fd); … … 46 64 return (PCLIENT_DOWN); 47 65 } 66 if (line == NULL) return (PCLIENT_HUNG); 48 67 if (status == -1) return (PCLIENT_HUNG); 49 if (line == NULL) return (PCLIENT_HUNG);50 68 51 69 // fprintf (stderr, "buffer.buffer: %s\n", buffer[0].buffer); 70 71 // we have detected a valid response, clear the response data 72 host[0].response_state = PCONTROL_RESP_NONE; 73 host[0].response = NULL; 74 52 75 return (PCLIENT_GOOD); 53 76 }
Note:
See TracChangeset
for help on using the changeset viewer.
