Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function disableWriteWatcher(StreamWatcher $watcher, bool $dispose = false)
 {
     if ($watcher->event === null) {
         return;
     }
     $id = (int) $watcher->event;
     unset($this->writeWatchers[$id][$watcher->id]);
     if (empty($this->writeWatchers[$id])) {
         unset($this->writeWatchers[$id]);
         if (\uv_is_active($watcher->event)) {
             \uv_poll_stop($watcher->event);
         }
         if (isset($this->readWatchers[$id])) {
             \uv_poll_start($watcher->event, \UV::READABLE, $this->streamCallback);
         }
     }
     if ($dispose) {
         try {
             if (empty($this->readWatchers[$id]) && empty($this->writeWatchers[$id])) {
                 unset($this->streamEvents[$watcher->streamId]);
                 if ($this->dispatching) {
                     $this->dispose->enqueue($watcher->event);
                 } else {
                     \uv_close($watcher->event);
                 }
             }
         } finally {
             $watcher->event = null;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function cancel(Io $io)
 {
     $id = (int) $io->getResource();
     if (isset($this->sockets[$id], $this->polls[$id]) && $io === $this->sockets[$id] && \uv_is_active($this->polls[$id])) {
         \uv_poll_stop($this->polls[$id]);
         if (isset($this->timers[$id]) && \uv_is_active($this->timers[$id])) {
             \uv_timer_stop($this->timers[$id]);
         }
     }
 }
Exemplo n.º 3
0
 private function disablePollFromWatcher($watcher)
 {
     $poll = $watcher->poll;
     $watcherId = $watcher->id;
     unset($poll->readers[$watcherId], $poll->writers[$watcherId]);
     $poll->disable[$watcherId] = $watcher;
     if ($watcher->keepAlive) {
         \uv_unref($poll->handle);
     }
     if (!($poll->readers || $poll->writers)) {
         \uv_poll_stop($poll->handle);
         return;
     }
     // If we're still here we may need to update the polling flags
     $newFlags = 0;
     if ($poll->readers) {
         $newFlags |= \UV::READABLE;
     }
     if ($poll->writers) {
         $newFlags |= \UV::WRITABLE;
     }
     if ($poll->flags != $newFlags) {
         $poll->flags = $newFlags;
         \uv_poll_start($poll->handle, $newFlags, $poll->callback);
     }
 }
Exemplo n.º 4
0
<?php

$socket = stream_socket_server("tcp://0.0.0.0:9999", $errno, $errstr);
stream_set_blocking($socket, 0);
$poll = uv_poll_init(uv_default_loop(), $socket);
uv_poll_start($poll, UV::READABLE, function ($poll, $stat, $ev, $socket) {
    echo "parent poll:\n";
    var_dump($stat);
    $conn = stream_socket_accept($socket);
    $pp = uv_poll_init(uv_default_loop(), $conn);
    uv_poll_start($pp, UV::WRITABLE, function ($poll, $stat, $ev, $conn) {
        echo "  cb";
        var_dump($stat);
        var_dump($conn);
        uv_poll_stop($poll);
        uv_fs_write(uv_default_loop(), $conn, "Hello World", -1, function ($conn, $nwrite) {
            var_dump($conn);
            fclose($conn);
        });
    });
});
uv_run();
Exemplo n.º 5
0
 public function del($fd, $flag)
 {
     $event_key = (int) $fd;
     switch ($flag) {
         case self::EV_ACCEPT:
             if (isset($this->allEvents[$event_key][self::EV_ACCEPT])) {
                 uv_poll_stop($this->allEvents[$event_key][self::EV_ACCEPT]['poll']);
             }
             unset($this->allEvents[$event_key][self::EV_ACCEPT]);
             return true;
             break;
         case self::EV_READ:
             if (isset($this->allEvents[$event_key][self::EV_READ])) {
                 uv_poll_stop($this->allEvents[$event_key][self::EV_READ]['poll']);
             }
             unset($this->allEvents[$event_key][self::EV_READ]);
             return true;
         case self::EV_WRITE:
             break;
         case self::EV_SIGNAL:
             pcntl_signal($fd, SIG_IGN);
             return true;
         case self::EV_NOINOTIFY:
             if (isset($this->allEvents[$event_key][self::EV_NOINOTIFY])) {
                 uv_poll_stop($this->allEvents[$event_key][self::EV_NOINOTIFY]['poll']);
             }
             unset($this->allEvents[$event_key][self::EV_NOINOTIFY]);
             return true;
             break;
     }
     if (empty($this->allEvents[$event_key])) {
         unset($this->allEvents[$event_key]);
     }
     return true;
 }