Exemple #1
0
 public void Start(AcceptMethod acceptor)
 {
     logger.Log("Starting server");
     foreach (Socket socket in sockets)
     {
         Task.Run(() => AcceptAll(socket, acceptor));
     }
 }
Exemple #2
0
 public NHContext(NHServerConnection c, Stream i, AcceptMethod a, ILogger l)
 {
     connection     = c;
     inputStream    = i;
     acceptor       = a;
     logger         = l;
     sequenceNumber = -1;
     request        = new NHServerRequest(this, logger);
     response       = new NHServerResponse(inputStream, this, logger);
 }
Exemple #3
0
        public NHServerConnection(NetworkStream s, EndPoint remoteEndpoint, Uri sA, AcceptMethod a, ILogger l)
        {
            stream          = s;
            networkEndpoint = remoteEndpoint;
            serverAddress   = sA;
            acceptor        = a;
            logger          = l;

            state               = State.Unknown;
            responseWaiters     = new LinkedList <Task <NHServerResponse> >();
            faulted             = false;
            outstandingRequests = 0;
            finished            = null;

            logger.Log("Got connection from " + remoteEndpoint);
        }
Exemple #4
0
 void AcceptAll(Socket socket, AcceptMethod acceptor)
 {
     try
     {
         while (true)
         {
             Socket connection = socket.Accept();
             Task.Run(() => HandleConnection(connection, acceptor));
         }
     }
     catch (Exception e)
     {
         // the server was stopped
         logger.Log("Caught exception " + e.Message);
         return;
     }
 }
Exemple #5
0
 async void HandleConnection(Socket connection, AcceptMethod acceptor)
 {
     try
     {
         using (NetworkStream stream = new NetworkStream(connection, true))
         {
             NHServerConnection connectionHandler =
                 new NHServerConnection(stream, connection.RemoteEndPoint, serverAddress, acceptor, logger);
             await connectionHandler.Run();
         }
     }
     catch (Exception e)
     {
         logger.Log("Got exception " + e.ToString());
         // the connection went away
     }
 }
Exemple #6
0
        public Yytoken yylex()
        {
            char yy_lookahead;
            int  yy_anchor            = YY_NO_ANCHOR;
            int  yy_state             = yy_state_dtrans[yy_lexical_state];
            int  yy_next_state        = YY_NO_STATE;
            int  yy_last_accept_state = YY_NO_STATE;
            bool yy_initial           = true;
            int  yy_this_accept;

            yy_mark_start();
            yy_this_accept = yy_acpt[yy_state];
            if (YY_NOT_ACCEPT != yy_this_accept)
            {
                yy_last_accept_state = yy_state;
                yy_mark_end();
            }
            while (true)
            {
                if (yy_initial && yy_at_bol)
                {
                    yy_lookahead = (char)YY_BOL;
                }
                else
                {
                    yy_lookahead = yy_advance();
                }
                yy_next_state = yy_nxt[yy_rmap[yy_state], yy_cmap[yy_lookahead]];
                if (YY_EOF == yy_lookahead && yy_initial)
                {
                    return(null);
                }
                if (YY_F != yy_next_state)
                {
                    yy_state       = yy_next_state;
                    yy_initial     = false;
                    yy_this_accept = yy_acpt[yy_state];
                    if (YY_NOT_ACCEPT != yy_this_accept)
                    {
                        yy_last_accept_state = yy_state;
                        yy_mark_end();
                    }
                }
                else
                {
                    if (YY_NO_STATE == yy_last_accept_state)
                    {
                        throw new System.ApplicationException("Lexical Error: Unmatched Input.");
                    }
                    else
                    {
                        yy_anchor = yy_acpt[yy_last_accept_state];
                        if (0 != (YY_END & yy_anchor))
                        {
                            yy_move_end();
                        }
                        yy_to_mark();
                        if (yy_last_accept_state < 0)
                        {
                            if (yy_last_accept_state < 20)
                            {
                                yy_error(YY_E_INTERNAL, false);
                            }
                        }
                        else
                        {
                            AcceptMethod m = accept_dispatch[yy_last_accept_state];
                            if (m != null)
                            {
                                Yytoken tmp = m();
                                if (tmp != null)
                                {
                                    return(tmp);
                                }
                            }
                        }
                        yy_initial           = true;
                        yy_state             = yy_state_dtrans[yy_lexical_state];
                        yy_next_state        = YY_NO_STATE;
                        yy_last_accept_state = YY_NO_STATE;
                        yy_mark_start();
                        yy_this_accept = yy_acpt[yy_state];
                        if (YY_NOT_ACCEPT != yy_this_accept)
                        {
                            yy_last_accept_state = yy_state;
                            yy_mark_end();
                        }
                    }
                }
            }
        }
