Skip to content

Commit

Permalink
Improve error message if socket isn't configured for TLS
Browse files Browse the repository at this point in the history
  • Loading branch information
kelunik committed Oct 3, 2018
1 parent 4f2927a commit c95926d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ServerSocket.php
Expand Up @@ -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);
}
}

0 comments on commit c95926d

Please sign in to comment.