Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/SecureServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion src/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/ServerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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();
}
6 changes: 3 additions & 3 deletions tests/SecureServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
20 changes: 10 additions & 10 deletions tests/ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;

Expand All @@ -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();
Expand Down Expand Up @@ -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();
}
}
}
2 changes: 1 addition & 1 deletion tests/Stub/ServerStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function getPort()
return 80;
}

public function shutdown()
public function close()
{
}
}