From c95926d10a4167d7d8f698605a1a5b0460aec0b8 Mon Sep 17 00:00:00 2001 From: Niklas Keller Date: Wed, 3 Oct 2018 11:05:45 +0200 Subject: [PATCH] Improve error message if socket isn't configured for TLS --- src/ServerSocket.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ServerSocket.php b/src/ServerSocket.php index 5ca035b..829cd53 100644 --- a/src/ServerSocket.php +++ b/src/ServerSocket.php @@ -13,6 +13,15 @@ public function enableCrypto(): Promise { return new Failure(new ClosedException("The socket has been closed")); } + $ctx = \stream_context_get_options($resource); + if (empty($ctx['ssl'])) { + return new Failure(new SocketException( + "Can't enable TLS without configuration. " . + "If you used Amp\\Socket\\listen(), be sure to pass a ServerTlsContext as third argument, " . + "otherwise set the 'ssl' context option to the PHP stream resource." + )); + } + return Internal\enableCrypto($resource, [], true); } }