title: NetworkStream: ReadTimeout and its effect Read()
body: <p>I have a confusion on how the <code>ReadTimeout</code> is used and how this affects Read().</p>
  
  <p>When trying to read the network stream, there are 3 scenarios, assuming we are trying to read X number of bytes:</p>
  
  <ol>
  <li>Data is available, and bytes &lt; X</li>
  <li>Data is available, and bytes = X</li>
  <li>Data is available, and bytes > X</li>
  <li>No data is available, and <code>ReadTimeout</code> > 0</li>
  <li>No data is available, and <code>ReadTimeout</code> = 0</li>
  </ol>
  
  <p>The documentation is a bit ambiguous and does not explicitly mention about <code>ReadTimeout</code> in the call to <code>Read()</code>, or whether <code>ReadTimeout</code> affects <code>Read()</code> call at all.</p>
  
  <blockquote>
    <p>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.</p>
  </blockquote>
  
  <p>What I understand is for the above 5 scenarios:</p>
  
  <ol>
  <li><code>Read()</code> will read in X bytes and return immediately. <code>ReadTimeout</code> does not matter</li>
  <li><code>Read()</code> will read X bytes and return</li>
  <li><code>Read()</code> will read X bytes and return. Need to call read again to read the rest of the X bytes.</li>
  <li>Call to <code>Read()</code> will wait for <code>ReadTimeout</code> period of time for data.</li>
  <li><code>Read()</code> will return immediately with 0.</li>
  </ol>
  
  <p>Would greatly appreciate if anybody can give some clarification.</p>
  
  <p>Thank you.</p>