Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
walkor committed Sep 16, 2015
1 parent 7fb397d commit 70b29be
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Engine/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Engine extends Emitter
{
public $pingTimeout = 60;
public $pingInterval = 25;
public $upgradeTimeout = 10;
public $upgradeTimeout = 5;
public $transports = array();
public $allowUpgrades = array();
public $allowRequest = array();
Expand Down
20 changes: 14 additions & 6 deletions src/Engine/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ public function onUpgradePacket($packet)
if('ping' === $packet['type'] && (isset($packet['data']) && 'probe' === $packet['data']))
{
$this->upgradeTransport->send(array(array('type'=> 'pong', 'data'=> 'probe')));
//$this->transport->shouldClose = function(){};
Timer::del($this->checkIntervalTimer);
$this->checkIntervalTimer = Timer::add(0.1, array($this, 'check'));
}
else if ('upgrade' === $packet['type'] && $this->readyState !== 'closed')
else if('upgrade' === $packet['type'] && $this->readyState !== 'closed')
{
$this->cleanup();
$this->upgraded = true;
Expand All @@ -81,6 +82,7 @@ public function onUpgradePacket($packet)

}


public function cleanup()
{
Timer::del($this->checkIntervalTimer);
Expand Down Expand Up @@ -108,7 +110,7 @@ public function upgradeTimeoutCallback($transport)
{
echo("client did not complete upgrade - closing transport\n");
$this->cleanup();
if('open' == $transport->readyState)
if('open' === $transport->readyState)
{
$transport->close();
}
Expand Down Expand Up @@ -192,7 +194,13 @@ public function setPingTimeout()
Timer::del($this->pingTimeoutTimer);
$this->pingTimeoutTimer = Timer::add(
$this->server->pingInterval + $this->server->pingTimeout ,
array($this, 'onClose'), null, false);
array($this, 'pingTimeoutCallback'), null, false);
}

public function pingTimeoutCallback()
{
$this->transport->close();
$this->onClose('ping timeout');
}


Expand All @@ -204,7 +212,7 @@ public function clearTransport()

public function onClose($reason = '', $description = null)
{
if ('closed' != $this->readyState) {
if ('closed' !== $this->readyState) {
Timer::del($this->pingTimeoutTimer);
Timer::del($this->checkIntervalTimer);
$this->checkIntervalTimer = null;
Expand Down Expand Up @@ -263,7 +271,7 @@ public function sendPacket($type, $data = null, $callback = null)

public function flush()
{
if ('closed' != $this->readyState && $this->transport->writable
if ('closed' !== $this->readyState && $this->transport->writable
&& $this->writeBuffer)
{
$this->emit('flush', $this->writeBuffer);
Expand Down Expand Up @@ -296,7 +304,7 @@ public function getAvailableUpgrades()

public function close()
{
if ('open' != $this->readyState)
if ('open' !== $this->readyState)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/SocketIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class_alias('PHPSocketIO\Engine\Protocols\SocketIO', 'Protocols\SocketIO');
public function path($v = null)
{
if($v === null) return $this->_path;
$this->_path = str_replace('/\/$/', '', $v);
$this->_path = preg_replace('/\/$/', '', $v);
return $this;
}

Expand Down

0 comments on commit 70b29be

Please sign in to comment.