Exemple #7
0
        public Token <Sym> GetNextToken()
        {
            char yy_lookahead;
            int  yy_anchor            = YY_NO_ANCHOR;
            int  yy_state             = yy_state_dtrans[yy_lexical_state];
            int  yy_next_state        = YY_NO_STATE;
            int  yy_last_accept_state = YY_NO_STATE;
            bool yy_initial           = true;
            int  yy_this_accept;

            yy_mark_start();
            yy_this_accept = yy_acpt[yy_state];
            if (YY_NOT_ACCEPT != yy_this_accept)
            {
                yy_last_accept_state = yy_state;
                yy_mark_end();
            }

            // begin_str

            while (true)
            {
                if (yy_initial && yy_at_bol)
                {
                    yy_lookahead = (char)YY_BOL;
                }
                else
                {
                    yy_lookahead = yy_advance();
                }

                yy_next_state = yy_nxt[yy_rmap[yy_state], yy_cmap[yy_lookahead]];

                // state_str

                if (YY_EOF == yy_lookahead && yy_initial)
                {
                    // EOF_Test()
                    return(Token.Eof <Sym>());
                }

                if (YY_F != yy_next_state)
                {
                    yy_state       = yy_next_state;
                    yy_initial     = false;
                    yy_this_accept = yy_acpt[yy_state];
                    if (YY_NOT_ACCEPT != yy_this_accept)
                    {
                        yy_last_accept_state = yy_state;
                        yy_mark_end();
                    }
                }
                else
                {
                    if (YY_NO_STATE == yy_last_accept_state)
                    {
                        throw new ApplicationException("Lexical Error: Unmatched Input.");
                    }
                    else
                    {
                        yy_anchor = yy_acpt[yy_last_accept_state];
                        if (0 != (YY_END & yy_anchor))
                        {
                            yy_move_end();
                        }

                        yy_to_mark();
                        if (yy_last_accept_state < 0)
                        {
                            if (yy_last_accept_state < 12) // spec.accept_list.Count
                            {
                                yy_error(YY_E_INTERNAL, false);
                            }
                        }
                        else
                        {
                            AcceptMethod m = accept_dispatch[yy_last_accept_state];
                            if (m != null)
                            {
                                var tmp = m(); // spec.type_name
                                if (tmp != Token.Epsilon <Sym>())
                                {
                                    return(tmp);
                                }
                            }
                        }

                        yy_initial           = true;
                        yy_state             = yy_state_dtrans[yy_lexical_state];
                        yy_next_state        = YY_NO_STATE;
                        yy_last_accept_state = YY_NO_STATE;
                        yy_mark_start();
                        yy_this_accept = yy_acpt[yy_state];
                        if (YY_NOT_ACCEPT != yy_this_accept)
                        {
                            yy_last_accept_state = yy_state;
                            yy_mark_end();
                        }
                    }
                }
            }
        }
Exemple #8
0
        internal CqlLexer.Token yylex()
        {
            char yy_lookahead;
            int  yy_anchor            = YY_NO_ANCHOR;
            int  yy_state             = yy_state_dtrans[yy_lexical_state];
            int  yy_next_state        = YY_NO_STATE;
            int  yy_last_accept_state = YY_NO_STATE;
            bool yy_initial           = true;
            int  yy_this_accept;

            yy_mark_start();
            yy_this_accept = yy_acpt[yy_state];
            if (YY_NOT_ACCEPT != yy_this_accept)
            {
                yy_last_accept_state = yy_state;
                yy_mark_end();
            }
            while (true)
            {
                if (yy_initial && yy_at_bol)
                {
                    yy_lookahead = (char)YY_BOL;
                }
                else
                {
                    yy_lookahead = yy_advance();
                }
                yy_next_state = yy_nxt[yy_rmap[yy_state], yy_cmap[yy_lookahead]];
                if (YY_EOF == yy_lookahead && yy_initial)
                {
                    return(null);
                }
                if (YY_F != yy_next_state)
                {
                    yy_state       = yy_next_state;
                    yy_initial     = false;
                    yy_this_accept = yy_acpt[yy_state];
                    if (YY_NOT_ACCEPT != yy_this_accept)
                    {
                        yy_last_accept_state = yy_state;
                        yy_mark_end();
                    }
                }
                else
                {
                    if (YY_NO_STATE == yy_last_accept_state)
                    {
                        throw new System.Data.EntitySqlException(EntitySqlException.GetGenericErrorMessage(_query, yychar));
                    }
                    else
                    {
                        yy_anchor = yy_acpt[yy_last_accept_state];
                        if (0 != (YY_END & yy_anchor))
                        {
                            yy_move_end();
                        }
                        yy_to_mark();
                        if (yy_last_accept_state < 0)
                        {
                            if (yy_last_accept_state < 85)
                            {
                                yy_error(YY_E_INTERNAL, false);
                            }
                        }
                        else
                        {
                            AcceptMethod m = accept_dispatch[yy_last_accept_state];
                            if (m != null)
                            {
                                CqlLexer.Token tmp = m();
                                if (tmp != null)
                                {
                                    return(tmp);
                                }
                            }
                        }
                        yy_initial           = true;
                        yy_state             = yy_state_dtrans[yy_lexical_state];
                        yy_next_state        = YY_NO_STATE;
                        yy_last_accept_state = YY_NO_STATE;
                        yy_mark_start();
                        yy_this_accept = yy_acpt[yy_state];
                        if (YY_NOT_ACCEPT != yy_this_accept)
                        {
                            yy_last_accept_state = yy_state;
                            yy_mark_end();
                        }
                    }
                }
            }
        }
