Esempio n. 1
0
 /**
  * @param \Icicle\Loop\UvLoop $loop
  * @param int $eventType
  */
 public function __construct(UvLoop $loop, int $eventType)
 {
     $this->loopHandle = $loop->getLoopHandle();
     $this->type = $eventType;
     $this->pollCallback = function ($poll, int $status, int $events, $resource) {
         $id = (int) $resource;
         switch ($status) {
             case 0:
                 // OK
                 break;
                 // If $status is a severe error, stop the poll and throw an exception.
             // If $status is a severe error, stop the poll and throw an exception.
             case \UV::EACCES:
             case \UV::EBADF:
             case \UV::EINVAL:
             case \UV::ENOTSOCK:
                 \uv_poll_stop($poll);
                 if (isset($this->timers[$id]) && \uv_is_active($this->timers[$id])) {
                     \uv_timer_stop($this->timers[$id]);
                 }
                 throw new UvException($status);
             default:
                 // Ignore other (probably) trivial warnings and continuing polling.
                 return;
         }
         if ($this->sockets[$id]->isPersistent()) {
             if (isset($this->timers[$id]) && \uv_is_active($this->timers[$id])) {
                 \uv_timer_stop($this->timers[$id]);
                 \uv_timer_again($this->timers[$id]);
             }
         } else {
             \uv_poll_stop($poll);
             if (isset($this->timers[$id]) && \uv_is_active($this->timers[$id])) {
                 \uv_timer_stop($this->timers[$id]);
             }
         }
         $this->sockets[$id]->call(false);
     };
     $this->timerCallback = function ($timer) {
         $id = $this->handles[(int) $timer];
         \uv_timer_stop($timer);
         if (\uv_is_active($this->polls[$id])) {
             \uv_poll_stop($this->polls[$id]);
             $this->sockets[$id]->call(true);
         }
     };
 }
Esempio n. 2
0
 /**
  * @param \Icicle\Loop\UvLoop $loop
  */
 public function __construct(UvLoop $loop)
 {
     $this->loopHandle = $loop->getLoopHandle();
     $this->timers = new ObjectStorage();
     $this->callback = function ($handle) {
         $id = (int) $handle;
         if (!isset($this->handles[$id])) {
             return;
         }
         $timer = $this->handles[$id];
         if (!$timer->isPeriodic()) {
             \uv_close($this->timers[$timer]);
             unset($this->timers[$timer]);
             unset($this->handles[$id]);
         }
         $timer->call();
     };
 }