Index: trunk/Ohana/src/opihi/pcontrol/PclientCommand.c
===================================================================
--- trunk/Ohana/src/opihi/pcontrol/PclientCommand.c	(revision 17474)
+++ trunk/Ohana/src/opihi/pcontrol/PclientCommand.c	(revision 17475)
@@ -1,26 +1,19 @@
 # include "pcontrol.h"
-# define PCLIENT_TIMEOUT 20000
+# define PCLIENT_TIMEOUT 100
 
-int PclientCommand (Host *host, char *command, char *response, IOBuffer *buffer) {
+// send a command and check for errors; ignore output
+int PclientCommand (Host *host, char *command, char *response, HostResp response_state) {
 
-  int i;
   int status;
-  char *line;
-  struct timespec request, remain;
+  IOBuffer buffer;
 
   ASSERT (host != NULL, "host missing");
-  ASSERT (buffer != NULL, "buffer missing");
   ASSERT (command != NULL, "command missing");
-  ASSERT (response != NULL, "response missing");
-
-  /* avoid blocking on read, test every 100 usec, up to 2.0 sec */
-  request.tv_sec = 0;
-  request.tv_nsec = 100000;
 
   // flush the stdout and stderr buffers here
-  ReadtoIOBuffer (buffer, host[0].stdout_fd);
-  FlushIOBuffer (buffer);
-  ReadtoIOBuffer (buffer, host[0].stderr_fd);
-  FlushIOBuffer (buffer);
+  ReadtoIOBuffer (&buffer, host[0].stdout_fd);
+  FlushIOBuffer (&buffer);
+  ReadtoIOBuffer (&buffer, host[0].stderr_fd);
+  FlushIOBuffer (&buffer);
 
   /* send command to client (adding on \n) */
@@ -33,8 +26,33 @@
   }
   
+  // prepare host to accept response
+  host[0].response_state = response_state;
+  host[0].response = response;
+  FlushIOBuffer (&host[0].comms_buffer);
+
+  return (PCLIENT_GOOD);
+}
+  
+// check for response; message must end with specified string.
+// accumulate the response in the buffer
+int PclientResponse (Host *host, char *response, IOBuffer *buffer) {
+
+  int i;
+  int status;
+  char *line;
+  struct timespec request, remain;
+
+  ASSERT (response != NULL, "response missing");
+  ASSERT (buffer != NULL, "buffer missing");
+
+  /* avoid blocking very long on read, test every 100 usec, up to 0.1 sec */
+  request.tv_sec = 0;
+  request.tv_nsec = 100000;
+
   /* watch for response - wait up to 1 second */
   line = NULL;
   status = -1;
 
+  // how long does each cycle really take?
   for (i = 0; (i < PCLIENT_TIMEOUT) && (status != 0) && (line == NULL); i++) {
     status = ReadtoIOBuffer (buffer, host[0].stdout_fd);
@@ -46,8 +64,13 @@
     return (PCLIENT_DOWN);
   }
+  if (line == NULL) return (PCLIENT_HUNG);
   if (status == -1) return (PCLIENT_HUNG);
-  if (line == NULL) return (PCLIENT_HUNG);
 
   // fprintf (stderr, "buffer.buffer: %s\n", buffer[0].buffer);
+
+  // we have detected a valid response, clear the response data
+  host[0].response_state = PCONTROL_RESP_NONE;
+  host[0].response = NULL;
+
   return (PCLIENT_GOOD);
 }
