Ejemplo n.º 1
0
 /**
  * @param   \Icicle\Loop\EvLoop $loop
  * @param   \Icicle\Loop\Events\EventFactoryInterface $factory
  */
 public function __construct(EvLoop $loop, EventFactoryInterface $factory)
 {
     $this->factory = $factory;
     $this->loop = $loop->getEvLoop();
     $this->timers = new ObjectStorage();
     $this->callback = function (\EvTimer $event) {
         /** @var \Icicle\Loop\Events\TimerInterface $timer */
         $timer = $event->data;
         if (!$timer->isPeriodic()) {
             $event->stop();
             unset($this->timers[$timer]);
         } else {
             $event->again();
         }
         $timer->call();
     };
 }
Ejemplo n.º 2
0
 /**
  * @param bool $enableSignals True to enable signal handling, false to disable.
  *
  * @return \Icicle\Loop\LoopInterface
  *
  * @codeCoverageIgnore
  */
 function create(bool $enableSignals = true) : LoopInterface
 {
     if (EvLoop::enabled()) {
         return new EvLoop($enableSignals);
     }
     if (EventLoop::enabled()) {
         return new EventLoop($enableSignals);
     }
     if (LibeventLoop::enabled()) {
         return new LibeventLoop($enableSignals);
     }
     return new SelectLoop($enableSignals);
 }
Ejemplo n.º 3
0
 /**
  * @param \Icicle\Loop\EvLoop $loop
  * @param \Icicle\Loop\Events\EventFactoryInterface $factory
  * @param int $eventType
  */
 public function __construct(EvLoop $loop, EventFactoryInterface $factory, int $eventType)
 {
     $this->factory = $factory;
     $this->loop = $loop->getEvLoop();
     $this->type = $eventType;
     $this->socketCallback = function (\EvIO $event) {
         /** @var \Icicle\Loop\Events\SocketEventInterface $socket */
         $socket = $event->data;
         $id = (int) $socket->getResource();
         $event->stop();
         if (isset($this->timers[$id])) {
             $this->timers[$id]->stop();
         }
         $socket->call(false);
     };
     $this->timerCallback = function (\EvTimer $event) {
         /** @var \Icicle\Loop\Events\SocketEventInterface $socket */
         $socket = $event->data;
         $id = (int) $socket->getResource();
         $event->stop();
         $this->events[$id]->stop();
         $socket->call(true);
     };
 }
Ejemplo n.º 4
0
 /**
  * Calls loopFork() on the EvLoop object.
  */
 public function reInit()
 {
     $this->loop->loopFork();
 }