示例#1
0
文件: lwan.c 项目: lpereira/lwan
static int
accept_connection_coro(struct coro *coro, void *data)
{
    struct lwan *l = data;
    uint64_t cores = 0;

    while (coro_yield(coro, 1) & ~(EPOLLHUP | EPOLLRDHUP | EPOLLERR)) {
        enum herd_accept ha;

        do {
            ha = accept_one(l, &cores);
        } while (ha == HERD_MORE);

        if (UNLIKELY(ha > HERD_MORE))
            break;

        if (LIKELY(cores)) {
            for (unsigned short t = 0; t < l->thread.count; t++) {
                if (cores & UINT64_C(1)<<t)
                    lwan_thread_nudge(&l->thread.threads[t]);
            }

            cores = 0;
        }
    }

    return 0;
}
示例#2
0
文件: lwan.c 项目: dreamsxin/lwan
void
lwan_main_loop(struct lwan *l)
{
    uint64_t cores = 0;

    assert(main_socket == -1);
    main_socket = l->main_socket;
    if (signal(SIGINT, sigint_handler) == SIG_ERR)
        lwan_status_critical("Could not set signal handler");

    lwan_status_info("Ready to serve");

    while (LIKELY(main_socket >= 0)) {
        if (UNLIKELY(accept_herd(l, &cores) == HERD_SHUTDOWN))
            break;

        if (LIKELY(cores)) {
            for (unsigned short t = 0; t < l->thread.count; t++) {
                if (cores & 1ULL<<t)
                    lwan_thread_nudge(&l->thread.threads[t]);
            }

            cores = 0;
        }
    }
}