Esempio n. 1
0
/* Return an array of symbols for supported backends */
static VALUE NIO_Selector_supported_backends(VALUE klass) {
    unsigned int backends = ev_supported_backends();
    VALUE result = rb_ary_new();

    if(backends & EVBACKEND_EPOLL) {
        rb_ary_push(result, ID2SYM(rb_intern("epoll")));
    }

    if(backends & EVBACKEND_POLL) {
        rb_ary_push(result, ID2SYM(rb_intern("poll")));
    }

    if(backends & EVBACKEND_KQUEUE) {
        rb_ary_push(result, ID2SYM(rb_intern("kqueue")));
    }

    if(backends & EVBACKEND_SELECT) {
        rb_ary_push(result, ID2SYM(rb_intern("select")));
    }

    if(backends & EVBACKEND_PORT) {
        rb_ary_push(result, ID2SYM(rb_intern("port")));
    }

    return result;
}
Esempio n. 2
0
/**
 * Initializes the networking interfaces
 * @arg config Takes the bloom server configuration
 * @arg mgr The filter manager to pass up to the connection handlers
 * @arg netconf Output. The configuration for the networking stack.
 */
int init_networking(statsite_config *config, statsite_networking **netconf_out) {
    // Initialize the netconf structure
    statsite_networking *netconf = calloc(1, sizeof(struct statsite_networking));
    netconf->config = config;

    /**
     * Check if we can use kqueue instead of select.
     * By default, libev will not use kqueue since it only
     * works for sockets, which is all we need.
     */
    int ev_mode = EVFLAG_AUTO;
    if (ev_supported_backends () & ~ev_recommended_backends () & EVBACKEND_KQUEUE) {
        ev_mode = EVBACKEND_KQUEUE;
    }

    if (!ev_default_loop (ev_mode)) {
        syslog(LOG_CRIT, "Failed to initialize libev!");
        free(netconf);
        return 1;
    }

    // Setup the stdin listener
    int res = setup_stdin_listener(netconf);
    if (res != 0) {
        free(netconf);
        return 1;
    }

    // Setup the TCP listener
    res = setup_tcp_listener(netconf);
    if (res != 0) {
        free(netconf);
        return 1;
    }

    // Setup the UDP listener
    res = setup_udp_listener(netconf);
    if (res != 0) {
        if (ev_is_active(&netconf->tcp_client)) {
            ev_io_stop(&netconf->tcp_client);
            close(netconf->tcp_client.fd);
        }
        free(netconf);
        return 1;
    }

    // Setup the timer
    ev_timer_init(&netconf->flush_timer, handle_flush_event, config->flush_interval, config->flush_interval);
    ev_timer_start(&netconf->flush_timer);

    // Prepare the conn handlers
    init_conn_handler(config);

    // Success!
    *netconf_out = netconf;
    return 0;
}
Esempio n. 3
0
/**
 * Initializes the networking interfaces
 * @arg config Takes the bloom server configuration
 * @arg mgr The filter manager to pass up to the connection handlers
 * @arg netconf Output. The configuration for the networking stack.
 */
int init_networking(bloom_config *config, bloom_filtmgr *mgr, bloom_networking **netconf_out) {
    // Make the netconf structure
    bloom_networking *netconf = calloc(1, sizeof(struct bloom_networking));

    // Initialize
    netconf->config = config;
    netconf->mgr = mgr;
    netconf->workers = calloc(config->worker_threads, sizeof(worker_ev_userdata*));
    if (!netconf->workers) {
        free(netconf);
        perror("Failed to calloc() for worker threads");
        return 1;
    }

    // Setup the barrier
    if (barrier_init(&netconf->thread_barrier, config->worker_threads + 1)) {
        free(netconf->workers);
        free(netconf);
        return 1;
    }

    /**
     * Check if we can use kqueue instead of select.
     * By default, libev will not use kqueue since it has
     * certain limitations that select doesn't, but which
     * we don't need.
     */
    int ev_mode = EVFLAG_AUTO;
    if (ev_supported_backends () & ~ev_recommended_backends () & EVBACKEND_KQUEUE) {
        ev_mode = EVBACKEND_KQUEUE;
    }
    netconf->ev_mode = ev_mode;

    if (!(netconf->default_loop = ev_loop_new (ev_mode))) {
        syslog(LOG_CRIT, "Failed to initialize libev!");
        free(netconf);
        return 1;
    }

    // Setup the TCP listener
    int res = setup_tcp_listener(netconf);
    if (res != 0) {
        free(netconf);
        return 1;
    }

    // Setup the UDP listener
    res = setup_udp_listener(netconf);
    if (res != 0) {
        ev_io_stop(netconf->default_loop, &netconf->tcp_client);
        close(netconf->tcp_client.fd);
        free(netconf);
        return 1;
    }

    // Prepare the conn handlers
    init_conn_handler();

    // Success!
    *netconf_out = netconf;
    return 0;
}
Esempio n. 4
0
/**
 * Initializes the networking interfaces
 * @arg config Takes the statsite_proxy server configuration
 * @arg netconf Output. The configuration for the networking stack.
 * @arg proxy Pointer to proxy for routing metrics via consistent hashing
 */
int init_networking(statsite_proxy_config *config, statsite_proxy_networking **netconf_out, proxy *proxy) {
    // Make the netconf structure
    statsite_proxy_networking *netconf = calloc(1, sizeof(struct statsite_proxy_networking));

    // Initialize
    netconf->events = NULL;
    netconf->config = config;
    netconf->proxy = proxy;
    netconf->should_run = 1;
    netconf->thread = NULL;

    /**
     * Check if we can use kqueue instead of select.
     * By default, libev will not use kqueue since it only
     * works for sockets, which is all we need.
     */
    int ev_mode = EVFLAG_AUTO;
    if (ev_supported_backends () & ~ev_recommended_backends () & EVBACKEND_KQUEUE) {
        ev_mode = EVBACKEND_KQUEUE;
    }

    if (!ev_default_loop (ev_mode)) {
        syslog(LOG_CRIT, "Failed to initialize libev!");
        free(netconf);
        return 1;
    }

    // Setup proxy connections
    int proxy_res = setup_proxy_connections(netconf);
    if (proxy_res != 0) {
    	// free proxy connections stuff
    	free(netconf);
    	return 1;
    }

    // Setup the TCP listener
    int res = setup_tcp_listener(netconf);
    if (res != 0) {
        free(netconf);
        return 1;
    }

    // Setup the UDP listener
    res = setup_udp_listener(netconf);
    if (res != 0) {
        ev_io_stop(&netconf->tcp_client);
        close(netconf->tcp_client.fd);
        free(netconf);
        return 1;
    }

    // Setup the async handler
    ev_async_init(&netconf->loop_async, handle_async_event);
    ev_async_start(&netconf->loop_async);

    // Prepare the conn handlers
    init_conn_handler(config);

    // Success!
    *netconf_out = netconf;
    return 0;
}
Esempio n. 5
0
File: pyev.c Progetto: Spencerx/pyev
static PyObject *
pyev_supported_backends(PyObject *module)
{
    return PyInt_FromUnsignedLong(ev_supported_backends());
}