This commit is contained in:
2021-06-09 20:08:15 +03:00
parent 411fabb1f5
commit e3c64f6f09
3 changed files with 28 additions and 3 deletions

View File

@ -5,15 +5,16 @@ declare(strict_types=1);
namespace Nsq\Stream;
use Amp\Promise;
use Amp\Socket\ClientTlsContext;
use Amp\Socket\ConnectContext;
use Amp\Socket\Socket;
use Amp\Socket\EncryptableSocket;
use Nsq\Stream;
use function Amp\call;
use function Amp\Socket\connect;
class SocketStream implements Stream
{
public function __construct(private Socket $socket)
public function __construct(private EncryptableSocket $socket)
{
}
@ -37,6 +38,11 @@ class SocketStream implements Stream
$context = $context->withTcpNoDelay();
}
$context = $context->withTlsContext(
(new ClientTlsContext(''))
->withoutPeerVerification()
);
return new self(yield connect($uri, $context));
});
}
@ -61,4 +67,12 @@ class SocketStream implements Stream
{
$this->socket->close();
}
/**
* @return Promise<void>
*/
public function setupTls(): Promise
{
return $this->socket->setupTls();
}
}