I'm using NetworkStream.BeginRead
to read asynchronously from a Socket
.
But it is much faster if you actually wrap the network stream with a BufferedStream
.
My question: NetworkStream.BeginRead
internally invokes to Socket.BeginReceive
and the whole stack of async IO (CompletionPorts on Windows and so on). Does the same happen when BufferedStream
is in the middle?
BufferedStream does not support efficient async IO. It uses the default implementation inherited from the Stream class. It will issue synchronous IOs on the thread-pool. So you won't get IO completion ports doing that. You need to do this work yourself. If you are using C# 5 you can nearly reuse BufferedStream's implementation and try to slap async and awaits on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With