public HttpContext(
             WebServer ownerServer,
            int recvBufferSize,
            int sendBufferSize)
        {
            this.EnableWebSocket = true;
            this.ownerServer = ownerServer;
            //each recvSendArgs is created for this connection session only ***
            //---------------------------------------------------------------------------------------------------------- 
            KeepAlive = true;
            //set buffer for newly created saArgs
            ownerServer.SetBufferFor(this.recvSendArgs = new SocketAsyncEventArgs());
            recvIO = new RecvIO(recvSendArgs, recvSendArgs.Offset, recvBufferSize, HandleReceive);
            sendIO = new SendIO(recvSendArgs, recvSendArgs.Offset + recvBufferSize, sendBufferSize, HandleSend);
            //----------------------------------------------------------------------------------------------------------  
            httpReq = new HttpRequest(this);
            httpResp = new HttpResponse(this, sendIO);

            //common(shared) event listener***
            recvSendArgs.Completed += (object sender, SocketAsyncEventArgs e) =>
            {
                switch (e.LastOperation)
                {
                    case SocketAsyncOperation.Receive:                         
                        recvIO.ProcessReceivedData();
                        break;
                    case SocketAsyncOperation.Send:
                        sendIO.ProcessWaitingData();
                        break;
                    default:
                        throw new ArgumentException("The last operation completed on the socket was not a receive or send");
                }
            };
        }
        public WebSocketContext(WebSocketServer webSocketServer, ReqRespHandler<WebSocketRequest, WebSocketResponse> webSocketReqHandler)
        {
            this.webSocketReqHandler = webSocketReqHandler;
            this.webSocketServer = webSocketServer;
            connectionId = System.Threading.Interlocked.Increment(ref connectionIdTotal);
            //-------------------
            //send,resp 
            sockAsyncSender = new SocketAsyncEventArgs();
            sockAsyncSender.SetBuffer(new byte[RECV_BUFF_SIZE], 0, RECV_BUFF_SIZE); 
            sendIO = new SendIO(sockAsyncSender, 0, RECV_BUFF_SIZE, sendIO_SendCompleted);
            sockAsyncSender.Completed += new EventHandler<SocketAsyncEventArgs>((s, e) =>
            {
                switch (e.LastOperation)
                {
                    default:
                        {
                        }
                        break;
                    case SocketAsyncOperation.Send:
                        {
                            sendIO.ProcessWaitingData();
                        }
                        break;
                    case SocketAsyncOperation.Receive:
                        {
                        }
                        break;
                }
            });
            webSocketResp = new WebSocketResponse(this, sendIO);

            //------------------------------------------------------------------------------------
            //recv,req ,new socket
            sockAsyncListener = new SocketAsyncEventArgs();
            sockAsyncListener.SetBuffer(new byte[RECV_BUFF_SIZE], 0, RECV_BUFF_SIZE);
            recvIO = new RecvIO(sockAsyncListener, 0, RECV_BUFF_SIZE, HandleReceivedData);
            sockAsyncListener.Completed += new EventHandler<SocketAsyncEventArgs>((s, e) =>
            {
                switch (e.LastOperation)
                {
                    default:
                        {
                        }
                        break;
                    case SocketAsyncOperation.Send:
                        {
                        }
                        break;
                    case SocketAsyncOperation.Receive:
                        {
                            recvIO.ProcessReceivedData();
                        }
                        break;
                }
            });
            //------------------------------------------------------------------------------------             
            this.webSocketReqParser = new WebSocketProtocolParser(recvIO);

        }
        public Connection(ConnectionConfig userConfig)
        {
            config = userConfig;
            recvBufferSize = userConfig.recvBufferSize;
            sendBufferSize = userConfig.sendBufferSize;
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            //
            switch ((CharSets)config.charsetNumber)
            {
                case CharSets.UTF8_GENERAL_CI:
                    //_parser = new PacketParser(Encoding.UTF8);
                    _writer = new MySqlStreamWriter(Encoding.UTF8);
                    break;
                case CharSets.ASCII:
                    //_parser = new PacketParser(Encoding.ASCII);
                    _writer = new MySqlStreamWriter(Encoding.ASCII);
                    break;
                default:
                    throw new NotImplementedException();
            }

            //------------------
            //we share recvSendArgs between recvIO and sendIO
            //similar to simple http 
            //it is simple, (NOT  duplex like web socket)             
            //------------------
            recvSendArgs = new SocketAsyncEventArgs();
            recvSendArgs.SetBuffer(new byte[recvBufferSize + sendBufferSize], 0, recvBufferSize + sendBufferSize);
            recvIO = new RecvIO(recvSendArgs, recvSendArgs.Offset, recvBufferSize, HandleReceive);
            sendIO = new SendIO(recvSendArgs, recvSendArgs.Offset + recvBufferSize, sendBufferSize, HandleSend);
            //------------------
            //common(shared) event listener***
            recvSendArgs.Completed += (object sender, SocketAsyncEventArgs e) =>
            {
                switch (e.LastOperation)
                {
                    case SocketAsyncOperation.Receive:
                        recvIO.ProcessReceivedData();
                        break;
                    case SocketAsyncOperation.Send:
                        sendIO.ProcessWaitingData();
                        break;
                    default:
                        throw new ArgumentException("The last operation completed on the socket was not a receive or send");
                }
            };
            //------------------
            recvSendArgs.AcceptSocket = socket;
            _mysqlParserMx = new MySqlParserMx(config);

        }
 internal HttpResponse(HttpContext context, SendIO sendIO)
 {
     this.context = context;
     bodyMs = new MemoryStream();
     StatusCode = 200; //init
     this.sendIO = sendIO;
     this.ContentTypeCharSet = WebServers.TextCharSet.Utf8;
 }