IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 23, 2008, 11:35:39 AM (18 years ago)
Author:
eugene
Message:

split out client command from client response; allow response to return slowly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/pcontrol/PclientCommand.c

    r17474 r17475  
    11# include "pcontrol.h"
    2 # define PCLIENT_TIMEOUT 20000
     2# define PCLIENT_TIMEOUT 100
    33
    4 int PclientCommand (Host *host, char *command, char *response, IOBuffer *buffer) {
     4// send a command and check for errors; ignore output
     5int PclientCommand (Host *host, char *command, char *response, HostResp response_state) {
    56
    6   int i;
    77  int status;
    8   char *line;
    9   struct timespec request, remain;
     8  IOBuffer buffer;
    109
    1110  ASSERT (host != NULL, "host missing");
    12   ASSERT (buffer != NULL, "buffer missing");
    1311  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;
    1912
    2013  // 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);
    2518
    2619  /* send command to client (adding on \n) */
     
    3326  }
    3427 
     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
     38int 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
    3552  /* watch for response - wait up to 1 second */
    3653  line = NULL;
    3754  status = -1;
    3855
     56  // how long does each cycle really take?
    3957  for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (line == NULL); i++) {
    4058    status = ReadtoIOBuffer (buffer, host[0].stdout_fd);
     
    4664    return (PCLIENT_DOWN);
    4765  }
     66  if (line == NULL) return (PCLIENT_HUNG);
    4867  if (status == -1) return (PCLIENT_HUNG);
    49   if (line == NULL) return (PCLIENT_HUNG);
    5068
    5169  // 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
    5275  return (PCLIENT_GOOD);
    5376}
Note: See TracChangeset for help on using the changeset viewer.