Пример #1
0
 /**
  * @test
  */
 public function sendShouldBufferMessages()
 {
     $loop = $this->getMock('React\\EventLoop\\LoopInterface');
     $loop->expects($this->once())->method('addWriteStream')->with(14);
     $socket = $this->getMockBuilder('ZMQSocket')->disableOriginalConstructor()->getMock();
     $socket->expects($this->any())->method('getSockOpt')->with(ZMQ::SOCKOPT_FD)->will($this->returnValue(14));
     $wrapped = new SocketWrapper($socket, $loop);
     $wrapped->send('foobar');
 }
Пример #2
0
 /**
  * @param SocketWrapper $stream
  * @param string $msgType
  * @param array $content
  * @param array $parentHeader
  * @param array $metadata
  */
 public function send(SocketWrapper $stream, $msgType, array $content = [], array $parentHeader = [], array $metadata = [])
 {
     $header = $this->createHeader($msgType);
     $msgDef = [json_encode(empty($header) ? new \stdClass() : $header), json_encode(empty($parentHeader) ? new \stdClass() : $parentHeader), json_encode(empty($metadata) ? new \stdClass() : $metadata), json_encode(empty($content) ? new \stdClass() : $content)];
     $finalMsg = array_merge(['<IDS|MSG>', $this->sign($msgDef)], $msgDef);
     if (null !== $this->logger) {
         $this->logger->debug('Sent message', ['processId' => posix_getpid(), 'message' => $finalMsg]);
     }
     $stream->send($finalMsg);
 }
Пример #3
0
 /**
  * @param Context $context
  * @param BitcoinNode $node
  * @param ScriptThreadControl $threadControl
  */
 public function __construct(Context $context, BitcoinNode $node, ScriptThreadControl $threadControl)
 {
     $cmdControl = $context->getSocket(\ZMQ::SOCKET_REP);
     $cmdControl->bind('tcp://127.0.0.1:5560');
     $cmdControl->on('message', function ($e) use($threadControl, $node) {
         $result = ['error' => 'Unrecognized command'];
         if ($e === 'shutdown') {
             $threadControl->shutdown();
             $result = $this->onShutdown($threadControl);
         } elseif ($e === 'info') {
             $result = $this->onInfo($node);
         }
         $this->socket->send(json_encode($result, JSON_PRETTY_PRINT));
         if ($e === 'shutdown') {
             $node->stop();
         }
     });
     $this->socket = $cmdControl;
 }
Пример #4
0
 /**
  * @param array $result
  * @return bool
  */
 private function respond(array $result)
 {
     $this->socket->send(json_encode($result, JSON_PRETTY_PRINT));
     return true;
 }
Пример #5
0
 /**
  * @param string $subject
  * @param array $params
  */
 public function log($subject, array $params = [])
 {
     $this->socket->send(json_encode(['event' => $subject, 'params' => $params]));
 }