def stream_readline(S):
  """Read a line, with a \r\n newline, including trailing \r\n."""
  ans = []
  while True:
    c = S.recv(1)
    if c == '': break
    if c == '\n': break
    ans += [c]
  return ''.join(ans)