Is it safe to wrap NetworkStream with BufferedStream to read async?

I am using NetworkStream.BeginRead for asynchronous reading from Socket .

But it is much faster if you actually terminate the network stream using BufferedStream .

My question is: NetworkStream.BeginRead internally calls Socket.BeginReceive and the entire async IO stack (CompletionPorts on Windows, etc.). Does the same thing happen when a BufferedStream is in the middle?

+8
c # asyncsocket
source share
1 answer

BufferedStream does not support efficient asynchronous I / O. It uses the default implementation inherited from the Stream class. It will issue synchronous IOs in the thread pool. This way you will not get I / O ports. You need to do this work yourself. If you use C # 5, you can almost reuse the BufferedStream implementation and try to tickle the asynchronous call and wait on it.

+2
source share

All Articles