public virtual String ReadLine()
{
Boolean lDone = false;
String lResult = "";
while (!lDone)
{
if (fBuffer == null)
{
fBuffer = new Byte[READLINE_BUFFER_SIZE];
fBufferStart = 0;
fBufferEnd = DataSocketReceiveWhatsAvaiable(fBuffer, 0, fBuffer.Length);
if (fBufferEnd == 0)
throw new ConnectionClosedException();
}
Int32 i = fBufferStart;
while (i < fBufferEnd && !lDone)
{
if (fBuffer[i] == 10)
lDone = true;
i++;
}
if (lDone)
{
if ((i - 2 >= fBufferStart) && fBuffer[i - 2] == 13)
{
// if last character is 13, of yes we have a Windows style CRLF line end and must discard the CR, too
lResult = lResult + Encoding.GetString(fBuffer, fBufferStart, i - fBufferStart - 2);
}
else
{
// else just discard the 10 (LF)
lResult = lResult + Encoding.GetString(fBuffer, fBufferStart, i - fBufferStart - 1);
}
}
else
{
lResult = lResult + Encoding.GetString(fBuffer, fBufferStart, i - fBufferStart);
}
if (lDone)
{
/* Keep remaining buffer for future reads. */
fBufferStart = i;
if (fBufferStart == fBufferEnd)
fBuffer = null;
}
else
{
fBuffer = null;
}
// Enforce Line Length checking
if (MaxLineLengthEnabled && lResult.Length > MaxLineLength)
{
Disconnect();
throw new ConnectionClosedException("Size limit for ReadLine() was exceeded.");
}
}
return lResult;
}