public function __construct(int $errorCode) { parent::__construct(sprintf('UV_%s: %s', \uv_err_name($errorCode), \ucfirst(\uv_strerror($errorCode))), $errorCode); }
private function doPut($path, $contents) : \Generator { $flags = \UV::O_WRONLY | \UV::O_CREAT; $mode = \UV::S_IRWXU | \UV::S_IRUSR; $this->reactor->addRef(); $promise = $this->doFsOpen($path, $flags, $mode); if (!($fh = (yield $promise))) { $this->reactor->delRef(); throw new \RuntimeException("Failed opening write file handle"); } $promisor = new Deferred(); $len = strlen($contents); \uv_fs_write($this->loop, $fh, $contents, $offset = 0, function ($fh, $result) use($promisor, $len) { \uv_fs_close($this->loop, $fh, function () use($promisor, $result, $len) { $this->reactor->delRef(); if ($result < 0) { $promisor->fail(new \RuntimeException(uv_strerror($result))); } else { $promisor->succeed($len); } }); }); (yield new \Amp\CoroutineResult((yield $promisor->promise()))); }
private function doWrite($op) { $this->reactor->addRef(); $onWrite = function ($fh, $result) use($op) { $this->isActive = false; $this->reactor->delRef(); if ($result < 0) { $op->promisor->fail(new FilesystemException(\uv_strerror($result))); } else { StatCache::clear($this->path); $bytesWritten = \strlen($op->writeData); $this->pendingWriteOps--; $newPosition = $op->position + $bytesWritten; $delta = $newPosition - $this->position; $this->position = $this->mode[0] === "a" ? $this->position : $newPosition; $this->size += $delta; $op->promisor->succeed($result); } if ($this->queue) { $this->dequeue(); } }; \uv_fs_write($this->loop, $this->fh, $op->writeData, $op->position, $onWrite); }