/// <summary> /// Receives byte stream from remote end point. /// </summary> /// <param name="context">Context information.</param> /// <exception cref="InvalidOperationException"> /// This instance is not in 'Idle' state. /// </exception> /// <exception cref="ObjectDisposedException"> /// This instance is disposed. /// </exception> private void Receive(ClientResponseContext context) { Contract.Assert(context != null); Contract.Assert(context.BoundTransport == this, "Context is not bound to this object."); // First, drain last received request. if (context.ReceivedData.Any(segment => 0 < segment.Count)) { this.DrainRemainingReceivedData(context); } else { // There might be dirty data due to client shutdown. context.ReceivedData.Clear(); Array.Clear(context.CurrentReceivingBuffer, 0, context.CurrentReceivingBuffer.Length); context.PrepareReceivingBuffer(); var socket = this.BoundSocket; MsgPackRpcClientProtocolsTrace.TraceEvent( MsgPackRpcClientProtocolsTrace.BeginReceive, "Receive inbound data. {{ \"Socket\" : 0x{0:X}, \"RemoteEndPoint\" : \"{1}\", \"LocalEndPoint\" : \"{2}\" }}", GetHandle(socket), GetRemoteEndPoint(socket, context), GetLocalEndPoint(socket) ); this.ReceiveCore(context); } }