private function doFsRead($fh, $offset, $len) { $promisor = new Deferred(); \uv_fs_read($this->loop, $fh, $offset, $len, function ($fh, $nread, $buffer) use($promisor) { $promisor->succeed($nread < 0 ? false : $buffer); }); return $promisor->promise(); }
<?php uv_fs_open(uv_default_loop(), __FILE__, UV::O_RDONLY, 0, function ($r) { uv_fs_read(uv_default_loop(), $r, function ($stream, $nread, $data) { if ($nread <= 0) { if ($nread < 0) { throw new Exception("read error"); } uv_fs_close(uv_default_loop(), $stream, function () { }); } else { echo $data; } }); }); uv_run();
public function read($fd, $callback) { uv_fs_read($this->getEventLoop(), $fd, $callback); }
private function doRead($op) { $this->reactor->addRef(); $onRead = function ($fh, $result, $buffer) use($op) { $this->isActive = false; $this->reactor->delRef(); if ($result < 0) { $op->promisor->fail(new FilesystemException(\uv_strerror($result))); } else { $this->position = $op->position + strlen($buffer); $op->promisor->succeed($buffer); } if ($this->queue) { $this->dequeue(); } }; \uv_fs_read($this->loop, $this->fh, $op->position, $op->readLen, $onRead); }