Exemplo n.º 1
0
 /**
  * Get informations about the shared worker.
  *
  * @return  array
  */
 public function getInformations()
 {
     $this->_client->connect();
     $this->_client->writeAll(Backend\Shared::pack(Backend\Shared::TYPE_INFORMATIONS, ""));
     $this->_client->read(2);
     // skip type.
     $length = unpack('Nl', $this->_client->read(4));
     $message = $this->_client->read($length['l']);
     $this->_client->read(1);
     // skip eom.
     $this->_client->disconnect();
     return unserialize($message);
 }
Exemplo n.º 2
0
 /**
  * Send a request and get a response.
  *
  * @param   \Hoa\XmlRpc\Message\Request  $message    Message.
  * @return  \Hoa\XmlRpc\Message\Response
  * @throws  \Hoa\XmlRpc\Exception\Fault
  */
 public function send(Message\Request $message)
 {
     $request = $message->__toString();
     $this->_client->writeAll($this->getHeader($request));
     $response = $this->_client->readAll();
     if (false === ($pos = strpos($response, "\r\n\r\n"))) {
         throw new Exception('Oops, an unknown error occured. Headers seem to be corrupted.', 0);
     }
     $response = substr($response, $pos + 4);
     if (0 !== preg_match('#<methodResponse>(\\s|\\n)*<fault>#i', $response)) {
         preg_match('#<(i4|int)>(?:\\s|\\n)*(\\d+)(?:\\s|\\n)*</\\1>#i', $response, $faultCodeMatches);
         preg_match('#<string>(?:\\s|\\n)*(.*)(?:\\s|\\n)*</string>#i', $response, $faultStringMatches);
         $faultCode = -1;
         $faultString = 'An ununderstable fault from the server occured.';
         if (isset($faultCodeMatches[2])) {
             $faultCode = $faultCodeMatches[2];
         }
         if (isset($faultStringMatches[1])) {
             $faultString = $faultStringMatches[1];
         }
         throw new Exception\Fault($faultString, $faultCode, $request);
     }
     return new Message\Response($response);
 }
Exemplo n.º 3
0
 /**
  * Stop the shared worker.
  *
  * @return  bool
  */
 public function stop()
 {
     $client = new Socket\Client($this->_socket);
     $client->connect();
     $client->writeAll(static::pack(static::TYPE_STOP, $this->_password));
     $client->disconnect();
     return true;
 }
Exemplo n.º 4
0
 public function case_constructor()
 {
     $this->given($socket = 'tcp://hoa-project.net:80', $timeout = 42, $flag = SUT::ASYNCHRONOUS, $context = 'foo')->when($result = new SUT($socket, $timeout, $flag, $context))->then->let($_socket = $result->getSocket())->object($_socket)->isInstanceOf('Hoa\\Socket\\Socket')->integer($_socket->getAddressType())->isEqualTo($_socket::ADDRESS_DOMAIN)->string($_socket->getTransport())->isEqualTo('tcp')->string($_socket->getAddress())->isEqualTo('hoa-project.net')->integer($_socket->getPort())->isEqualTo(80)->boolean($_socket->isSecured())->isFalse()->integer($result->getTimeout())->isEqualTo($timeout)->integer($result->getFlag())->isEqualTo($flag | SUT::CONNECT)->string($result->getContext())->isEqualTo($context);
 }