aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2016-08-04 08:32:03 +0200
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2016-08-04 08:32:03 +0200
commit934f949747f44402571f20aa886dbd43c22cbfdb (patch)
treee252a6badddcc532a7330e8971d1142d2294b9c6
parentde5e6506b6c0db10c12f633f75e7177f0b877c2b (diff)
downloadWebsocket-934f949747f44402571f20aa886dbd43c22cbfdb.zip
Websocket-934f949747f44402571f20aa886dbd43c22cbfdb.tar.gz
Websocket-934f949747f44402571f20aa886dbd43c22cbfdb.tar.bz2
Connection: If a normal close fails, no error.
When a normal close is attempted and it fails because of several reasons (it is likely to be because the client might already be disconnected and then it is not possible to send messages to it), then this situation is not considered as an error. Indeed, the client has sent a normal close but it does not listen for the confirmation from the server. This is a protocol error but happening on closing. So instead of getting an exception when closing, catching this exception later and then firing an `error` event, this makes more sense to catch the exception, do nothing with it, and fire the expected `close` event.
-rw-r--r--Connection.php22
1 files changed, 14 insertions, 8 deletions
diff --git a/Connection.php b/Connection.php
index 75899fe..96a70c6 100644
--- a/Connection.php
+++ b/Connection.php
@@ -463,14 +463,20 @@ abstract class Connection
}
}
- $this->close(self::CLOSE_NORMAL);
- $this->getListener()->fire(
- 'close',
- new Event\Bucket([
- 'code' => $code,
- 'reason' => $reason
- ])
- );
+ try {
+ $this->close(self::CLOSE_NORMAL);
+ } catch (HoaException\Idle $e) {
+ // Cannot properly close the connection because the
+ // client might already be disconnected.
+ } finally {
+ $this->getListener()->fire(
+ 'close',
+ new Event\Bucket([
+ 'code' => $code,
+ 'reason' => $reason
+ ])
+ );
+ }
break;