public byte[] EndReadMessage(IAsyncResult asyncResult)
{
if (asyncResult == null)
{
throw new ArgumentNullException(nameof(asyncResult));
}
WorkerAsyncResult workerResult = asyncResult as WorkerAsyncResult;
if (workerResult == null)
{
throw new ArgumentException(SR.Format(SR.net_io_async_result, typeof(WorkerAsyncResult).FullName), nameof(asyncResult));
}
if (!workerResult.InternalPeekCompleted)
{
workerResult.InternalWaitForCompletion();
}
if (workerResult.Result is Exception)
{
throw (Exception)(workerResult.Result);
}
int size = (int)workerResult.Result;
if (size == -1)
{
_eof = true;
return null;
}
else if (size == 0)
{
// Empty frame.
return Array.Empty<byte>();
}
return workerResult.Buffer;
}