Example #1
0
 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())));
 }
Example #2
0
 public function close($fd, $callback)
 {
     uv_fs_close($this->getEventLoop(), $fd, $callback);
 }
Example #3
0
<?php

uv_fs_open(uv_default_loop(), "./tmp", UV::O_WRONLY, UV::S_IRWXU | UV::S_IRUSR, function ($r) {
    var_dump($r);
    uv_fs_ftruncate(uv_default_loop(), $r, 0, function () use($r) {
        uv_fs_close(uv_default_loop(), $r, function () {
        });
    });
});
uv_run();
Example #4
0
<?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();
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function close()
 {
     $this->isCloseInitialized = true;
     $this->reactor->addRef();
     $promisor = new Deferred();
     \uv_fs_close($this->loop, $this->fh, function ($fh) use($promisor) {
         $this->reactor->delRef();
         $promisor->succeed();
     });
     return $promisor->promise();
 }