isnecure send/receive now works... next, secure master
authorpaulr <me@pjr.cc>
Tue, 22 Mar 2011 16:43:58 +0000 (03:43 +1100)
committerpaulr <me@pjr.cc>
Tue, 22 Mar 2011 16:43:58 +0000 (03:43 +1100)
lib/interComms.php
unittests/commrecv.php
unittests/commsend.php

index 69680ad..980a557 100644 (file)
@@ -161,12 +161,17 @@ class netCom {
                $continue = true;
                while($continue) {
                        // wait for a message
-                       $msg = unserialize($this->receiveMessageInternal($socket));
+                       $msg_s = $this->receiveMessageInternal($socket);
+                       if(!$msg_s) {
+                               echo "Connection handler dieing 1\n";
+                               return false;
+                       }
+                       $msg = unserialize($msg_s);
                        $retmsg = $callback($msg);
                        $retval = $this->sendMessageInternal(serialize($retmsg), $socket);
                        if(!$retval) {
-                               echo "Connection handler dieing\n";
-                               $continue = false;
+                               echo "Connection handler dieing 2\n";
+                               return false;
                        }
                }
        }
@@ -187,7 +192,8 @@ class netCom {
        
        function sendMessageInsecure($data)
        {
-               $returned = $this->sendMessageInternal(serialize($data), $this->socket);
+               $this->sendMessageInternal(serialize($data), $this->socket);
+               $returned = $this->receiveMessageInternal($this->socket);
                
                return unserialize($returned);
        }
@@ -199,7 +205,10 @@ class netCom {
                $tosend = "PEN:$datacomp:INE";
                
                $retval = socket_send($comsock, $tosend, strlen($tosend), 0);
-               if(!$retval) return false;
+               if(!$retval) {
+                       echo "in smi, retval false\n";
+                       return false;
+               }
                echo "end send message $retval\n";
                // get up to one meg of data - this is bad... i can feel this function
                // hurting alot
@@ -211,8 +220,10 @@ class netCom {
                if($recv != "PEN:ACK:INE") {
                        echo "invalid response?\n$recv\n";
                } else {
-                       echo "got ack\n";
+                       echo "smi got ack\n";
                }
+               
+               return true;
        }
        
        function receiveMessageInternal($comsock)
@@ -223,6 +234,10 @@ class netCom {
                while($continue) {
                        $size = socket_recv($comsock, $recvd_a, 1024, 0);
                        
+                       if($size === false) {
+                               echo "recevie in rmi was false\n";
+                               return false;
+                       }
                        $recvd .= $recvd_a;
                        echo "got $recvd_a so far for $size\n";
                        if($size == 0) return false;
index 000ecef..9a36482 100644 (file)
@@ -3,9 +3,9 @@ require_once("../lib/lib.php");
 
 function myfunction($msg)
 {
-       echo "got a msg\n";
+       echo "myfunction got a msg\n";
        print_r($msg);
-       echo "end message\n";
+       echo "myfunction end message\n";
        $returnmsg["0"] = "asdf";
        
        return $returnmsg; 
index c37256b..cdd8e4e 100644 (file)
@@ -9,6 +9,5 @@ $array["other"] = "moogie";
 for($i = 0; $i < 10; $i++) {
        $array["bl"] = $i;
        $mn->sendMessage($array);
-       sleep(1);
 }
 ?>
\ No newline at end of file