diff --git a/Connection.php b/Connection.php index 394f6df..ce1e355 100644 --- a/Connection.php +++ b/Connection.php @@ -202,6 +202,7 @@ public function __construct(HoaSocket\Connection $connection) 'message', 'binary-message', 'ping', + 'close-before', 'close', 'error' ] @@ -580,13 +581,21 @@ public function close($code = self::CLOSE_NORMAL, $reason = null) $protocol = $connection->getCurrentNode()->getProtocolImplementation(); try { + $this->getListener()->fire( + 'close-before', + new Event\Bucket([ + 'code' => $code, + 'reason' => $reason + ]) + ); + if (null !== $protocol) { $protocol->close($code, $reason); } } finally { - $out = $connection->disconnect(); + $connection->disconnect(); } - return $out; + return; } } diff --git a/Test/Unit/Connection.php b/Test/Unit/Connection.php index f7fddf8..64a1e4a 100644 --- a/Test/Unit/Connection.php +++ b/Test/Unit/Connection.php @@ -121,6 +121,8 @@ public function case_constructor() ->isTrue() ->boolean($listener->listenerExists('ping')) ->isTrue() + ->boolean($listener->listenerExists('close-before')) + ->isTrue() ->boolean($listener->listenerExists('close')) ->isTrue() ->boolean($listener->listenerExists('error'))