Skip to content

Commit 667a44e

Browse files
authored
Merge pull request #419 from clue-labs/socket
Simplify usage by supporting new Socket API without nullable loop arguments
2 parents e1c5e4f + 30c33fe commit 667a44e

30 files changed

+146
-144
lines changed

README.md

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ $http = new React\Http\HttpServer(function (Psr\Http\Message\ServerRequestInterf
107107
);
108108
});
109109

110-
$socket = new React\Socket\Server(8080);
110+
$socket = new React\Socket\SocketServer('127.0.0.1:8080');
111111
$http->listen($socket);
112112
```
113113

@@ -260,7 +260,6 @@ like this:
260260
```php
261261
$browser = new React\Http\Browser(
262262
new React\Socket\Connector(
263-
null,
264263
array(
265264
'timeout' => 5
266265
)
@@ -604,7 +603,7 @@ $proxy = new Clue\React\HttpProxy\ProxyConnector(
604603
new React\Socket\Connector()
605604
);
606605

607-
$connector = new React\Socket\Connector(null, array(
606+
$connector = new React\Socket\Connector(array(
608607
'tcp' => $proxy,
609608
'dns' => false
610609
));
@@ -631,7 +630,7 @@ $proxy = new Clue\React\Socks\Client(
631630
new React\Socket\Connector()
632631
);
633632

634-
$connector = new React\Socket\Connector(null, array(
633+
$connector = new React\Socket\Connector(array(
635634
'tcp' => $proxy,
636635
'dns' => false
637636
));
@@ -660,7 +659,7 @@ plain HTTP and TLS-encrypted HTTPS.
660659
```php
661660
$proxy = new Clue\React\SshProxy\SshSocksConnector('me@localhost:22', Loop::get());
662661

663-
$connector = new React\Socket\Connector(null, array(
662+
$connector = new React\Socket\Connector(array(
664663
'tcp' => $proxy,
665664
'dns' => false
666665
));
@@ -741,13 +740,13 @@ to be attached to an instance of
741740
[`React\Socket\ServerInterface`](https://github.com/reactphp/socket#serverinterface)
742741
through the [`listen()`](#listen) method as described in the following
743742
chapter. In its most simple form, you can attach this to a
744-
[`React\Socket\Server`](https://github.com/reactphp/socket#server) in order
745-
to start a plaintext HTTP server like this:
743+
[`React\Socket\SocketServer`](https://github.com/reactphp/socket#socketserver)
744+
in order to start a plaintext HTTP server like this:
746745

747746
```php
748747
$http = new React\Http\HttpServer($handler);
749748

750-
$socket = new React\Socket\Server('0.0.0.0:8080');
749+
$socket = new React\Socket\SocketServer('0.0.0.0:8080');
751750
$http->listen($socket);
752751
```
753752

@@ -869,13 +868,13 @@ is responsible for emitting the underlying streaming connections. This
869868
HTTP server needs to be attached to it in order to process any
870869
connections and pase incoming streaming data as incoming HTTP request
871870
messages. In its most common form, you can attach this to a
872-
[`React\Socket\Server`](https://github.com/reactphp/socket#server) in
873-
order to start a plaintext HTTP server like this:
871+
[`React\Socket\SocketServer`](https://github.com/reactphp/socket#socketserver)
872+
in order to start a plaintext HTTP server like this:
874873

875874
```php
876875
$http = new React\Http\HttpServer($handler);
877876

878-
$socket = new React\Socket\Server('0.0.0.0:8080');
877+
$socket = new React\Socket\SocketServer('0.0.0.0:8080');
879878
$http->listen($socket);
880879
```
881880

@@ -894,15 +893,17 @@ Likewise, it's usually recommended to use a reverse proxy setup to accept
894893
secure HTTPS requests on default HTTPS port `443` (TLS termination) and
895894
only route plaintext requests to this HTTP server. As an alternative, you
896895
can also accept secure HTTPS requests with this HTTP server by attaching
897-
this to a [`React\Socket\Server`](https://github.com/reactphp/socket#server)
896+
this to a [`React\Socket\SocketServer`](https://github.com/reactphp/socket#socketserver)
898897
using a secure TLS listen address, a certificate file and optional
899898
`passphrase` like this:
900899

901900
```php
902901
$http = new React\Http\HttpServer($handler);
903902

904-
$socket = new React\Socket\Server('tls://0.0.0.0:8443', null, array(
905-
'local_cert' => __DIR__ . '/localhost.pem'
903+
$socket = new React\Socket\SocketServer('tls://0.0.0.0:8443', array(
904+
'tls' => array(
905+
'local_cert' => __DIR__ . '/localhost.pem'
906+
)
906907
));
907908
$http->listen($socket);
908909
```
@@ -1889,7 +1890,7 @@ proxy servers etc.), you can explicitly pass a custom instance of the
18891890
[`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface):
18901891

18911892
```php
1892-
$connector = new React\Socket\Connector(null, array(
1893+
$connector = new React\Socket\Connector(array(
18931894
'dns' => '127.0.0.1',
18941895
'tcp' => array(
18951896
'bindto' => '192.168.10.1:0'

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"react/event-loop": "^1.2",
3333
"react/promise": "^2.3 || ^1.2.1",
3434
"react/promise-stream": "^1.1",
35-
"react/socket": "^1.8",
35+
"react/socket": "^1.9",
3636
"react/stream": "^1.2",
3737
"ringcentral/psr7": "^1.2"
3838
},

examples/11-client-http-connect-proxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
$proxy = new HttpConnectClient('127.0.0.1:8080', new Connector());
1818

1919
// create a Browser object that uses the HTTP CONNECT proxy client for connections
20-
$connector = new Connector(null, array(
20+
$connector = new Connector(array(
2121
'tcp' => $proxy,
2222
'dns' => false
2323
));

examples/12-client-socks-proxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
$proxy = new SocksClient('127.0.0.1:1080', new Connector());
1515

1616
// create a Browser object that uses the SOCKS proxy client for connections
17-
$connector = new Connector(null, array(
17+
$connector = new Connector(array(
1818
'tcp' => $proxy,
1919
'dns' => false
2020
));

examples/13-client-ssh-proxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
$proxy = new SshSocksConnector(isset($argv[1]) ? $argv[1] : 'localhost:22', Loop::get());
1414

1515
// create a Browser object that uses the SSH proxy client for connections
16-
$connector = new Connector(null, array(
16+
$connector = new Connector(array(
1717
'tcp' => $proxy,
1818
'dns' => false
1919
));

examples/51-server-hello-world.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
);
1616
});
1717

18-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
18+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
1919
$http->listen($socket);
2020

2121
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

examples/52-server-count-visitors.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
);
1717
});
1818

19-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
19+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
2020
$http->listen($socket);
2121

2222
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

examples/53-server-whatsmyip.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
);
1818
});
1919

20-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
20+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
2121
$http->listen($socket);
2222

2323
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

examples/54-server-query-parameter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
);
2525
});
2626

27-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
27+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
2828
$http->listen($socket);
2929

3030
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

examples/55-server-cookie-handling.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
);
3131
});
3232

33-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
33+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
3434
$http->listen($socket);
3535

3636
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

examples/56-server-sleep.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
});
2323
});
2424

25-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
25+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
2626
$http->listen($socket);
2727

2828
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

examples/57-server-error-handling.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
});
2828
});
2929

30-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
30+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
3131
$http->listen($socket);
3232

3333
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

examples/58-server-stream-response.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
);
3939
});
4040

41-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
41+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
4242
$http->listen($socket);
4343

4444
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

examples/59-server-json-api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
);
5353
});
5454

55-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
55+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
5656
$http->listen($socket);
5757

5858
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

examples/61-server-hello-world-https.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
);
1616
});
1717

18-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
19-
$socket = new React\Socket\SecureServer($socket, null, array(
20-
'local_cert' => isset($argv[2]) ? $argv[2] : __DIR__ . '/localhost.pem'
18+
$uri = 'tls://' . (isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
19+
$socket = new React\Socket\SocketServer($uri, array(
20+
'tls' => array(
21+
'local_cert' => isset($argv[2]) ? $argv[2] : __DIR__ . '/localhost.pem'
22+
)
2123
));
2224
$http->listen($socket);
2325

24-
//$socket->on('error', 'printf');
26+
$socket->on('error', 'printf');
2527

2628
echo 'Listening on ' . str_replace('tls:', 'https:', $socket->getAddress()) . PHP_EOL;

examples/62-server-form-upload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
$handler
129129
);
130130

131-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
131+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
132132
$http->listen($socket);
133133

134134
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

examples/63-server-streaming-request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function (Psr\Http\Message\ServerRequestInterface $request) {
4444

4545
$http->on('error', 'printf');
4646

47-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
47+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
4848
$http->listen($socket);
4949

5050
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

examples/71-server-http-proxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
);
4545
});
4646

47-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
47+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
4848
$http->listen($socket);
4949

5050
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

examples/72-server-http-connect-proxy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function ($e) {
5050
);
5151
});
5252

53-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
53+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
5454
$http->listen($socket);
5555

5656
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

examples/81-server-upgrade-echo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
);
5757
});
5858

59-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
59+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
6060
$http->listen($socket);
6161

6262
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

examples/82-server-upgrade-chat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
);
8585
});
8686

87-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
87+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
8888
$http->listen($socket);
8989

9090
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

examples/99-server-benchmark-download.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function getSize()
122122
);
123123
});
124124

125-
$socket = new React\Socket\Server(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
125+
$socket = new React\Socket\SocketServer(isset($argv[1]) ? $argv[1] : '0.0.0.0:0');
126126
$http->listen($socket);
127127

128128
echo 'Listening on ' . str_replace('tcp:', 'http:', $socket->getAddress()) . PHP_EOL;

src/Browser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class Browser
4747
* [`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface):
4848
*
4949
* ```php
50-
* $connector = new React\Socket\Connector(null, array(
50+
* $connector = new React\Socket\Connector(array(
5151
* 'dns' => '127.0.0.1',
5252
* 'tcp' => array(
5353
* 'bindto' => '192.168.10.1:0'

src/Client/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class Client
1616
public function __construct(LoopInterface $loop, ConnectorInterface $connector = null)
1717
{
1818
if ($connector === null) {
19-
$connector = new Connector($loop);
19+
$connector = new Connector(array(), $loop);
2020
}
2121

2222
$this->connector = $connector;

src/HttpServer.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@
5454
* [`React\Socket\ServerInterface`](https://github.com/reactphp/socket#serverinterface)
5555
* through the [`listen()`](#listen) method as described in the following
5656
* chapter. In its most simple form, you can attach this to a
57-
* [`React\Socket\Server`](https://github.com/reactphp/socket#server) in order
58-
* to start a plaintext HTTP server like this:
57+
* [`React\Socket\SocketServer`](https://github.com/reactphp/socket#socketserver)
58+
* in order to start a plaintext HTTP server like this:
5959
*
6060
* ```php
6161
* $http = new React\Http\HttpServer($handler);
6262
*
63-
* $socket = new React\Socket\Server('0.0.0.0:8080');
63+
* $socket = new React\Socket\SocketServer('0.0.0.0:8080');
6464
* $http->listen($socket);
6565
* ```
6666
*
@@ -263,13 +263,13 @@ public function __construct($requestHandlerOrLoop)
263263
* HTTP server needs to be attached to it in order to process any
264264
* connections and pase incoming streaming data as incoming HTTP request
265265
* messages. In its most common form, you can attach this to a
266-
* [`React\Socket\Server`](https://github.com/reactphp/socket#server) in
267-
* order to start a plaintext HTTP server like this:
266+
* [`React\Socket\SocketServer`](https://github.com/reactphp/socket#socketserver)
267+
* in order to start a plaintext HTTP server like this:
268268
*
269269
* ```php
270270
* $http = new React\Http\HttpServer($handler);
271271
*
272-
* $socket = new React\Socket\Server(8080);
272+
* $socket = new React\Socket\SocketServer('0.0.0.0:8080');
273273
* $http->listen($socket);
274274
* ```
275275
*
@@ -288,15 +288,17 @@ public function __construct($requestHandlerOrLoop)
288288
* secure HTTPS requests on default HTTPS port `443` (TLS termination) and
289289
* only route plaintext requests to this HTTP server. As an alternative, you
290290
* can also accept secure HTTPS requests with this HTTP server by attaching
291-
* this to a [`React\Socket\Server`](https://github.com/reactphp/socket#server)
291+
* this to a [`React\Socket\SocketServer`](https://github.com/reactphp/socket#socketserver)
292292
* using a secure TLS listen address, a certificate file and optional
293293
* `passphrase` like this:
294294
*
295295
* ```php
296296
* $http = new React\Http\HttpServer($handler);
297297
*
298-
* $socket = new React\Socket\Server('tls://0.0.0.0:8443', null, array(
299-
* 'local_cert' => __DIR__ . '/localhost.pem'
298+
* $socket = new React\Socket\SocketServer('tls://0.0.0.0:8443', array(
299+
* 'tls' => array(
300+
* 'local_cert' => __DIR__ . '/localhost.pem'
301+
* )
300302
* ));
301303
* $http->listen($socket);
302304
* ```

src/Io/Sender.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Sender
3939
* settings. You can use this method manually like this:
4040
*
4141
* ```php
42-
* $connector = new \React\Socket\Connector($loop);
42+
* $connector = new \React\Socket\Connector(array(), $loop);
4343
* $sender = \React\Http\Io\Sender::createFromLoop($loop, $connector);
4444
* ```
4545
*

0 commit comments

Comments
 (0)