aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMetalaka <matthieu.de.laubrie@gmail.com>2017-03-30 21:37:26 +0200
committerMetalaka <matthieu.de.laubrie@gmail.com>2017-03-30 21:58:47 +0200
commitbead328cef0a7df0d4aa201f509a8368d253cdc7 (patch)
treeb9bd27690ffd855cb885192ed4e754579975c429
parent834b4abf8cad9d1ba4035c2f29f12eb29f2d3e6e (diff)
downloadWebsocket-bead328cef0a7df0d4aa201f509a8368d253cdc7.zip
Websocket-bead328cef0a7df0d4aa201f509a8368d253cdc7.tar.gz
Websocket-bead328cef0a7df0d4aa201f509a8368d253cdc7.tar.bz2
Connection: Add `close-before` event.
-rw-r--r--Connection.php29
-rw-r--r--Test/Unit/Connection.php2
2 files changed, 18 insertions, 13 deletions
diff --git a/Connection.php b/Connection.php
index 71525f2..ce1e355 100644
--- a/Connection.php
+++ b/Connection.php
@@ -202,6 +202,7 @@ abstract class Connection
'message',
'binary-message',
'ping',
+ 'close-before',
'close',
'error'
]
@@ -464,6 +465,11 @@ 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([
@@ -471,22 +477,11 @@ 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) {
@@ -586,13 +581,21 @@ abstract class Connection
$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 @@ class Connection extends Test\Unit\Suite
->isTrue()
->boolean($listener->listenerExists('ping'))
->isTrue()
+ ->boolean($listener->listenerExists('close-before'))
+ ->isTrue()
->boolean($listener->listenerExists('close'))
->isTrue()
->boolean($listener->listenerExists('error'))