예제 #1
0
 public function __construct(int $errorCode)
 {
     parent::__construct(sprintf('UV_%s: %s', \uv_err_name($errorCode), \ucfirst(\uv_strerror($errorCode))), $errorCode);
 }
예제 #2
0
파일: UvDriver.php 프로젝트: staabm/file
 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())));
 }
예제 #3
0
파일: UvHandle.php 프로젝트: amphp/file
 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);
 }