I have a confusion on how the ReadTimeout
is used and how this affects Read().
When trying to read the network stream, there are 3 scenarios, assuming we are trying to read X number of bytes:
- Data is available, and bytes < X
- Data is available, and bytes = X
- Data is available, and bytes > X
- No data is available, and
ReadTimeout
> 0 - No data is available, and
ReadTimeout
= 0
The documentation is a bit ambiguous and does not explicitly mention about ReadTimeout
in the call to Read()
, or whether ReadTimeout
affects Read()
call at all.
This method reads data into the buffer parameter and returns the number of bytes successfully read. If no data is available for reading, the Read method returns 0. The Read operation reads as much data as is available, up to the number of bytes specified by the size parameter.
What I understand is for the above 5 scenarios:
Read()
will read in X bytes and return immediately.ReadTimeout
does not matterRead()
will read X bytes and returnRead()
will read X bytes and return. Need to call read again to read the rest of the X bytes.- Call to
Read()
will wait forReadTimeout
period of time for data. Read()
will return immediately with 0.
Would greatly appreciate if anybody can give some clarification.
Thank you.