Skip to content

Commit

Permalink
Improve error message if socket isn't configured for TLS and TLS is e…
Browse files Browse the repository at this point in the history
…nabled
  • Loading branch information
kelunik committed Oct 3, 2018
1 parent 4f2927a commit ebd06b1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/ServerSocket.php
Expand Up @@ -6,13 +6,24 @@
use Amp\Failure;
use Amp\Promise;

class ServerSocket extends Socket {
class ServerSocket extends Socket
{
/** @inheritdoc */
public function enableCrypto(): Promise {
public function enableCrypto(): Promise
{
if (($resource = $this->getResource()) === null) {
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 ebd06b1

Please sign in to comment.