public function handleWriteEvent()
{
foreach ($this->messages as $i => $message) {
try {
$message = (array) $message;
$sent = (bool) $this->socket->sendmulti($message, ZMQ::MODE_DONTWAIT);
unset($this->messages[$i]);
if (0 === count($this->messages)) {
$this->loop->removeWriteStream($this->fd);
$this->listening = false;
$this->emit('end');
}
} catch (ZMQSocketException $ex) {
$this->emit('error', [$ex]);
}
}
}
/** * Handle ZMQ Event. */ public function handleEvent() { while ($this->socket !== null) { $events = $this->socket->getSockOpt(ZMQ::SOCKOPT_EVENTS); $hasEvents = $events & ZMQ::POLL_IN || $events & ZMQ::POLL_OUT && $this->buffer->listening; if (!$hasEvents) { break; } if ($events & ZMQ::POLL_IN) { $this->handleReadEvent(); } if ($events & ZMQ::POLL_OUT && $this->buffer->listening) { $this->buffer->handleWriteEvent(); } } }