コード例 #1
0
ファイル: backend.c プロジェクト: Hobbitron/tmi2_fluffos_v3
void backend()
{
    struct timeval timeout;
    int i, nb;
    volatile int first_call = 1;
    int there_is_a_port = 0;
    error_context_t econ;

    debug_message("Initializations complete.\n\n");
    for (i = 0; i < 5; i++) {
        if (external_port[i].port) {
            debug_message("Accepting connections on port %d.\n",
                    external_port[i].port);
            there_is_a_port = 1;
        }
    }

    if (!there_is_a_port)
        debug_message("No external ports specified.\n");

    init_user_conn();   /* initialize user connection socket */
#ifdef SIGHUP
    signal(SIGHUP, startshutdownMudOS);
#endif
    clear_state();
    save_context(&econ);
    if (SETJMP(econ.context))
        restore_context(&econ);
    if (!t_flag && first_call) {
        first_call = 0;
        call_heart_beat();
    }

    while (1) {
        /* Has to be cleared if we jumped out of process_user_command() */
        current_interactive = 0;
        set_eval(max_cost);

        if (obj_list_replace || obj_list_destruct)
            remove_destructed_objects();

        /*
         * shut down MudOS if MudOS_is_being_shut_down is set.
         */
        if (MudOS_is_being_shut_down)
            shutdownMudOS(0);
        if (slow_shut_down_to_do) {
            int tmp = slow_shut_down_to_do;

            slow_shut_down_to_do = 0;
            slow_shut_down(tmp);
        }
        /*
         * select
         */
        make_selectmasks();
        timeout.tv_sec = 1;
        timeout.tv_usec = 0;
#ifndef hpux
        nb = select(FD_SETSIZE, &readmask, &writemask, (fd_set *) 0, &timeout);
#else
        nb = select(FD_SETSIZE, (int *) &readmask, (int *) &writemask,
                (int *) 0, &timeout);
#endif
        /*
         * process I/O if necessary.
         */
        if (nb > 0) {
            process_io();
        }
        /*
         * process user commands.
         */
        for (i = 0; process_user_command() && i < max_users; i++)
            ;

        /*
         * call outs
         */
        call_out();
#ifdef PACKAGE_ASYNC
        check_reqs();
#endif
    }
}       /* backend() */
コード例 #2
0
ファイル: backend.c プロジェクト: lnsoso/mudos_with_mysql
void backend()
{
    struct timeval timeout;
    int i, nb;
    volatile int first_call = 1;
    int there_is_a_port = 0;
    error_context_t econ;

    debug_message("Initializations complete.\n\n");
    for (i = 0; i < 5; i++) {
	if (external_port[i].port) {
	    debug_message("Accepting connections on port %d.\n",
		    external_port[i].port);
	    there_is_a_port = 1;
	}
    }

    if (!there_is_a_port)
	debug_message("No external ports specified.\n");

    init_user_conn();		/* initialize user connection socket */
#ifdef SIGHUP
    signal(SIGHUP, startshutdownMudOS);
#endif
    clear_state();
    save_context(&econ);
    if (SETJMP(econ.context))
	restore_context(&econ);
    if (!t_flag && first_call) {
	first_call = 0;
	call_heart_beat();
    }

    while (1) {	
	/* Has to be cleared if we jumped out of process_user_command() */
	current_interactive = 0;
	eval_cost = max_cost;

	if (obj_list_replace || obj_list_destruct)
	    remove_destructed_objects();

	/*
	 * shut down MudOS if MudOS_is_being_shut_down is set.
	 */
	if (MudOS_is_being_shut_down)
	    shutdownMudOS(0);
	if (slow_shut_down_to_do) {
	    int tmp = slow_shut_down_to_do;

	    slow_shut_down_to_do = 0;
	    slow_shut_down(tmp);
	}
	/*
	 * select
	 */
	make_selectmasks();
	if (heart_beat_flag) {	/* use zero timeout if a heartbeat is
				 * pending. */
	    timeout.tv_sec = 0;	/* this should avoid problems with longjmp's
				 * too */
	    timeout.tv_usec = 0;
	} else {
	    /*
	     * not using infinite timeout so that we'll have insurance in the
	     * unlikely event a heartbeat happens between now and the
	     * select(). Note that SIGALRMs (for heartbeats) do make select()
	     * drop through. (Except on Windows)
	     */
#ifdef WIN32
	    timeout.tv_sec = HEARTBEAT_INTERVAL/1000000;
	    timeout.tv_usec = HEARTBEAT_INTERVAL%1000000;
#else
	    timeout.tv_sec = 60;
	    timeout.tv_usec = 0;
#endif
	}
#ifndef hpux
	nb = select(FD_SETSIZE, &readmask, &writemask, (fd_set *) 0, &timeout);
#else
	nb = select(FD_SETSIZE, (int *) &readmask, (int *) &writemask,
		    (int *) 0, &timeout);
#endif
	/*
	 * process I/O if necessary.
	 */
	if (nb > 0) {
	    process_io();
	}
	/*
	 * process user commands.
	 */
	for (i = 0; process_user_command() && i < max_users; i++)
	    ;

	/*
	 * call heartbeat if appropriate.
	 */
	if (heart_beat_flag)
	    call_heart_beat();
    }
}				/* backend() */