Example #1
0
 /// <summary>
 /// 接受头部换行数据
 /// </summary>
 /// <param name="result">异步操作状态</param>
 private unsafe void onReceive(IAsyncResult result)
 {
     if (IsKeepAliveReceive)
     {
         if (!result.CompletedSynchronously)
         {
             KeepAliveReceiveTimeout.Cancel(httpSocket);
         }
         IsKeepAliveReceive = false;
     }
     else if (!result.CompletedSynchronously)
     {
         ReceiveTimeout.Cancel(httpSocket);
     }
     try
     {
         int count = httpSocket.SslStream.EndRead(result);
         if (count > 0)
         {
             receiveCount += count;
             if (searchEnd())
                 return; }
             if (receiveCount != ReceiveBufferSize && (count >= TcpServer.Server.MinSocketSize || ReceiveSizeLessCount++ == 0))
             {
                 if (!httpSocket.SslStream.BeginRead(Buffer.Buffer, Buffer.StartIndex + receiveCount, ReceiveBufferSize - receiveCount, receiveCallback, this).CompletedSynchronously)
                 {
                     ReceiveTimeout.Push(httpSocket, socket);
                 }
             }
         }
     }
Example #2
0
        /// <summary>
        /// 接收数据完成后的回调
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="async">异步回调参数</param>
        private void onReceive(object sender, SocketAsyncEventArgs async)
#endif
        {
            try
            {
#if DOTNET2
                if (IsKeepAliveReceive)
                {
                    if (!async.CompletedSynchronously)
                        KeepAliveReceiveTimeout.Cancel(httpSocket); }
                    IsKeepAliveReceive = false;
                }
                else if (!async.CompletedSynchronously)
                {
                    ReceiveTimeout.Cancel(httpSocket);
                }
                if (onReceiveAsync(async))
                {
                    return;
                }
#else
                if (IsKeepAliveReceive)
                {
                    KeepAliveReceiveTimeout.Cancel(httpSocket);
                    IsKeepAliveReceive = false;
                }
                else
                {
                    ReceiveTimeout.Cancel(httpSocket);
                }
                if (onReceive())
                {
                    return;
                }
#endif
            }