Skip to content

Commit

Permalink
Fix #105: Quickly unload the client when closed by remote
Browse files Browse the repository at this point in the history
  • Loading branch information
bwoebi committed Dec 22, 2016
1 parent 5066f71 commit de8bc2f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/Websocket/Rfc6455Endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private function doClose(Rfc6455Client $client, int $code, string $reason): \Gen
$promise = $this->sendCloseFrame($client, $code, $reason);
yield from $this->tryAppOnClose($client->id, $code, $reason);
return $promise;
// Don't unload the client here, it will be unloaded upon timeout
// Don't unload the client here, it will be unloaded upon timeout or last data written if closed by client or OP_CLOSE received by client
}

private function sendCloseFrame(Rfc6455Client $client, $code, $msg): Promise {
Expand Down Expand Up @@ -507,11 +507,16 @@ public function onWritable($watcherId, $socket, Rfc6455Client $client) {
}

} elseif ($client->closedAt) {
@stream_socket_shutdown($socket, STREAM_SHUT_WR);
\Amp\cancel($watcherId);
$client->writeWatcher = null;
$client->writeDeferred = null;
$client->writeBuffer = "";
$client->writeDeferred = null;
if ($client->readWatcher) { // readWatcher exists == we are still waiting for an OP_CLOSE frame
@stream_socket_shutdown($socket, STREAM_SHUT_WR);
\Amp\cancel($watcherId);
$client->writeWatcher = null;
} else {
unset($this->closeTimeouts[$client->id]);
$this->unloadClient($client);
}
} elseif ($client->writeDataQueue) {
$key = key($client->writeDataQueue);
$client->writeBuffer = $client->writeDataQueue[$key];
Expand Down

0 comments on commit de8bc2f

Please sign in to comment.