public static function handleEvent(Event $event) { $messageID = $event->header['response_to']; if (!isset(self::$pendingRequests[$messageID])) { return; } $pendingRequest = self::$pendingRequests[$messageID]; $socket = $pendingRequest['socket']; if ($event->status === '_zpc_hb') { $request = new Request('_zpc_hb', array(), $messageID, $event->getMessageID()); return $socket->sendMulti($request->serialize()); } $callback = self::$pendingRequests[$messageID]['callback']; $callback($event->getContent()); unset(self::$pendingRequests[$messageID]); }
public function dispatch() { do { if (!($recv = $this->zmq->recvMulti())) { throw new SocketException('Lost remote after ' . $this->timeout . 'ms'); } if (strlen($recv[count($recv) - 2]) !== 0) { throw new SocketException('Expected second to last argument to be an empty buffer, but it is not'); } $envelope = array_slice($recv, 0, count($recv) - 2); $event = Event::deserialize($envelope, $recv[count($recv) - 1]); $channel = Channel::get($event->header['response_to']); if ($channel) { $channel->invoke($event); } } while (Channel::count() > 0); }