/ConnectCallback.cs Secret
Last active
November 29, 2022 17:58
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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