public String EndReadLine(IAsyncResult ar)
{
AsyncReadLineRequest lRequest = (AsyncReadLineRequest)ar;
try
{
if (lRequest.State == AsyncReadLineState.MaxLineLengthReached)
{
TriggerAsyncDisconnect();
Disconnect();
throw new ConnectionClosedException("Size limit for ReadLine() was exceeded.");
}
Byte[] lBuffer = lRequest.Data.GetBuffer();
if (lRequest.Data.Length > 0 && lBuffer[lRequest.Data.Length - 1] == 13)
return Encoding.GetString(lBuffer, 0, (Int32)lRequest.Data.Length - 1); // on the rare occasion that the split is between the #13 and the #10
return Encoding.GetString(lBuffer, 0, (Int32)lRequest.Data.Length);
}
finally
{
lRequest.Data.Close();
}
}