/** * Called when the output pipe becomes writable. * * This should only be called by the event loop. * * @param \EvIo $watcher * @param integer $revents * @return void */ public function _onReceiverOutWritable(\EvIo $watcher, $revents) { // Get the first item in the response queue. $data = array_shift($this->response_queue); // Stop the watcher if the queue is empty. if (!$data) { return $watcher->stop(); } // Write the data to the output pipe. $this->pipeline->send($data . PHP_EOL); }
/** * Called whtn the child's output FIFO becomes readable to receive RPC repsonses. * * This should only be called by the event loop. * * @param \EvIo $watcher * @param integer $revents * @return void */ public function _onReceiverOutReadable(\EvIo $watcher, $revents) { // Check we're still receiving any data. while ($data = $this->pipeline->receive()) { // Check we've receieved an actual response. if (empty($data)) { continue; } $rpc_processed = unserialize($data); if (!$rpc_processed instanceof Rpc) { continue; } // Add to processed RPC queue waiting to be resolved. $this->inventory->receiveProcessed($rpc_processed); } // Stop if we have no more requests pending and there is no data incoming. if (!$this->inventory->hasWaiting()) { return $watcher->stop(); } }