__socket = $g_zmqcontext->getSocket(ZMQ::SOCKET_REQ); $this->__socket->connect($uri); } function send($data, $result = null) { if (is_string($data)) { $ret = $this->__socket->send($data); } elseif (is_array($data)) { $ret = $this->__socket->send(json_encode($data)); } else { $this->__test->failure("RPC message is not a valid reply"); var_dump($data); } $this->_test->equal($this->__socket, $ret); } /** * Expect no received messages * * @param for how many millis no messages must be received */ function recvNone($for) { $endTime = (microtime(true) * 1000) + $for; while (true) { $r = $this->__socket->recv(ZMQ::MODE_NOBLOCK); $this->_test->isFalse($r); if ($r) { $this->_test->failure("Got message while expecting none"); break; } if ($endTime < (microtime(true) * 1000)) break; usleep(1000); } } function recv($classMethod, $result = [], $autoReply = false) { while (true) { $r = $this->__socket->recv(); if (!$this->__socket->getSockOpt(ZMQ::SOCKOPT_RCVMORE)) break; } $msg = $this->validateRpc($r, $classMethod); $this->_test->isTrue(isset($msg['rep'])); if (count($result)) $this->_test->equal($result, $msg['result']); if ($autoReply) $this->sendReply($msg); return $msg; } function recvError($classMethod, $expectedError) { while (true) { $r = $this->__socket->recv(); if (!$this->__socket->getSockOpt(ZMQ::SOCKOPT_RCVMORE)) break; } $msg = $this->validateRpc($r, $classMethod); if (!isset($msg['error'])) { $this->_test->errorCount++; $this->_test->failed("Error occurred, error member NOT found"); } elseif($msg['error']['code'] != $expectedError) { $this->_test->errorCount++; $this->_test->failed("Error occurred, expected code " . $expectedError . ", got " . $msg['error']['code']); } else { } return $msg; } }