public function start()
 {
     $this->onStart();
     $this->base = new EventBase();
     if ($this->_server) {
         $this->event = new EventListener($this->base, array($this, "accept"), $this->base, EventListener::OPT_CLOSE_ON_FREE | EventListener::OPT_REUSEABLE, -1, $this->_server);
         //EventListener($this->base, array($this, "accept"), null, EventListener::OPT_CLOSE_ON_FREE | EventListener::OPT_REUSEABLE, -1, $this->_server);
     }
     if ($this->_service) {
         $this->service_event = new EventListener($this->base, array($this, "service"), $this->base, EventListener::OPT_CLOSE_ON_FREE | EventListener::OPT_REUSEABLE, -1, $this->_service);
         //EventListener($this->base, array($this, "accept"), null, EventListener::OPT_CLOSE_ON_FREE | EventListener::OPT_REUSEABLE, -1, $this->_server);
     }
     if ($this->_master) {
         $connectionId = $this->getIdByConnection($this->_master);
         $buffer = new EventBufferEvent($this->base, $this->_master, EventBufferEvent::OPT_CLOSE_ON_FREE);
         $buffer->setCallbacks(array($this, "onRead"), array($this, "onWrite"), array($this, "onError"), $connectionId);
         $buffer->enable(Event::READ | Event::WRITE | Event::PERSIST);
         $this->buffers[$connectionId] = $buffer;
     }
     if ($this->timer) {
         $timer = Event::timer($this->base, function () use(&$timer) {
             $timer->addTimer($this->timer);
             $this->onTimer();
         });
         $timer->addTimer($this->timer);
     }
     $this->base->dispatch();
 }
Example #2
0
function retry_connect($base)
{
    echo "\nretry connect...\n\n";
    global $timer;
    if ($timer) {
        $timer->del();
    }
    $timer = Event::timer($base, 'connect_dest', $base);
    $timer->addTimer(1);
}
Example #3
0
 /**
  * Constructor
  * @param  callable       $cb       Callback
  * @param  integer        $timeout  Timeout
  * @param  integer|string $id       Timer ID
  * @param  integer        $priority Priority
  */
 public function __construct($cb, $timeout = null, $id = null, $priority = null)
 {
     if ($id === null) {
         $id = ++self::$counter;
     } else {
         $id = (string) $id;
     }
     $this->id = $id;
     $this->cb = $cb;
     $this->ev = \Event::timer(Daemon::$process->eventBase, [$this, 'eventCall']);
     if ($priority !== null) {
         $this->setPriority($priority);
     }
     if ($timeout !== null) {
         $this->timeout($timeout);
     }
     self::$list[$id] = $this;
 }
Example #4
0
 /**
  * 创建一个定时器 
  * 
  * @param int $interval 
  * @access protected
  * @return void
  */
 protected function _create_timer($interval)
 {
     $this->__event_timer[$interval] = \Event::timer($this->__event_base, array($this, 'callback'), $interval);
     if (false === $this->__event_timer[$interval]) {
         $log = "create event timer faild, interval: {$interval}.";
         $this->log($log, LOG_WARNING);
         throw new sw_exception($log);
     }
     $this->__event_timer[$interval]->add($interval);
     $log = "create a event timer success, interval: {$interval}.";
     $this->log($log, LOG_DEBUG);
 }
Example #5
0
 /**
  * @param array ...$args
  * @return mixed
  */
 public function timer(...$args)
 {
     return \Event::timer($this->base, ...$args);
 }
Example #6
0
function timer()
{
    global $base, $ev;
    $ev = Event::timer($base, 'display', 'libo');
    $ev->addTimer(3);
}