IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 3, 2008, 10:26:51 PM (18 years ago)
Author:
eugene
Message:

updates from HEAD

File:
1 edited

Legend:

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

    r16590 r18424  
    11# include "pcontrol.h"
    2 # define PCLIENT_TIMEOUT 5000
     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;
    108
    119  ASSERT (host != NULL, "host missing");
    12   ASSERT (buffer != NULL, "buffer missing");
    1310  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;
    1911
    2012  // 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);
    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  // 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
     40int 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
    3554  /* watch for response - wait up to 1 second */
    3655  line = NULL;
    3756  status = -1;
     57
     58  // how long does each cycle really take?
    3859  for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (line == NULL); i++) {
    3960    status = ReadtoIOBuffer (buffer, host[0].stdout_fd);
     
    4566    return (PCLIENT_DOWN);
    4667  }
     68  if (line == NULL) return (PCLIENT_HUNG);
    4769  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
    4973  return (PCLIENT_GOOD);
    5074}
    5175
    5276/* 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.