Skip to content

Commit

Permalink
Updated heartbeat logic
Browse files Browse the repository at this point in the history
  • Loading branch information
calcinai committed Dec 1, 2015
1 parent 3aae0fd commit 72bb9b1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public function __construct($uri, LoopInterface $loop, Resolver $resolver = null
$this->loop = $loop;
$this->resolver = $resolver;
$this->state = self::STATE_CLOSED;
$this->heartbeat_interval = null;
}

public function connect() {
Expand Down
2 changes: 1 addition & 1 deletion src/Protocol/AbstractProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function onHeartbeat(){
}

$this->client->getLoop()->addTimer($this->client->getHeartbeatInterval(), function(){
//Set a new timeout (1 sec seems reasonable)
//Set a new timeout (2 sec seems reasonable)
$this->heartbeat_timer = $this->client->getLoop()->addTimer(2, function(){
$this->stream->close();
throw new ConnectionLostException();
Expand Down
6 changes: 5 additions & 1 deletion src/Protocol/RFC6455.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ private function processUpgrade(Response $response) {
}

$this->client->setState(Client::STATE_CONNECTED);
$this->sendHeartbeat();

if($this->client->getHeartbeatInterval() !== null){
//Start the heartbeat loop
$this->onHeartbeat();
}

}

Expand Down

0 comments on commit 72bb9b1

Please sign in to comment.