From 5267a138edfe85efeb4be0c365e2f674c340a009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20K=C3=A4hm?= Date: Tue, 2 Jun 2015 16:40:54 +0200 Subject: [PATCH 1/3] Add support for Unix domain sockets, This change adds support for unix domain socket transport for using unix:// and udg:// for connections. --- src/Server.php | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Server.php b/src/Server.php index 98a0a835..da78be49 100644 --- a/src/Server.php +++ b/src/Server.php @@ -18,14 +18,26 @@ public function __construct(LoopInterface $loop) public function listen($port, $host = '127.0.0.1') { - if (strpos($host, ':') !== false) { + $localSocket = ''; + if (filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { + $localSocket = 'tcp://' . $host . ':' . $port; + } elseif (filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { // enclose IPv6 addresses in square brackets before appending port - $host = '[' . $host . ']'; + $localSocket = 'tcp://[' . $host . ']:' . $port; + } elseif (preg_match('#^(unix|udg)://#', $host)) { + $localSocket = $host; } - $this->master = @stream_socket_server("tcp://$host:$port", $errno, $errstr); + if (empty($localSocket)) { + throw new \UnexpectedValueException( + '"' . $host . '" does not match to a set of supported transports. ' . + 'Supported transports are: IPv4, IPv6, unix:// and udg:// .' + , 1433253311); + } + + $this->master = @stream_socket_server($localSocket, $errno, $errstr); if (false === $this->master) { - $message = "Could not bind to tcp://$host:$port: $errstr"; + $message = "Could not bind to $localSocket . Error: $errstr"; throw new ConnectionException($message, $errno); } stream_set_blocking($this->master, 0); From 97a838c922982e7a0c8e46b50d4918700a6fd841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20K=C3=A4hm?= Date: Tue, 2 Jun 2015 17:52:44 +0200 Subject: [PATCH 2/3] require ext-filter for validating ip v4 and v6 Required ext-filter for validating ip v4 and v6 addresses to composer.json added --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 2a007dac..31aff37c 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,8 @@ "php": ">=5.4.0", "evenement/evenement": "~2.0", "react/event-loop": "0.4.*", - "react/stream": "0.4.*" + "react/stream": "0.4.*", + "ext-filter": "*" }, "autoload": { "psr-4": { From 0932e9b938b81cd67387a648d6225eba7f74fe27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20K=C3=A4hm?= Date: Tue, 2 Jun 2015 18:18:50 +0200 Subject: [PATCH 3/3] remove udg:// UDG sockets are based on datagrams instead of streams of bytes and already a part of React's datagram component. --- src/Server.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Server.php b/src/Server.php index da78be49..db693263 100644 --- a/src/Server.php +++ b/src/Server.php @@ -24,14 +24,12 @@ public function listen($port, $host = '127.0.0.1') } elseif (filter_var($host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { // enclose IPv6 addresses in square brackets before appending port $localSocket = 'tcp://[' . $host . ']:' . $port; - } elseif (preg_match('#^(unix|udg)://#', $host)) { + } elseif (preg_match('#^unix://#', $host)) { $localSocket = $host; - } - - if (empty($localSocket)) { + } else { throw new \UnexpectedValueException( '"' . $host . '" does not match to a set of supported transports. ' . - 'Supported transports are: IPv4, IPv6, unix:// and udg:// .' + 'Supported transports are: IPv4, IPv6 and unix:// .' , 1433253311); }