Exemple #9
0
        public Token getNextToken()
        {
            char yy_lookahead;
            int  yy_anchor            = YY_NO_ANCHOR;
            int  yy_state             = yy_state_dtrans[yy_lexical_state];
            int  yy_next_state        = YY_NO_STATE;
            int  yy_last_accept_state = YY_NO_STATE;
            bool yy_initial           = true;
            int  yy_this_accept;

            yy_mark_start();
            yy_this_accept = yy_acpt[yy_state];
            if (YY_NOT_ACCEPT != yy_this_accept)
            {
                yy_last_accept_state = yy_state;
                yy_mark_end();
            }

            // begin_str

            while (true)
            {
                if (yy_initial && yy_at_bol)
                {
                    yy_lookahead = (char)YY_BOL;
                }
                else
                {
                    yy_lookahead = yy_advance();
                }

                yy_next_state = yy_nxt[yy_rmap[yy_state], yy_cmap[yy_lookahead]];

                // state_str

                if (YY_EOF == yy_lookahead && yy_initial)
                {
                    // EOF_Test()

                    if (commentStart != -1)
                    {
                        currentToken = new Token(commentStart, yychar + yytext().Length, TokenType.BadCharacter);
                        return(currentToken);
                    }

                    currentToken = new Token(yychar, yychar + yytext().Length, TokenType.Eof);
                    return(currentToken);
                }

                if (YY_F != yy_next_state)
                {
                    yy_state       = yy_next_state;
                    yy_initial     = false;
                    yy_this_accept = yy_acpt[yy_state];
                    if (YY_NOT_ACCEPT != yy_this_accept)
                    {
                        yy_last_accept_state = yy_state;
                        yy_mark_end();
                    }
                }
                else
                {
                    if (YY_NO_STATE == yy_last_accept_state)
                    {
                        throw new ApplicationException("Lexical Error: Unmatched Input.");
                    }
                    else
                    {
                        yy_anchor = yy_acpt[yy_last_accept_state];
                        if (0 != (YY_END & yy_anchor))
                        {
                            yy_move_end();
                        }

                        yy_to_mark();
                        if (yy_last_accept_state < 0)
                        {
                            if (yy_last_accept_state < 42) // spec.accept_list.Count
                            {
                                yy_error(YY_E_INTERNAL, false);
                            }
                        }
                        else
                        {
                            AcceptMethod m = accept_dispatch[yy_last_accept_state];
                            if (m != null)
                            {
                                Token tmp = m(); // spec.type_name
                                if (tmp != null)
                                {
                                    return(tmp);
                                }
                            }
                        }

                        yy_initial           = true;
                        yy_state             = yy_state_dtrans[yy_lexical_state];
                        yy_next_state        = YY_NO_STATE;
                        yy_last_accept_state = YY_NO_STATE;
                        yy_mark_start();
                        yy_this_accept = yy_acpt[yy_state];
                        if (YY_NOT_ACCEPT != yy_this_accept)
                        {
                            yy_last_accept_state = yy_state;
                            yy_mark_end();
                        }
                    }
                }
            }

            #endregion
        }
Exemple #10
0
 public void Start(AcceptMethod a)
 {
     accept = a;
     logger.Log("Starting system http server");
     server.GetContextAsync().ContinueWith(x => AcceptContext(x.Result));
 }