Пример #1
0
        void HandleReceive(RecvEventCode recvEventCode)
        {
            switch (recvEventCode)
            {
            case RecvEventCode.SocketError:
            {
                UnBindSocket(true);
            }
            break;

            case RecvEventCode.NoMoreReceiveData:
            {
                //no data to receive
                _httpResp.End();
                //reqHandler(this.httpReq, httpResp);
            }
            break;

            case RecvEventCode.HasSomeData:
            {
                //process some data
                //there some data to process
                switch (_httpReq.LoadData())
                {
                case ProcessReceiveBufferResult.Complete:
                {
                    //recv and parse complete
                    //goto user action

                    if (this.EnableWebSocket &&
                        _ownerServer.CheckWebSocketUpgradeRequest(this))
                    {
                        return;
                    }
                    _reqHandler(_httpReq, _httpResp);
                    if (_httpResp._actualEnd)
                    {
                        _httpResp.ActualEnd();
                    }

//                                    Reset();
                }
                break;

                case ProcessReceiveBufferResult.NeedMore:
                {
                    _recvIO.StartReceive();
                }
                break;

                case ProcessReceiveBufferResult.Error:
                default:
                    throw new NotSupportedException();
                }
            }
            break;
            }
        }
Пример #2
0
        void HandleReceivedData(RecvEventCode recvCode)
        {
            switch (recvCode)
            {
            case RecvEventCode.HasSomeData:

                //parse recv msg
                switch (this.webSocketReqParser.ParseRecvData())
                {
                //in this version all data is copy into WebSocketRequest
                //so we can reuse recv buffer
                //TODO: review this, if we need to copy?,

                case ProcessReceiveBufferResult.Complete:
                {
                    //you can choose ...
                    //invoke webSocketReqHandler in this thread or another thread
                    while (webSocketReqParser.ReqCount > 0)
                    {
                        WebSocketRequest req = webSocketReqParser.Dequeue();
                        webSocketReqHandler(req, webSocketResp);
                    }
                    recvIO.StartReceive();
                    //***no code after StartReceive***
                }
                    return;

                case ProcessReceiveBufferResult.NeedMore:
                {
                    recvIO.StartReceive();
                    //***no code after StartReceive***
                }
                    return;

                case ProcessReceiveBufferResult.Error:
                default:
                    throw new NotSupportedException();
                }

            case RecvEventCode.NoMoreReceiveData:
            {
            }
            break;

            case RecvEventCode.SocketError:
            {
            }
            break;
            }
        }
        void HandleReceive(RecvEventCode recvEventCode)
        {
            switch (recvEventCode)
            {
                default: throw new NotSupportedException();
                case RecvEventCode.SocketError:
                    {
                        UnBindSocket(true);
                    }
                    break;
                case RecvEventCode.NoMoreReceiveData:
                    {
                    }
                    break;
                case RecvEventCode.HasSomeData:
                    {
                        //process some data
                        //there some data to process  
                        //parse the data    
#if DEBUG
                        if (dbugPleaseBreak)
                        {
                        }
#endif

                        bool needMoreData = _mysqlParserMx.ParseData(recvIO);
                        //please note that: result packet may not ready in first round
                        //but parser mx may 'release' some part of the result (eg. large table)
                        MySqlResult result = _mysqlParserMx.ParseResult; //'release' result 
                        //---------------------------------------------------------------
                        if (result != null)
                        {
                            //if we has some 'release' result from parser mx
                            if (needMoreData)
                            {
                                //this is 'partial result'
                                if (whenRecvData == null)
                                {
                                    //?
                                }
                                //-------------------------
                                //partial release data here
                                //before recv next
                                //because we want to 'sync'
                                //the series of result
                                whenRecvData(result);
                                //-------------------------
                            }
                            else
                            {
                                //when recv complete***
                                Action<MySqlResult> tmpWhenRecvData = whenRecvData;
                                //delete recv handle **before** invoke it, and
                                //reset state to 'rest' state
                                this.whenRecvData = null;
                                this._workingState = WorkingState.Rest;
                                tmpWhenRecvData(result);
                            }
                        }
                        //--------------------------
                        if (needMoreData)
                        {
                            //so if it need more data then start receive next
                            recvIO.StartReceive();//***
                        }
                        else
                        {

                        }
                        //--------------------------
                    }
                    break;
            }
        }
        void HandleReceive(RecvEventCode recvEventCode)
        {
            switch (recvEventCode)
            {
                case RecvEventCode.SocketError:
                    {
                        UnBindSocket(true);
                    } break;
                case RecvEventCode.NoMoreReceiveData:
                    {
                        //no data to receive
                        httpResp.End();
                        //reqHandler(this.httpReq, httpResp);
                    } break;
                case RecvEventCode.HasSomeData:
                    {
                        //process some data
                        //there some data to process  
                        switch (httpReq.LoadData(recvIO))
                        {
                            case ProcessReceiveBufferResult.Complete:
                                {
                                    //recv and parse complete  
                                    //goto user action

                                    if (this.EnableWebSocket &&
                                        this.ownerServer.CheckWebSocketUpgradeRequest(this))
                                    {
                                        return;
                                    }

                                    reqHandler(this.httpReq, httpResp);
                                } break;
                            case ProcessReceiveBufferResult.NeedMore:
                                {
                                    recvIO.StartReceive();
                                } break;
                            case ProcessReceiveBufferResult.Error:
                            default:
                                throw new NotSupportedException();
                        }
                    } break;
            }
        }
        void HandleReceivedData(RecvEventCode recvCode)
        {
            switch (recvCode)
            {
                case RecvEventCode.HasSomeData:

                    //parse recv msg
                    switch (this.webSocketReqParser.ParseRecvData())
                    {
                        //in this version all data is copy into WebSocketRequest
                        //so we can reuse recv buffer 
                        //TODO: review this, if we need to copy?,  

                        case ProcessReceiveBufferResult.Complete:
                            {
                                //you can choose ...
                                //invoke webSocketReqHandler in this thread or another thread
                                while (webSocketReqParser.ReqCount > 0)
                                {
                                    WebSocketRequest req = webSocketReqParser.Dequeue();
                                    webSocketReqHandler(req, webSocketResp);
                                }
                                //start next recv
                                //byte[] newRecvBuffer = new byte[RECV_BUFF_SIZE];
                                //recvIO.StartReceive(newRecvBuffer, RECV_BUFF_SIZE);
                                recvIO.StartReceive();
                                //***no code after StartReceive***
                            }
                            return;
                        case ProcessReceiveBufferResult.NeedMore:
                            {
                                //start next recv
                                //byte[] newRecvBuffer = new byte[RECV_BUFF_SIZE];
                                //recvIO.StartReceive(newRecvBuffer, RECV_BUFF_SIZE);
                                recvIO.StartReceive();
                                //***no code after StartReceive***
                            }
                            return;
                        case ProcessReceiveBufferResult.Error:
                        default:
                            throw new NotSupportedException();
                    }

                case RecvEventCode.NoMoreReceiveData:
                    {
                    }
                    break;
                case RecvEventCode.SocketError:
                    {
                    }
                    break;
            }
        }
