I tracked it down in the Netduino source code:
StreamReader.Peek()
m_curBufPos is 511
m_curBufLen is 512
m_buffer is byte[512]
[color=#0000FF;] if[/color] (m_curBufPos == m_curBufLen || (([color=#ff0000;]m_buffer[m_curBufPos + 1][/color] & 0x80) != 0 && m_curBufPos + 3 > m_curBufLen))
As you know, in a 512 length array, there is no position 512.
So if we change the code to:
[color=#0000FF;]if[/color] (m_curBufPos <= (m_curBufLen - 1) || ((m_buffer[m_curBufPos + 1] & 0x80) != 0 && m_curBufPos + 3 > m_curBufLen))
There is also an endless loop inside Peek():
[color=#008000;]// Retry read until response timeout expires[/color]
[color=#0000FF;]if [/color](m_stream.Length > 0) [color=#0000FF;]while[/color] (i < m_buffer.Length && (noRead = m_stream.Read(m_buffer, i, ([color=#0000FF;]int[/color])(m_buffer.Length - i < m_stream.Length ? m_buffer.Length - i : m_stream.Length))) == 0)
{
i += noRead; [color=#ff0000;]// gets stuck here[/color]
}
}
Fixing that with:
[color=#0000FF;]if[/color] (m_stream.Length > 0 && (m_stream.Position != m_stream.Length))
However, this probably breaks if you are reading from a network stream or something.
Anyways, here's a quick & dirty line reader:
- per123 likes this