Created
November 14, 2023 22:26
-
-
Save jacobslusser/55497df65d90db75a67a2f6ae693b8f9 to your computer and use it in GitHub Desktop.
Proper DoSend pipeline loop
This file contains 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
while (true) | |
{ | |
// Get data from the send buffer | |
var result = await reader.ReadAsync().ConfigureAwait(false); | |
if (result.IsCanceled) | |
{ | |
break; | |
} | |
// Write to the socket | |
var buffers = result.Buffer; | |
if (!buffers.IsEmpty) | |
{ | |
int bytesSent; | |
if (buffers.IsSingleSegment) | |
{ | |
bytesSent = await _socket!.SendAsync(buffers.First, SocketFlags.None).ConfigureAwait(false); | |
} | |
else | |
{ | |
// HELP!!! | |
bytesSent = 0; | |
} | |
reader.AdvanceTo(buffers.GetPosition(bytesSent)); | |
if (result.IsCompleted) | |
{ | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I ended up following the
SendMultiSegmentAsync
approach used in SignalR. A little more basic than I expected, but I guess if it is good enough for SignalR....