Example #1
0
 public static function cancelCurrentTimeoutTimer()
 {
     if (static::$timeoutTimer !== null) {
         static::$timeoutTimer->cancel();
         static::$timeoutTimer = null;
     }
 }
Example #2
0
 protected function stopRouter()
 {
     $this->assertInstanceOf('Thruway\\Peer\\Router', $this->router);
     $this->assertInstanceOf('React\\EventLoop\\Timer\\Timer', $this->currentTimer);
     $this->currentTimer->cancel();
     $this->router->stop(false);
 }
Example #3
0
 public function onHeartbeat()
 {
     if (isset($this->heartbeat_timer)) {
         $this->heartbeat_timer->cancel();
     }
     $this->client->getLoop()->addTimer($this->client->getHeartbeatInterval(), function () {
         //Set a new timeout (2 sec seems reasonable)
         $this->heartbeat_timer = $this->client->getLoop()->addTimer(2, function () {
             $this->stream->close();
             throw new ConnectionLostException();
         });
         $this->sendHeartbeat();
     });
 }
Example #4
0
 /**
  * Disconnects client from server.
  *
  * Calling disconnect() multiple times or if client is not connected will result in error.
  *
  * @param int $replyCode
  * @param string $replyText
  * @return Promise\PromiseInterface
  */
 public function disconnect($replyCode = 0, $replyText = "")
 {
     if ($this->state !== ClientStateEnum::CONNECTED) {
         return Promise\reject(new ClientException("Client is not connected."));
     }
     $this->state = ClientStateEnum::DISCONNECTING;
     $promises = [];
     if ($replyCode === 0) {
         foreach ($this->channels as $channel) {
             $promises[] = $channel->close();
         }
     }
     if ($this->heartbeatTimer) {
         $this->heartbeatTimer->cancel();
         $this->heartbeatTimer = null;
     }
     return Promise\all($promises)->then(function () use($replyCode, $replyText) {
         return $this->connectionClose($replyCode, $replyText, 0, 0);
     })->then(function () {
         $this->eventLoop->removeReadStream($this->getStream());
         $this->closeStream();
         $this->init();
         return $this;
     });
 }