Пример #6
0
        void HandleReceive(RecvEventCode recvEventCode)
        {
            switch (recvEventCode)
            {
            default: throw new NotSupportedException();

            case RecvEventCode.SocketError:
            {
                UnBindSocket(true);
            }
            break;

            case RecvEventCode.NoMoreReceiveData:
            {
            }
            break;

            case RecvEventCode.HasSomeData:
            {
                //process some data
                //there some data to process
                //parse the data
#if DEBUG
                if (dbugPleaseBreak)
                {
                }
#endif

                bool needMoreData = _mysqlParserMx.ParseData(recvIO);
                //please note that: result packet may not ready in first round
                //but parser mx may 'release' some part of the result (eg. large table)
                MySqlResult result = _mysqlParserMx.ParseResult;         //'release' result
                //---------------------------------------------------------------
                if (result != null)
                {
                    //if we has some 'release' result from parser mx
                    if (needMoreData)
                    {
                        //this is 'partial result'
                        if (whenRecvData == null)
                        {
                            //?
                        }
                        //-------------------------
                        //partial release data here
                        //before recv next
                        //because we want to 'sync'
                        //the series of result
                        whenRecvData(result);
                        //-------------------------
                    }
                    else
                    {
                        //when recv complete***
                        Action <MySqlResult> tmpWhenRecvData = whenRecvData;
                        //delete recv handle **before** invoke it, and
                        //reset state to 'rest' state
                        this.whenRecvData  = null;
                        this._workingState = WorkingState.Rest;
                        tmpWhenRecvData(result);
                    }
                }
                //--------------------------
                if (needMoreData)
                {
                    //so if it need more data then start receive next
                    recvIO.StartReceive();        //***
                }
                else
                {
                }
                //--------------------------
            }
            break;
            }
        }