<?php

namespace Amp\Socket;

use Amp\ByteStream\ClosedException;
use Amp\Failure;
use Amp\Promise;

class ServerSocket extends Socket {
    /** @inheritdoc */
    public function enableCrypto(): Promise {
        if (($resource = $this->getResource()) === null) {
            return new Failure(new ClosedException("The socket has been closed"));
        }

        return Internal\enableCrypto($resource, [], true);
    }
}

<?php

namespace Amp\Socket;

use Amp\ByteStream\ClosedException;
use Amp\Failure;
use Amp\Promise;

class ServerSocket extends Socket {
    /** @inheritdoc */
    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);
    }
}

Improve error message if socket isn't configured for TLS
Improve error message if socket isn't configured for TLS
