title: TextReader.ReadLine returns incomplete lines
body: <p>I am using a <code>Socket</code> to receive data via TCP, and <code>TextReader.ReadLine</code> to read lines from the connection.  There is a problem where a full line has not been received -- <code>TextReader.ReadLine</code> returns an incomplete string.  I want it to return <code>null</code>, indicating that a full line could not be read.  How can I do this?</p>
  
  <p>Basically, I have this data incoming:</p>
  
  <pre><code>"hello\nworld\nthis is a test\n"
  </code></pre>
  
  <p>When I run <code>ReadLine</code> I get these in return:</p>
  
  <pre><code>"hello"
  "world"
  "this is a te"
  &lt;null&gt;
  &lt;socket gets more data&gt;
  "st"
  &lt;null&gt;
  </code></pre>
  
  <p>I do not want "this is a te" returned.  Rather, I want "this is a test" to wait until the entire line has been received.</p>
  
  <p>Code:</p>
  
  <pre><code>var endPoint = ...;
  var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
  socket.Connect(endPoint);
  
  var stream = new NetworkStream(socket, true);
  
  var messageBuffer = new StringBuilder();
  
  // Data received async callback (called several times).
  int bytesRead = stream.EndRead(result);
  string data = Encoding.UTF8.GetString(readBuffer.Take(bytesRead).ToArray());
  messageBuffer.Append(data);
  
  using(var reader = new StringReader(messageBuffer.ToString()))
  {
      // This loop does not know that Message.Read reads lines.  For all it knows, it could read bytes or words or the whole stream.
  
      while((Message msg = Message.Read(reader)) != null)  // See below.
      {
          Console.WriteLine(msg.ToString());    // See example input/echo above.
      }
  
      messageBuffer = new StringBuilder(reader.ReadToEnd());
  }
  
  // Method of Message.
  public static Message Read(TextReader reader)
  {
      string line = reader.ReadLine();
  
      if(line == null)
          return null;
  
      return Message.FromRawString(line);
  }
  </code></pre>
  
  <p>Thanks.</p>