aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjmdevince <james@hexhost.net>2016-04-28 15:15:33 -0500
committerMetalaka <matthieu.de.laubrie@gmail.com>2017-03-30 21:44:28 +0200
commit834b4abf8cad9d1ba4035c2f29f12eb29f2d3e6e (patch)
tree883849c7d32018021560b6b83322615cef63a3d1
parentc018385af6ae303bdf65a8073c9bf60257eb80f8 (diff)
downloadWebsocket-834b4abf8cad9d1ba4035c2f29f12eb29f2d3e6e.zip
Websocket-834b4abf8cad9d1ba4035c2f29f12eb29f2d3e6e.tar.gz
Websocket-834b4abf8cad9d1ba4035c2f29f12eb29f2d3e6e.tar.bz2
Fire close event before closing and on error
Firing the close event before closing allows for the user to grab the connection's unique ID. This is useful if the user is keeping track of connection based states across the lifecycle of a connection (e.g. session data). Fire the event on a protocol error as well before closing.
-rw-r--r--Connection.php16
1 files changed, 11 insertions, 5 deletions
diff --git a/Connection.php b/Connection.php
index 394f6df..71525f2 100644
--- a/Connection.php
+++ b/Connection.php
@@ -464,11 +464,6 @@ abstract class Connection
}
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([
@@ -476,11 +471,22 @@ abstract class Connection
'reason' => $reason
])
);
+ $this->close(self::CLOSE_NORMAL);
+ } catch (HoaException\Idle $e) {
+ // Cannot properly close the connection because the
+ // client might already be disconnected.
}
break;
default:
+ $this->getListener()->fire(
+ 'close',
+ new Event\Bucket([
+ 'code' =>self::CLOSE_PROTOCOL_ERROR,
+ 'reason' => null
+ ])
+ );
$this->close(self::CLOSE_PROTOCOL_ERROR);
}
} catch (HoaException\Idle $e) {