Fixed read timeout issue.

This commit is contained in:
flash 2022-04-10 18:49:40 +02:00
parent 0e1fb36721
commit ad80ef21c8
1 changed files with 11 additions and 5 deletions

View File

@ -13,6 +13,9 @@ namespace Hamakaze {
private Socket Socket { get; } private Socket Socket { get; }
private NetworkStream NetworkStream { get; }
private SslStream SslStream { get; }
public string Host { get; } public string Host { get; }
public bool IsSecure { get; } public bool IsSecure { get; }
@ -39,19 +42,19 @@ namespace Hamakaze {
}; };
Socket.Connect(endPoint); Socket.Connect(endPoint);
Stream stream = new NetworkStream(Socket, true); NetworkStream = new NetworkStream(Socket, true);
if(IsSecure) { if(IsSecure) {
SslStream sslStream = new SslStream(stream, false, (s, ce, ch, e) => e == SslPolicyErrors.None, null); SslStream = new SslStream(NetworkStream, false, (s, ce, ch, e) => e == SslPolicyErrors.None, null);
Stream = sslStream; Stream = SslStream;
sslStream.AuthenticateAsClient( SslStream.AuthenticateAsClient(
Host, Host,
null, null,
SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13, SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13,
true true
); );
} else } else
Stream = stream; Stream = NetworkStream;
} }
public void MarkUsed() { public void MarkUsed() {
@ -73,6 +76,9 @@ namespace Hamakaze {
throw new HttpConnectionAlreadyUpgradedException(); throw new HttpConnectionAlreadyUpgradedException();
HasUpgraded = true; HasUpgraded = true;
NetworkStream.ReadTimeout = -1;
SslStream.ReadTimeout = -1;
return new WsConnection(Stream); return new WsConnection(Stream);
} }