Skip to content

Commit

Permalink
Some more hardening/stability fixes on client disconnect/timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
nekudo committed Mar 18, 2012
1 parent a090b81 commit f4109c2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
9 changes: 7 additions & 2 deletions server/lib/WebSocket/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ public function send($payload, $type = 'text', $masked = true)
$this->server->removeClientOnError($this);
return false;
}
return true;
}

public function close($statusCode = 1000)
Expand Down Expand Up @@ -294,13 +295,17 @@ public function close($statusCode = 1000)
$payload .= 'message violates server policy';
break;
}
$this->send($payload, 'close', false);

if($this->send($payload, 'close', false) === false)
{
return false;
}

if($this->application)
{
$this->application->onDisconnect($this);
}
fclose($this->socket);
stream_socket_shutdown($this->socket, STREAM_SHUT_RDWR);
$this->server->removeClientOnClose($this);
}

Expand Down
8 changes: 4 additions & 4 deletions server/lib/WebSocket/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public function run()

if($bytes === 0)
{
//$client->onDisconnect();
$this->removeClientOnError($client);
$client->onDisconnect();
//$this->removeClientOnError($client);
continue;
}
elseif($data === false)
Expand Down Expand Up @@ -181,7 +181,7 @@ public function removeClientOnClose($client)
{
$this->getApplication('status')->clientDisconnected($clientIp, $clientPort);
}
unset($clientId, $clientIp, $clientPort, $resource);
unset($clientId, $clientIp, $clientPort, $resource);
}

/**
Expand Down Expand Up @@ -213,7 +213,7 @@ public function removeClientOnError($client)
{
$this->getApplication('status')->clientDisconnected($clientIp, $clientPort);
}
unset($resource, $clientId, $clientIp, $clientPort);
unset($resource, $clientId, $clientIp, $clientPort);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions server/lib/WebSocket/Socket.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function writeBuffer($resource, $string)
$stringLength = strlen($string);
for($written = 0; $written < $stringLength; $written += $fwrite)
{
$fwrite = fwrite($resource, substr($string, $written));
$fwrite = fwrite($resource, substr($string, $written));
if($fwrite === false)
{
return false;
Expand All @@ -145,7 +145,7 @@ public function writeBuffer($resource, $string)
{
return false;
}
}
}
return $written;
}
}

0 comments on commit f4109c2

Please sign in to comment.