private byte[] ReceiveData()
{
byte[] frameHeader = new byte[8];
if (!FillBuffer(frameHeader, 0))
{
if (this.OnError != null)
{
var connWasLostEx = new Exception("Connection was lost!");
this.OnError(this, new ProtocolErrorEventArgs(connWasLostEx));
}
}
byte[] frameBytes = new byte[0];
int frameLenInBytes = 8 + BinaryHelper.Int32FromBytes(new ArraySegment<byte>(frameHeader, 5, 3));
frameBytes = new byte[frameLenInBytes];
Buffer.BlockCopy(frameHeader, 0, frameBytes, 0, frameHeader.Length);
if (!FillBuffer(frameBytes, 8))
{
if (this.OnError != null)
{
var connWasLostEx = new Exception("Connection was lost!");
this.OnError(this, new ProtocolErrorEventArgs(connWasLostEx));
}
}
return frameBytes;
}