Skip to content

Instantly share code, notes, and snippets.

@MihaZupan
Last active November 29, 2022 17:58
async ValueTask<Stream> ConnectAsync(SocketsHttpConnectionContext context, CancellationToken cancellationToken)
{
var socket = new Socket(SocketType.Stream, ProtocolType.Tcp) { NoDelay = true };
try
{
await socket.ConnectAsync(context.DnsEndPoint, cancellationToken);
socket.SetFoo(bar);
return new NetworkStream(socket, ownsSocket: true);
}
catch
{
socket.Dispose();
throw;
}
}
async ValueTask<Stream> ConnectAsync(SocketsHttpConnectionContext context, CancellationToken cancellationToken)
{
var networkStream = await context.DefaultConnectAsync(cancellationToken);
networkStream.Socket.SetFoo(bar);
return networkStream;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment