diff --git a/README.md b/README.md index 2fc31025..1f0aa7d1 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ and [`Stream`](https://github.com/reactphp/stream) components. * [error event](#error-event) * [listen()](#listen) * [getPort()](#getport) - * [shutdown()](#shutdown) + * [close()](#close) * [Server](#server) * [SecureServer](#secureserver) * [ConnectionInterface](#connectioninterface) @@ -146,22 +146,22 @@ echo 'Server listening on port ' . $port . PHP_EOL; ``` This method MUST NOT be called before calling [`listen()`](#listen). -This method MUST NOT be called after calling [`shutdown()`](#shutdown). +This method MUST NOT be called after calling [`close()`](#close). -#### shutdown() +#### close() -The `shutdown(): void` method can be used to +The `close(): void` method can be used to shut down this listening socket. This will stop listening for new incoming connections on this socket. ```php echo 'Shutting down server socket' . PHP_EOL; -$server->shutdown(); +$server->close(); ``` This method MUST NOT be called before calling [`listen()`](#listen). -This method MUST NOT be called after calling [`shutdown()`](#shutdown). +This method MUST NOT be called after calling [`close()`](#close). ### Server diff --git a/src/SecureServer.php b/src/SecureServer.php index df30b03f..17607d27 100644 --- a/src/SecureServer.php +++ b/src/SecureServer.php @@ -78,9 +78,9 @@ public function getPort() return $this->tcp->getPort(); } - public function shutdown() + public function close() { - return $this->tcp->shutdown(); + return $this->tcp->close(); } /** @internal */ diff --git a/src/Server.php b/src/Server.php index a8674f02..06e998dc 100644 --- a/src/Server.php +++ b/src/Server.php @@ -88,7 +88,7 @@ public function getPort() return (int) substr(strrchr($name, ':'), 1); } - public function shutdown() + public function close() { $this->loop->removeStream($this->master); fclose($this->master); diff --git a/src/ServerInterface.php b/src/ServerInterface.php index b90448f0..3fe135ee 100644 --- a/src/ServerInterface.php +++ b/src/ServerInterface.php @@ -72,7 +72,7 @@ public function listen($port, $host = '127.0.0.1'); * Returns the port this server is currently listening on * * This method MUST NOT be called before calling listen(). - * This method MUST NOT be called after calling shutdown(). + * This method MUST NOT be called after calling close(). * * @return int the port number */ @@ -84,9 +84,9 @@ public function getPort(); * This will stop listening for new incoming connections on this socket. * * This method MUST NOT be called before calling listen(). - * This method MUST NOT be called after calling shutdown(). + * This method MUST NOT be called after calling close(). * * @return void */ - public function shutdown(); + public function close(); } diff --git a/tests/SecureServerTest.php b/tests/SecureServerTest.php index 9278483a..2b8f2395 100644 --- a/tests/SecureServerTest.php +++ b/tests/SecureServerTest.php @@ -25,15 +25,15 @@ public function testGetPortWillBePassedThroughToTcpServer() $this->assertEquals(1234, $server->getPort()); } - public function testShutdownWillBePassedThroughToTcpServer() + public function testCloseWillBePassedThroughToTcpServer() { $tcp = $this->getMockBuilder('React\Socket\Server')->disableOriginalConstructor()->getMock(); - $tcp->expects($this->once())->method('shutdown'); + $tcp->expects($this->once())->method('close'); $loop = $this->getMock('React\EventLoop\LoopInterface'); $server = new SecureServer($tcp, $loop, array()); - $server->shutdown(); + $server->close(); } } diff --git a/tests/ServerTest.php b/tests/ServerTest.php index e8f3cfbd..aefe3a9f 100644 --- a/tests/ServerTest.php +++ b/tests/ServerTest.php @@ -132,27 +132,27 @@ public function testDataWillBeFragmentedToBufferSize() $this->loop->tick(); } - public function testLoopWillEndWhenServerIsShutDown() + public function testLoopWillEndWhenServerIsClosed() { - // explicitly unset server because we already call shutdown() - $this->server->shutdown(); + // explicitly unset server because we already call close() + $this->server->close(); $this->server = null; $this->loop->run(); } - public function testLoopWillEndWhenServerIsShutDownAfterSingleConnection() + public function testLoopWillEndWhenServerIsClosedAfterSingleConnection() { $client = stream_socket_client('tcp://localhost:' . $this->port); // explicitly unset server because we only accept a single connection - // and then already call shutdown() + // and then already call close() $server = $this->server; $this->server = null; $server->on('connection', function ($conn) use ($server) { $conn->close(); - $server->shutdown(); + $server->close(); }); $this->loop->run(); @@ -169,7 +169,7 @@ public function testDataWillBeEmittedInMultipleChunksWhenClientSendsExcessiveAmo $mock = $this->expectCallableOnce(); // explicitly unset server because we only accept a single connection - // and then already call shutdown() + // and then already call close() $server = $this->server; $this->server = null; @@ -183,7 +183,7 @@ public function testDataWillBeEmittedInMultipleChunksWhenClientSendsExcessiveAmo $conn->on('end', $mock); // do not await any further connections in order to let the loop terminate - $server->shutdown(); + $server->close(); }); $this->loop->run(); @@ -236,12 +236,12 @@ public function testListenOnBusyPortThrows() } /** - * @covers React\Socket\Server::shutdown + * @covers React\Socket\Server::close */ public function tearDown() { if ($this->server) { - $this->server->shutdown(); + $this->server->close(); } } } diff --git a/tests/Stub/ServerStub.php b/tests/Stub/ServerStub.php index 98fe4e3f..2bc2f5aa 100644 --- a/tests/Stub/ServerStub.php +++ b/tests/Stub/ServerStub.php @@ -16,7 +16,7 @@ public function getPort() return 80; } - public function shutdown() + public function close() { } }