private void HeaderReceivedCallBack(IAsyncResult result)
        {
            ITransferContext context = (ITransferContext)result.AsyncState;
            int receive = context.Listener.EndReceive(result);

            if (receive > 0)
            {
                context.IncomingHeader(receive);
            }

            if (context.DeserialPacketSize > 0)
            {
                int buffersize = (context.DeserialPacketSize < context.BufferSize) ? (int)context.DeserialPacketSize : context.BufferSize;
                context.Listener.BeginReceive(context.HeaderBuffer, 0, buffersize, SocketFlags.None, HeaderReceivedCallBack, context);
            }
            else
            {
                TransferOperation request = new TransferOperation(context.Transfer, MessagePart.Header, DirectionType.Receive);
                request.Resolve(context.DeserialPacket);

                if (!context.ReceiveMessage &&
                    !context.SendMessage)
                {
                    context.Close = true;
                }

                context.HeaderReceivedNotice.Set();
                HeaderReceived.Execute(this);
            }
        }
Пример #2
0
        /// <summary>
        /// The HeaderReceivedCallback.
        /// </summary>
        /// <param name="result">The result<see cref="IAsyncResult"/>.</param>
        public void HeaderReceivedCallback(IAsyncResult result)
        {
            ITransferContext context = (ITransferContext)result.AsyncState;
            int receive = context.Listener.EndReceive(result);

            if (receive > 0)
            {
                context.IncomingHeader(receive);
            }

            if (context.Protocol == DealProtocol.DOTP)
            {
                DealHeaderReceived(context);
            }
            else if (context.Protocol == DealProtocol.HTTP)
            {
                HttpHeaderReceived(context);
            }
        }