public function handleEvent() { while (true) { $events = $this->socket->getSockOpt(ZMQ::SOCKOPT_EVENTS); $isPollIn = $events & ZMQ::POLL_IN; $isPollOut = $events & ZMQ::POLL_OUT; $hasEvents = $isPollIn || $isPollOut && $this->buffer->listening; if (!$hasEvents) { break; } if ($isPollIn) { $this->handleReadEvent(); } if ($isPollOut && $this->buffer->listening) { $this->buffer->handleWriteEvent(); } } }
/** * @test */ public function loopShouldSendQueuedMessages() { $writeListener = function () { }; $loop = $this->getMock('React\\EventLoop\\LoopInterface'); $loop->expects($this->once())->method('addWriteStream')->with($this->isType('integer'), $writeListener); $socket = $this->getMockBuilder('ZMQSocket')->disableOriginalConstructor()->getMock(); $socket->expects($this->at(0))->method('sendmulti')->with(array('foo'), \ZMQ::MODE_DONTWAIT)->will($this->returnSelf()); $socket->expects($this->at(1))->method('sendmulti')->with(array('bar'), \ZMQ::MODE_DONTWAIT)->will($this->returnSelf()); $buffer = new Buffer($socket, 42, $loop, $writeListener); $buffer->send('foo'); $buffer->send('bar'); $buffer->handleWriteEvent(); }