Example #1
0
        /// <summary>
        /// 接收并处理请求
        /// </summary>
        /// <param name="serverHandle"></param>
        /// <param name="status"></param>
        /// <param name="error"></param>
        /// <param name="state"></param>
        private void Accept(UvStreamHandle serverHandle, int status, Exception error, object state)
        {
            if (error != null || status != 0)
            {
                return;
            }
            ListenHandle listenHandle = new ListenHandle();

            listenHandle.Init(_loopHandle, new Action <Action <object>, object>(AsyncSendUserPostAction));
            listenHandle.TcpNodealy(true);
            serverHandle.Accept(listenHandle);
            OwinSocket owinSocket = null;

            try
            {
                owinSocket = new OwinSocket(listenHandle, new Action <Action <object>, object>(AsyncSendUserPostAction));
                _owinHttpProcess(owinSocket);
            }
            catch (Exception)
            {
                if (owinSocket != null)
                {
                    owinSocket.Dispose();
                }
                else
                {
                    listenHandle.Close();
                }
            }
        }
Example #2
0
        private static void SendCompleteCallback(OwinSocket sck, int status, Exception ex, object state)
        {
            if (state == null)
            {
                sck.Dispose();
                return;
            }
            RequestData requestData = (RequestData)state;

            byte[] preLoadedBody = requestData._preLoadedBody;
            bool   flag          = requestData.IsKeepAlive();

            requestData.SaveToPoll();
            if (status != 0 || ex != null || !flag)
            {
                sck.Dispose();
                return;
            }
            OwinHttpWorkerManage.Start(sck, preLoadedBody);
        }
Example #3
0
            private void CompilteCallback(OwinSocket sck, int status, Exception ex, object state)
            {
                if (status != 0 || ex != null)
                {
                    _fs.Close();
                    sck.Dispose();
                    _req.SaveToPoll();
                    return;
                }
                if (_offsetSize <= 0)
                {
                    _fs.Close();
                    if (_req.IsKeepAlive())
                    {
                        OwinHttpWorkerManage.Start(sck, _req._preLoadedBody);
                    }
                    else
                    {
                        sck.Dispose();
                    }
                    _req.SaveToPoll();
                    _req = null;
                    return;
                }
                long num2 = _offsetSize;

                if (num2 > 65536)
                {
                    num2 = 65536;
                }
                byte[] array = new byte[num2];
                _fs.Seek(_sendedSize, SeekOrigin.Begin);
                checked
                {
                    _fs.Read(array, 0, (int)num2);
                    _sendedSize += num2;
                    _offsetSize -= num2;
                    sck.Write(array, new Action <OwinSocket, int, Exception, object>(CompilteCallback), null);
                }
            }
Example #4
0
        /// <summary>
        /// 新连接回调事件
        /// </summary>
        /// <param name="serverHandle"></param>
        /// <param name="status"></param>
        /// <param name="error"></param>
        /// <param name="state"></param>
        private void OnNewConnectionCallback(UvStreamHandle serverHandle, int status, Exception error, object state)
        {
            if (error != null || status != 0)
            {
                return;
            }
            ListenHandle clientHandle = new ListenHandle();

            clientHandle.Init(_loopHandle, new Action <Action <object>, object>(AsyncSendUserPostAction));
            clientHandle.TcpNodealy(true);
            serverHandle.Accept(clientHandle);

            //int.MaxValue=2147483647
            _connectCount++;
            if (_connectCount > 2147483547)
            {
                _connectCount = 1;
            }

            int num2 = _connectCount % (_pipeHandleList.Count + 1);

            if (num2 != _pipeHandleList.Count)
            {
                WriteHandleFree(clientHandle, num2);
                return;
            }

            OwinSocket owinSocket = null;

            try
            {
                owinSocket = new OwinSocket(clientHandle, new Action <Action <object>, object>(AsyncSendUserPostAction));
                //主流程开始执行
                _owinHttpProcess(owinSocket);
            }
            catch (Exception)
            {
                if (owinSocket != null)
                {
                    owinSocket.Dispose();
                }
                else
                {
                    clientHandle.Close();
                }
            }
        }