More adding of pointless crap to manager
[progcomp2012.git] / manager / program.cpp
index ea5304c..acf501e 100644 (file)
@@ -10,6 +10,7 @@
 
 using namespace std;
 
+
 /**
  * Constructor
  * @param executablePath - path to the program that will be run
@@ -21,6 +22,8 @@ using namespace std;
  */
 Program::Program(const char * executablePath) : input(NULL), output(NULL), pid(0)
 {
+       
+
        int readPipe[2]; int writePipe[2];
        assert(pipe(readPipe) == 0);
        assert(pipe(writePipe) == 0);
@@ -69,7 +72,7 @@ Program::~Program()
        if (kill(pid, 0) == 0) //Check if the process created is still running...
        {
                fputc(EOF, output); //If it was, tell it to stop with EOF
-               sleep(1); //Give it 1 second to respond...
+               usleep(500000); //Give it 1/2 a second to respond...
                if (kill(pid, 0) == 0) //Check if its still running
                {
                        kill(pid, 9); //Slay the infidel mercilessly!
@@ -88,6 +91,7 @@ Program::~Program()
  * Sends a message to the wrapped AI program
  * WARNING: Always prints a new line after the message (so don't include a new line)
  *     This is because everything is always line buffered.
+ * @returns true if the message was successfully sent; false if it was not (ie: the process was not running!)
  */
 bool Program::SendMessage(const char * print, ...)
 {
@@ -97,12 +101,15 @@ bool Program::SendMessage(const char * print, ...)
        va_list ap;
        va_start(ap, print);
 
-       vfprintf(output, print, ap);
-       fprintf(output, "\n");
-
+       if (vfprintf(output, print, ap) < 0 || fprintf(output, "\n") < 0)
+       {
+               va_end(ap);
+               return false;
+       }
+       va_end(ap);
        
 
-       va_end(ap);
+
 
        return true;
 }
@@ -161,3 +168,5 @@ bool Program::Running() const
 }
 
 
+
+

UCC git Repository :: git.ucc.asn.au