It seems that ReadTimeout up to values ββlike 1000, 2000 does not affect the lock.
Msdn says ReadTimeout has no effect when using the async BeginRead
method.
Is bufferSize set to 1 so that there are no blocks?
No, for no reason. If no bytes are sent over the connection, the Read call will block regardless of buffering.
Will the performance impact be very bad?
I think you are talking about a 1-byte buffer. It depends on the amount and frequency of data you receive and on what code you execute on EndRead
. When processing a stream with high throughput, the impact can be large. You should try and see your processor when receiving data.
I'm not quite sure what you want to achieve, respectively, that your concern is about blocking.
When you start Receive (or Networkstream.Read) with a buffer, say 1024 bytes, and you get 10 bytes in the socket, a Read call will return this 10 bytes after a short delay, but will not be blocked until the entire buffer is full.
Is there any other way to make the lock short?
What do you mean with a short. As I said, even with a large buffer, Read will not block indefinitely when receiving small amounts of data.
(NoDelay = true does not work)
This is a completely different story , but it may be interesting to set it to true
on the side of your senders (if you control this too).
If set to false (the default), it will combine small data shunts sent to larger ones to reduce the overhead of a single tcp packet (40-byte header).
EDIT
I mean NetworkStream.BeginRead to return immediately if there is no data.
How about using stream.DataAvailable
? It should return false when there is no data.
Also, when using the async pattern, is not the expected behavior that calls will block until it does something? Otherwise, you will receive an active survey in the employment cycle.
When the buffer is large, it sometimes waits 60 seconds to return (when it is not full or full to a certain value)
Nm, I canβt believe it. What data do you send on the channel? 1 byte every minute? 1000 bytes per second?