I programmed the FastCGI library for C #. This was before async / wait. Now I am programming version 2 of this library based on performance. Therefore, I use IOCP using socket.ReceiveAsync. (Note: ReceiveAsync
has nothing to do with await
/ async
. I want to use ReceiveAsync
.)
However, the library user can respond to an incoming request without specifying a Content-Length-header. This leads to a situation where the library needs to collect all outgoing traffic until all data is available or the user specifies Content-Length.
My old version of this library implemented this with a class recorder LocalPipe
. LocalPipe
- this is just a stream in which you can write data and then read data from it. If there is insufficient data available, the read method is blocked.
While LocalPipe
blocking the calling thread, it is also blocked and therefore not freed when waiting for new data. This leads to the creation of a “single connection / single thread”, at least expecting data from LocalPipe
.
My question is: is there already a class (like the NuGet package or the .NET environment itself) that implements something like my class LocalPipe
, but which will "block" without supporting the call flow used?
I'm not looking for the usual Task
-Pattern for await
, unless it really escapes the use of unnecessary Thread
s / Task
and context switches. Currently, the only way to implement this "thread consuming friendly" class seems to make heavy use of ExecutionContext
and / or SynchronizationContext
while implementing the expected pattern. It would be nice if I could just avoid this.
source
share