Exemple #1
0
void worker_main(int _worker_n)
{
    worker_n = _worker_n;
    attach_on_exit(on_exit_handler);

    if(is_daemon == 1 && !getarg("gcore")) {
        set_process_user(/*user*/ NULL, /*group*/ NULL);
    }

    if(!init_ntoa_cache() || !init_access_cache()) {
        LOGF(ERR, "Couldn't init rbtree");
        exit(1);
    }

    init_mime_types();
    shm_serv_status = _shm_serv_status->p;

    if(luaL_loadfile(_L, "core.lua")) {
        LOGF(ERR, "Couldn't load file: %s", lua_tostring(_L, -1));
        exit(1);
    }

    int mrkey = luaL_ref(_L, LUA_REGISTRYINDEX);

    lua_pushstring(_L, "__main");
    lua_rawgeti(_L, LUA_REGISTRYINDEX, mrkey);
    lua_rawset(_L, LUA_GLOBALSINDEX);

    int thread_count = 1000;

    if(getarg("thread")) {
        thread_count = atoi(getarg("thread"));

        if(thread_count < 100) {
            thread_count = 100;

        } else if(thread_count > 10000) {
            thread_count = 10000;
        }
    }

    init_lua_threads(_L, thread_count);

    /// 进入 loop 处理循环
    loop_fd = se_create(4096);
    set_loop_fd(loop_fd, _worker_n); // for coevent module
    se_accept(loop_fd, server_fd, be_accept);

    if(ssl_server_fd > 0) {
        se_accept(loop_fd, ssl_server_fd, be_ssl_accept);
    }

    se_loop(loop_fd, 10, other_simple_jobs); // loop

    exit(0);
}
Exemple #2
0
void network_worker ( void *_process_func, int process_count, int process_at )
{
    if ( sizeof ( epdata_t ) != 4096 ) {
        printf ( "warning sizof(epdata_t) = %ld\n", sizeof ( epdata_t ) );    // must be 4096
    }

    signal ( SIGPIPE, SIG_IGN );

    _shm_serv_status = shm_malloc ( sizeof ( serv_status_t ) );

    if ( _shm_serv_status == NULL ) {
        perror ( "shm malloc failed\n" );
        signal ( SIGHUP, SIG_IGN );
        exit ( 1 );
    }

    shm_serv_status = _shm_serv_status->p;
    memcpy ( shm_serv_status, &serv_status, sizeof ( serv_status_t ) );

    process_func = _process_func;

    init_mime_types();

    loop_fd = se_create ( EPD_POOL_SIZE );
    set_loop_fd ( loop_fd, process_count );

    se_ptr_t *se = se_add ( loop_fd, server_fd, NULL );

    se_be_read ( se, network_be_accept );

    while ( 1 ) {

        se_loop ( loop_fd, EPOLL_WAITOUT, without_jobs );

        if ( checkProcessForExit() || has_error_for_exit ) {
            break;
        }
    }
}