Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Server to TcpServer #96

Merged
merged 1 commit into from
Apr 25, 2017
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
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ handle multiple concurrent connections without blocking.
* [pause()](#pause)
* [resume()](#resume)
* [close()](#close)
* [Server](#server)
* [TcpServer](#tcpserver)
* [SecureServer](#secureserver)
* [LimitingServer](#limitingserver)
* [getConnections()](#getconnections)
Expand All @@ -55,7 +55,7 @@ Here is a server that closes the connection if you send it anything:
```php
$loop = React\EventLoop\Factory::create();

$socket = new React\Socket\Server(8080, $loop);
$socket = new React\Socket\TcpServer(8080, $loop);
$socket->on('connection', function (ConnectionInterface $conn) {
$conn->write("Hello " . $conn->getRemoteAddress() . "!\n");
$conn->write("Welcome to this amazing server!\n");
Expand Down Expand Up @@ -173,7 +173,7 @@ Otherwise, it will return the full local address as a string value.

This method complements the [`getRemoteAddress()`](#getremoteaddress) method,
so they should not be confused.
If your `Server` instance is listening on multiple interfaces (e.g. using
If your `TcpServer` instance is listening on multiple interfaces (e.g. using
the address `0.0.0.0`), you can use this method to find out which interface
actually accepted this connection (such as a public or local interface).

Expand Down Expand Up @@ -319,13 +319,13 @@ $server->close();

Calling this method more than once on the same instance is a NO-OP.

### Server
### TcpServer

The `Server` class implements the [`ServerInterface`](#serverinterface) and
The `TcpServer` class implements the [`ServerInterface`](#serverinterface) and
is responsible for accepting plaintext TCP/IP connections.

```php
$server = new Server(8080, $loop);
$server = new TcpServer(8080, $loop);
```

As above, the `$uri` parameter can consist of only a port, in which case the
Expand All @@ -335,7 +335,7 @@ which means it will not be reachable from outside of this system.
In order to use a random port assignment, you can use the port `0`:

```php
$server = new Server(0, $loop);
$server = new TcpServer(0, $loop);
$address = $server->getAddress();
```

Expand All @@ -344,33 +344,33 @@ address through the first parameter provided to the constructor, optionally
preceded by the `tcp://` scheme:

```php
$server = new Server('192.168.0.1:8080', $loop);
$server = new TcpServer('192.168.0.1:8080', $loop);
```

If you want to listen on an IPv6 address, you MUST enclose the host in square
brackets:

```php
$server = new Server('[::1]:8080', $loop);
$server = new TcpServer('[::1]:8080', $loop);
```

If the given URI is invalid, does not contain a port, any other scheme or if it
contains a hostname, it will throw an `InvalidArgumentException`:

```php
// throws InvalidArgumentException due to missing port
$server = new Server('127.0.0.1', $loop);
$server = new TcpServer('127.0.0.1', $loop);
```

If the given URI appears to be valid, but listening on it fails (such as if port
is already in use or port below 1024 may require root access etc.), it will
throw a `RuntimeException`:

```php
$first = new Server(8080, $loop);
$first = new TcpServer(8080, $loop);

// throws RuntimeException because port is already in use
$second = new Server(8080, $loop);
$second = new TcpServer(8080, $loop);
```

> Note that these error conditions may vary depending on your system and/or
Expand All @@ -382,7 +382,7 @@ Optionally, you can specify [socket context options](http://php.net/manual/en/co
for the underlying stream socket resource like this:

```php
$server = new Server('[::1]:8080', $loop, array(
$server = new TcpServer('[::1]:8080', $loop, array(
'backlog' => 200,
'so_reuseport' => true,
'ipv6_v6only' => true
Expand All @@ -408,7 +408,7 @@ $server->on('connection', function (ConnectionInterface $connection) {

See also the [`ServerInterface`](#serverinterface) for more details.

Note that the `Server` class is a concrete implementation for TCP/IP sockets.
Note that the `TcpServer` class is a concrete implementation for TCP/IP sockets.
If you want to typehint in your higher-level protocol implementation, you SHOULD
use the generic [`ServerInterface`](#serverinterface) instead.

Expand All @@ -417,14 +417,14 @@ use the generic [`ServerInterface`](#serverinterface) instead.
The `SecureServer` class implements the [`ServerInterface`](#serverinterface)
and is responsible for providing a secure TLS (formerly known as SSL) server.

It does so by wrapping a [`Server`](#server) instance which waits for plaintext
It does so by wrapping a [`TcpServer`](#tcpserver) instance which waits for plaintext
TCP/IP connections and then performs a TLS handshake for each connection.
It thus requires valid [TLS context options](http://php.net/manual/en/context.ssl.php),
which in its most basic form may look something like this if you're using a
PEM encoded certificate file:

```php
$server = new Server(8000, $loop);
$server = new TcpServer(8000, $loop);
$server = new SecureServer($server, $loop, array(
'local_cert' => 'server.pem'
));
Expand All @@ -439,7 +439,7 @@ If your private key is encrypted with a passphrase, you have to specify it
like this:

```php
$server = new Server(8000, $loop);
$server = new TcpServer(8000, $loop);
$server = new SecureServer($server, $loop, array(
'local_cert' => 'server.pem',
'passphrase' => 'secret'
Expand Down Expand Up @@ -479,13 +479,13 @@ If you want to typehint in your higher-level protocol implementation, you SHOULD
use the generic [`ServerInterface`](#serverinterface) instead.

> Advanced usage: Despite allowing any `ServerInterface` as first parameter,
you SHOULD pass a `Server` instance as first parameter, unless you
you SHOULD pass a `TcpServer` instance as first parameter, unless you
know what you're doing.
Internally, the `SecureServer` has to set the required TLS context options on
the underlying stream resources.
These resources are not exposed through any of the interfaces defined in this
package, but only through the `React\Stream\Stream` class.
The `Server` class is guaranteed to emit connections that implement
The `TcpServer` class is guaranteed to emit connections that implement
the `ConnectionInterface` and also extend the `Stream` class in order to
expose these underlying resources.
If you use a custom `ServerInterface` and its `connection` event does not
Expand Down
4 changes: 2 additions & 2 deletions examples/01-echo.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
// $ openssl s_client -connect localhost:8000

use React\EventLoop\Factory;
use React\Socket\Server;
use React\Socket\TcpServer;
use React\Socket\ConnectionInterface;
use React\Socket\SecureServer;

require __DIR__ . '/../vendor/autoload.php';

$loop = Factory::create();

$server = new Server(isset($argv[1]) ? $argv[1] : 0, $loop);
$server = new TcpServer(isset($argv[1]) ? $argv[1] : 0, $loop);

// secure TLS mode if certificate is given as second parameter
if (isset($argv[2])) {
Expand Down
4 changes: 2 additions & 2 deletions examples/02-chat-server.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// $ openssl s_client -connect localhost:8000

use React\EventLoop\Factory;
use React\Socket\Server;
use React\Socket\TcpServer;
use React\Socket\ConnectionInterface;
use React\Socket\SecureServer;
use React\Socket\LimitingServer;
Expand All @@ -21,7 +21,7 @@

$loop = Factory::create();

$server = new Server(isset($argv[1]) ? $argv[1] : 0, $loop);
$server = new TcpServer(isset($argv[1]) ? $argv[1] : 0, $loop);

// secure TLS mode if certificate is given as second parameter
if (isset($argv[2])) {
Expand Down
4 changes: 2 additions & 2 deletions examples/03-benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
// $ dd if=/dev/zero bs=1M count=1000 | openssl s_client -connect localhost:8000

use React\EventLoop\Factory;
use React\Socket\Server;
use React\Socket\TcpServer;
use React\Socket\ConnectionInterface;
use React\Socket\SecureServer;

require __DIR__ . '/../vendor/autoload.php';

$loop = Factory::create();

$server = new Server(isset($argv[1]) ? $argv[1] : 0, $loop);
$server = new TcpServer(isset($argv[1]) ? $argv[1] : 0, $loop);

// secure TLS mode if certificate is given as second parameter
if (isset($argv[2])) {
Expand Down
2 changes: 1 addition & 1 deletion src/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function getRemoteAddress();
* This method complements the [`getRemoteAddress()`](#getremoteaddress) method,
* so they should not be confused.
*
* If your `Server` instance is listening on multiple interfaces (e.g. using
* If your `TcpServer` instance is listening on multiple interfaces (e.g. using
* the address `0.0.0.0`), you can use this method to find out which interface
* actually accepted this connection (such as a public or local interface).
*
Expand Down
20 changes: 10 additions & 10 deletions src/SecureServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

use Evenement\EventEmitter;
use React\EventLoop\LoopInterface;
use React\Socket\Server;
use React\Socket\TcpServer;
use React\Socket\ConnectionInterface;
use React\Stream\Stream;

/**
* The `SecureServer` class implements the `ServerInterface` and is responsible
* for providing a secure TLS (formerly known as SSL) server.
*
* It does so by wrapping a `Server` instance which waits for plaintext
* It does so by wrapping a `TcpServer` instance which waits for plaintext
* TCP/IP connections and then performs a TLS handshake for each connection.
*
* ```php
* $server = new Server(8000, $loop);
* $server = new TcpServer(8000, $loop);
* $server = new SecureServer($server, $loop, array(
* // tls context options here…
* ));
Expand Down Expand Up @@ -61,14 +61,14 @@ final class SecureServer extends EventEmitter implements ServerInterface
/**
* Creates a secure TLS server and starts waiting for incoming connections
*
* It does so by wrapping a `Server` instance which waits for plaintext
* It does so by wrapping a `TcpServer` instance which waits for plaintext
* TCP/IP connections and then performs a TLS handshake for each connection.
* It thus requires valid [TLS context options],
* which in its most basic form may look something like this if you're using a
* PEM encoded certificate file:
*
* ```php
* $server = new Server(8000, $loop);
* $server = new TcpServer(8000, $loop);
* $server = new SecureServer($server, $loop, array(
* 'local_cert' => 'server.pem'
* ));
Expand All @@ -83,7 +83,7 @@ final class SecureServer extends EventEmitter implements ServerInterface
* like this:
*
* ```php
* $server = new Server(8000, $loop);
* $server = new TcpServer(8000, $loop);
* $server = new SecureServer($server, $loop, array(
* 'local_cert' => 'server.pem',
* 'passphrase' => 'secret'
Expand All @@ -96,24 +96,24 @@ final class SecureServer extends EventEmitter implements ServerInterface
* Passing unknown context options has no effect.
*
* Advanced usage: Despite allowing any `ServerInterface` as first parameter,
* you SHOULD pass a `Server` instance as first parameter, unless you
* you SHOULD pass a `TcpServer` instance as first parameter, unless you
* know what you're doing.
* Internally, the `SecureServer` has to set the required TLS context options on
* the underlying stream resources.
* These resources are not exposed through any of the interfaces defined in this
* package, but only through the `React\Stream\Stream` class.
* The `Server` class is guaranteed to emit connections that implement
* The `TcpServer` class is guaranteed to emit connections that implement
* the `ConnectionInterface` and also extend the `Stream` class in order to
* expose these underlying resources.
* If you use a custom `ServerInterface` and its `connection` event does not
* meet this requirement, the `SecureServer` will emit an `error` event and
* then close the underlying connection.
*
* @param ServerInterface|Server $tcp
* @param ServerInterface|TcpServer $tcp
* @param LoopInterface $loop
* @param array $context
* @throws \BadMethodCallException for legacy HHVM < 3.8 due to lack of support
* @see Server
* @see TcpServer
* @link http://php.net/manual/en/context.ssl.php for TLS context options
*/
public function __construct(ServerInterface $tcp, LoopInterface $loop, array $context)
Expand Down
24 changes: 12 additions & 12 deletions src/Server.php → src/TcpServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
use RuntimeException;

/**
* The `Server` class implements the `ServerInterface` and
* The `TcpServer` class implements the `ServerInterface` and
* is responsible for accepting plaintext TCP/IP connections.
*
* ```php
* $server = new Server(8080, $loop);
* $server = new TcpServer(8080, $loop);
* ```
*
* Whenever a client connects, it will emit a `connection` event with a connection
Expand All @@ -28,14 +28,14 @@
*
* See also the `ServerInterface` for more details.
*
* Note that the `Server` class is a concrete implementation for TCP/IP sockets.
* Note that the `TcpServer` class is a concrete implementation for TCP/IP sockets.
* If you want to typehint in your higher-level protocol implementation, you SHOULD
* use the generic `ServerInterface` instead.
*
* @see ServerInterface
* @see ConnectionInterface
*/
final class Server extends EventEmitter implements ServerInterface
final class TcpServer extends EventEmitter implements ServerInterface
{
private $master;
private $loop;
Expand All @@ -49,7 +49,7 @@ final class Server extends EventEmitter implements ServerInterface
* for more details.
*
* ```php
* $server = new Server(8080, $loop);
* $server = new TcpServer(8080, $loop);
* ```
*
* As above, the `$uri` parameter can consist of only a port, in which case the
Expand All @@ -59,7 +59,7 @@ final class Server extends EventEmitter implements ServerInterface
* In order to use a random port assignment, you can use the port `0`:
*
* ```php
* $server = new Server(0, $loop);
* $server = new TcpServer(0, $loop);
* $address = $server->getAddress();
* ```
*
Expand All @@ -68,33 +68,33 @@ final class Server extends EventEmitter implements ServerInterface
* preceded by the `tcp://` scheme:
*
* ```php
* $server = new Server('192.168.0.1:8080', $loop);
* $server = new TcpServer('192.168.0.1:8080', $loop);
* ```
*
* If you want to listen on an IPv6 address, you MUST enclose the host in square
* brackets:
*
* ```php
* $server = new Server('[::1]:8080', $loop);
* $server = new TcpServer('[::1]:8080', $loop);
* ```
*
* If the given URI is invalid, does not contain a port, any other scheme or if it
* contains a hostname, it will throw an `InvalidArgumentException`:
*
* ```php
* // throws InvalidArgumentException due to missing port
* $server = new Server('127.0.0.1', $loop);
* $server = new TcpServer('127.0.0.1', $loop);
* ```
*
* If the given URI appears to be valid, but listening on it fails (such as if port
* is already in use or port below 1024 may require root access etc.), it will
* throw a `RuntimeException`:
*
* ```php
* $first = new Server(8080, $loop);
* $first = new TcpServer(8080, $loop);
*
* // throws RuntimeException because port is already in use
* $second = new Server(8080, $loop);
* $second = new TcpServer(8080, $loop);
* ```
*
* Note that these error conditions may vary depending on your system and/or
Expand All @@ -106,7 +106,7 @@ final class Server extends EventEmitter implements ServerInterface
* for the underlying stream socket resource like this:
*
* ```php
* $server = new Server('[::1]:8080', $loop, array(
* $server = new TcpServer('[::1]:8080', $loop, array(
* 'backlog' => 200,
* 'so_reuseport' => true,
* 'ipv6_v6only' => true
Expand Down
Loading