Beispiel #1
0
void uv__loop_delete(uv_loop_t* loop) {
  uv__signal_loop_cleanup(loop);
  uv__platform_loop_delete(loop);
  ev_loop_destroy(loop->ev);

  if (loop->async_pipefd[0] != -1) {
    close(loop->async_pipefd[0]);
    loop->async_pipefd[0] = -1;
  }

  if (loop->async_pipefd[1] != -1) {
    close(loop->async_pipefd[1]);
    loop->async_pipefd[1] = -1;
  }

  if (loop->emfile_fd != -1) {
    close(loop->emfile_fd);
    loop->emfile_fd = -1;
  }

  uv_mutex_lock(&loop->wq_mutex);
  assert(ngx_queue_empty(&loop->wq) && "thread pool work queue not empty!");
  uv_mutex_unlock(&loop->wq_mutex);
  uv_mutex_destroy(&loop->wq_mutex);
}
Beispiel #2
0
/**
 * Shuts down all the connections
 * and listeners and prepares to exit.
 * @arg netconf The config for the networking stack.
 * @arg threads A list of worker threads
 */
int shutdown_networking(bloom_networking *netconf, pthread_t *threads) {
    // Stop listening for new connections
    ev_io_stop(netconf->default_loop, &netconf->tcp_client);
    ev_io_stop(netconf->default_loop, &netconf->udp_client);
    close(netconf->tcp_client.fd);
    close(netconf->udp_client.fd);

    // Tell the threads to quit, async signal
    for (int i=0; i < netconf->config->worker_threads; i++) {
        write(netconf->workers[i]->pipefd[1], "q", 1);
    }

    // Wait for the threads to return
    pthread_t thread;
    for (int i=0; i < netconf->config->worker_threads; i++) {
        thread = threads[i];
        if (thread) pthread_join(thread, NULL);
    }

    // TODO: Close all the client connections
    // ??? For now, we just leak the memory
    // since we are shutdown down anyways...

    // Shutdown the event loo
    ev_loop_destroy(netconf->default_loop);

    // Free the netconf
    free(netconf->workers);
    free(netconf);
    return 0;
}
Beispiel #3
0
void test_libev_timer (void)
{
    struct ev_loop *loop;
    ev_timer w;
    int i;

    ok ((loop = ev_loop_new (EVFLAG_AUTO)) != NULL,
        "ev_loop_new works");
    ok (ev_run (loop, 0) == 0,
        "ev_run returns 0 with no watchers configured");

    ev_timer_init (&w, timer_cb, 1E-1, 0.);
    ev_timer_start (loop, &w);
    ok (ev_run (loop, 0) == 0,
        "ev_run returns 0 after no-repeat timer fires once");
    ev_timer_stop (loop, &w);

    i = 0;
    ev_timer_init (&w, timer_arg_cb, 1E-1, 0.);
    w.data = &i;
    ev_timer_start (loop, &w);
    ok (ev_run (loop, 0) == 0 && i == 1,
        "passing arbitrary data using w->data works");
    ev_timer_stop (loop, &w);

    i = 0;
    ev_timer_init (&w, timer_arg_cb, 1E-3, 1E-3);
    w.data = &i;
    ev_timer_start (loop, &w);
    ok (ev_run (loop, 0) != 0 && i == 100,
        "ev_break causes ev_run to return nonzero");
    ev_timer_stop (loop, &w);

    ev_loop_destroy (loop);
}
/**
 * Shuts down all the connections
 * and listeners and prepares to exit.
 * @arg netconf The config for the networking stack.
 */
int shutdown_networking(statsite_proxy_networking *netconf) {
    // Instruct the threads to shutdown
    netconf->should_run = 0;

    // Break the EV loop
    schedule_async(netconf, EXIT, NULL);

    // Wait for the thread to return
    if (netconf->thread) pthread_join(netconf->thread, NULL);

    // Stop listening for new connections
    ev_io_stop(&netconf->tcp_client);
    close(netconf->tcp_client.fd);
    ev_io_stop(&netconf->udp_client);
    close(netconf->udp_client.fd);

    // Stop the other timers
    ev_async_stop(&netconf->loop_async);

    // TODO: Close all the client/proxy connections
    // ??? For now, we just leak the memory
    // since we are shutdown down anyways...

    // Free the event loop
    ev_loop_destroy(EV_DEFAULT);

    // Free the netconf
    free(netconf);
    return 0;
}
Beispiel #5
0
/* timer adds zmsgs to zlist, then stops reactor after 100.
 */
void test_ev_zlist (void)
{
    struct ev_loop *loop;
    ev_zlist list_w;
    ev_timer timer_w;
    zlist_t *l;
    zmsg_t *zmsg;

    ok ((loop = ev_loop_new (EVFLAG_AUTO)) != NULL,
        "ev_loop_new works");

    if (!(l = zlist_new ()) || !(zmsg = zmsg_new ())
                            || zlist_append (l, zmsg) < 0)
        oom ();

    ev_zlist_init (&list_w, list_cb, l, EV_READ);
    ev_timer_init (&timer_w, list_timer_cb, 1E-3, 1E-3);
    timer_w.data = l;
    ev_zlist_start (loop, &list_w);
    ev_timer_start (loop, &timer_w);
    ok (ev_run (loop, 0) != 0 && zlist_size (l) == 0,
        "ev_zlist handler ran 100 times");
    ev_zlist_stop (loop, &list_w);
    ev_timer_stop (loop, &timer_w);

    if (l)
        zlist_destroy (&l);
    ev_loop_destroy (loop);
}
Beispiel #6
0
void net_mgr_free(net_mgr_t nmgr) {
    net_chanel_t chanel;

    assert(nmgr);

    /*free connectors*/
    net_connectors_free(nmgr);
    cpe_hash_table_fini(&nmgr->m_connectors);

    /*free listeners*/
    net_listeners_free(nmgr);
    cpe_hash_table_fini(&nmgr->m_listeners);

    /*free eps*/
    net_ep_pages_free(nmgr);
    cpe_range_mgr_fini(&nmgr->m_ep_ids);

    /*free event loop*/
    ev_loop_destroy(nmgr->m_ev_loop);
    nmgr->m_ev_loop = NULL;

    /*TODO*/
    while((chanel = TAILQ_FIRST(&nmgr->m_chanels))) {
        net_chanel_free(chanel);
    }

    mem_free(nmgr->m_alloc, nmgr);
}
Beispiel #7
0
void test_libev_io (void)
{
    struct ev_loop *loop;
    ev_io w, w2;
    int i, fd, fd2;

    ok ((loop = ev_loop_new (EVFLAG_AUTO)) != NULL,
        "ev_loop_new works");

    /* handle 100 read events from /dev/zero with two workers */
    fd = open ("/dev/zero", O_RDONLY);
    fd2 = open ("/dev/zero", O_RDONLY);
    ok (fd >= 0 && fd2 >= 0,
        "opened /dev/zero twice");

    i = 0;
    ev_io_init (&w, zero_cb, fd, EV_READ);
    w.data = &i;
    ev_io_init (&w2, zero_cb, fd2, EV_READ);
    w2.data = &i;
    ev_io_start (loop, &w);
    ev_io_start (loop, &w2);
    ok (ev_run (loop, 0) != 0 && i == 100,
        "ev_run ran two /dev/zero readers a total of 100 times");
    ev_io_stop (loop, &w);
    ev_io_stop (loop, &w2);

    close (fd);
    close (fd2);

    ev_loop_destroy (loop);
}
static void *thread(void *unused)
{
    struct ev_loop *loop = ev_loop_new(0);
    struct upump_mgr *upump_mgr =
        upump_ev_mgr_alloc(loop, UPUMP_POOL, UPUMP_BLOCKER_POOL);
    assert(upump_mgr != NULL);

    struct upipe *upipe;
    upipe = upipe_void_alloc(&uprobe_test_mgr, uprobe_use(uprobe));
    assert(upump_mgr_get_opaque(upump_mgr, struct upipe *) == NULL);
    uprobe_test_free(upipe);

    uprobe_pthread_upump_mgr_set(uprobe, upump_mgr);
    upipe = upipe_void_alloc(&uprobe_test_mgr, uprobe_use(uprobe));
    assert(upump_mgr_get_opaque(upump_mgr, struct upipe *) == upipe);
    uprobe_test_free(upipe);
    upump_mgr_set_opaque(upump_mgr, NULL);

    uprobe_throw(uprobe, NULL, UPROBE_FREEZE_UPUMP_MGR);
    upipe = upipe_void_alloc(&uprobe_test_mgr, uprobe_use(uprobe));
    assert(upump_mgr_get_opaque(upump_mgr, struct upipe *) == NULL);
    uprobe_test_free(upipe);

    uprobe_throw(uprobe, NULL, UPROBE_THAW_UPUMP_MGR);
    upipe = upipe_void_alloc(&uprobe_test_mgr, uprobe_use(uprobe));
    assert(upump_mgr_get_opaque(upump_mgr, struct upipe *) == upipe);
    uprobe_test_free(upipe);

    upump_mgr_release(upump_mgr);
    ev_loop_destroy(loop);
    return NULL;
}
Beispiel #9
0
/**
 * Shuts down all the connections
 * and listeners and prepares to exit.
 * @arg netconf The config for the networking stack.
 */
int shutdown_networking(statsite_networking *netconf) {
    // Stop listening for new connections
    if (ev_is_active(&netconf->tcp_client)) {
        ev_io_stop(&netconf->tcp_client);
        close(netconf->tcp_client.fd);
    }
    if (ev_is_active(&netconf->udp_client)) {
        ev_io_stop(&netconf->udp_client);
        close(netconf->udp_client.fd);
    }
    if (netconf->stdin_client != NULL) {
        close_client_connection(netconf->stdin_client);
        netconf->stdin_client = NULL;
    }

    // Stop the other timers
    ev_timer_stop(&netconf->flush_timer);

    // TODO: Close all the client connections
    // ??? For now, we just leak the memory
    // since we are shutdown down anyways...

    // Free the event loop
    ev_loop_destroy(EV_DEFAULT);

    // Free the netconf
    free(netconf);
    return 0;
}
static void*
as_ev_worker(void* udata)
{
	struct ev_loop* loop = udata;
	ev_loop(loop, 0);
	ev_loop_destroy(loop);
	return NULL;
}
Beispiel #11
0
int delete_ev_loop(ev_loop_s* ev_loop_s_ptr)
{
    g_maxfd = 0;
    if(ev_loop_s_ptr)
    {
        ev_loop_destroy(ev_loop_s_ptr->ev_loop_ptr);
    }
}
Beispiel #12
0
spx_private err_t spx_thread_context_free(void **arg){/*{{{*/
    struct spx_thread_context **tc = (struct spx_thread_context **) arg;
    ev_break((*tc)->loop,EVBREAK_ALL);
    ev_loop_destroy((*tc)->loop);
    SpxClose((*tc)->pipe[0]);
    SpxClose((*tc)->pipe[1]);
    SpxFree(*tc);
    return 0;
}/*}}}*/
Beispiel #13
0
/**
 * Entry point for threads to join the networking
 * stack. This method blocks indefinitely until the
 * network stack is shutdown.
 * @arg netconf The configuration for the networking stack.
 */
void start_networking_worker(bloom_networking *netconf) {
    // Allocate our user data
    worker_ev_userdata data;
    data.netconf = netconf;

    // Allocate our pipe
    if (pipe(data.pipefd)) {
        perror("failed to allocate worker pipes!");
        return;
    }

    // Create the event loop
    if (!(data.loop = ev_loop_new(netconf->ev_mode))) {
        syslog(LOG_ERR, "Failed to create event loop for worker!");
        return;
    }

    // Set the user data to be for this thread
    ev_set_userdata(data.loop, &data);

    // Setup the pipe listener
    ev_io_init(&data.pipe_client, handle_worker_notification,
                data.pipefd[0], EV_READ);
    ev_io_start(data.loop, &data.pipe_client);

    // Setup the periodic timers,
    ev_timer_init(&data.periodic, handle_periodic_timeout,
                PERIODIC_TIME_SEC, 1);
    ev_timer_start(data.loop, &data.periodic);

    // Syncronize until netconf->threads is available
    barrier_wait(&netconf->thread_barrier);

    // Register this thread so we can accept connections
    assert(netconf->threads);
    pthread_t id = pthread_self();
    for (int i=0; i < netconf->config->worker_threads; i++) {
        if (pthread_equal(id, netconf->threads[i])) {
            // Provide a pointer to our data
            netconf->workers[i] = &data;
            break;
        }
    }

    // Wait for everybody to be registered
    barrier_wait(&netconf->thread_barrier);

    // Run the event loop
    ev_run(data.loop, 0);

    // Cleanup after exit
    ev_timer_stop(data.loop, &data.periodic);
    ev_io_stop(data.loop, &data.pipe_client);
    close(data.pipefd[0]);
    close(data.pipefd[1]);
    ev_loop_destroy(data.loop);
}
Beispiel #14
0
void fiber_event_destroy()
{
    fiber_spinlock_lock(&fiber_loop_spinlock);
    if(fiber_loop) {
        ev_loop_destroy(fiber_loop);
        fiber_loop = NULL;
    }
    fiber_spinlock_unlock(&fiber_loop_spinlock);
}
Beispiel #15
0
void event_base_free (struct event_base *base)
{
  dLOOPbase;

#if EV_MULTIPLICITY
  if (ev_default_loop (EVFLAG_AUTO) != loop)
    ev_loop_destroy (loop);
#endif
}
Beispiel #16
0
spx_private err_t spx_nio_thread_context_free(void **arg){
    struct spx_nio_thread_context **context = (struct spx_nio_thread_context **) arg;
    ev_break((*context)->loop,EVBREAK_ALL);
    ev_loop_destroy((*context)->loop);
    SpxClose((*context)->pipe[0]);
    SpxClose((*context)->pipe[1]);
    SpxFree(*context);
    return 0;
}
Beispiel #17
0
static int loop_destroy(lua_State *L) {
    loop_t *lo = get_loop(L, 1);
    struct ev_loop* loop = lo->loop;
    if(loop) {
        lo->loop = 0;
        ev_loop_destroy(loop);
    }
    return 0;
}
Beispiel #18
0
void event_base_free (struct event_base *base)
{
  dLOOPbase;

#if EV_MULTIPLICITY
  if (!ev_is_default_loop (loop))
    ev_loop_destroy (loop);
#endif
}
Beispiel #19
0
static void lcb_destroy_io_opts(struct lcb_io_opt_st *iops)
{
    struct libev_cookie *io_cookie = iops->v.v2.cookie;
    if (io_cookie->allocated) {
        ev_loop_destroy(io_cookie->loop);
    }
    free(io_cookie);
    free(iops);
}
Beispiel #20
0
static void Coolio_Loop_free(struct Coolio_Loop *loop)
{
  if(!loop->ev_loop)
    return;

  ev_loop_destroy(loop->ev_loop);

  xfree(loop->eventbuf);
  xfree(loop);
}
static void
foreign_event_loop_cleanup_libev(void)
{
	/* cleanup the foreign loop assets */

	ev_timer_stop(loop_ev, &timer_outer_ev);
	ev_signal_stop(loop_ev, &sighandler_ev);

	ev_run(loop_ev, UV_RUN_DEFAULT);
	ev_loop_destroy(loop_ev);
}
Beispiel #22
0
int main(int argc ,char** argv)
{
 thread_init();
 int listen;
 listen=socket_init();
 ev_io_init(&(dispatcher_thread.accept_watcher), accept_callback,listen, EV_READ);
 ev_io_start(dispatcher_thread.loop,&(dispatcher_thread.accept_watcher)); 
 ev_loop(dispatcher_thread.loop,0);
 ev_loop_destroy(dispatcher_thread.loop);
 return 0;
}
Beispiel #23
0
void CBStartEventLoop(void * vloop){
	CBEventLoop * loop = vloop;
	CBLogVerbose("Starting network event loop.");
	// Start event loop
	ev_run(loop->base, 0);
	// Break from loop. Free everything.
	ev_loop_destroy(loop->base);
	free(loop->userEvent);
	CBFreeCallbackQueue(&loop->queue);
	CBFreeThread(loop->loopThread);
	free(loop);
}
Beispiel #24
0
/** @todo Figure out what to do with default vs. regular loops. --rue */
Loop::~Loop() {
    if(owner) {
        std::vector<Event*>::iterator it;
        for(it = events.begin(); it != events.end(); it = events.erase(it)) {
            delete *it;
        }

        if(base != ev_default_loop(0)) {
            ev_loop_destroy(base);
        }
    }
}
Beispiel #25
0
RLServer::~RLServer(){
    if(db_num<1){
        leveldb_close(db[0]);
    }else{
        for(int i=0;i<db_num;i++){
            leveldb_close(db[i]);
        }
    }
    delete[] db;
    if(loop) ev_loop_destroy(loop);
    close(fd);
}
Beispiel #26
0
Loop::~Loop()
{
    if (nullptr != _loop) {
        for (auto & io : _ios) {
            if (!io->sio.expired()) {
                ev_io_stop(_loop, &io->eio);
            }
        }
        SLOG(INFO) << "quit now!";
        ev_loop_destroy(_loop);
    }
}
Beispiel #27
0
void uv_loop_delete(uv_loop_t* loop) {
  uv_ares_destroy(loop, loop->channel);
  ev_loop_destroy(loop->ev);
  uv__loop_platform_delete(loop);
#ifndef NDEBUG
  memset(loop, -1, sizeof *loop);
#endif
  if (loop == default_loop_ptr)
    default_loop_ptr = NULL;
  else
    free(loop);
}
Beispiel #28
0
/* LoopType.tp_dealloc */
static void
Loop_tp_dealloc(Loop *self)
{
    Loop_tp_clear(self);
    if (self->loop) {
        if (ev_is_default_loop(self->loop)) {
            DefaultLoop = NULL;
        }
        ev_loop_destroy(self->loop);
    }
    Py_TYPE(self)->tp_free((PyObject *)self);
}
Beispiel #29
0
static void reactor_usecount_decr (flux_reactor_t *r)
{
    if (r && --r->usecount == 0) {
        if (r->loop) {
            if (ev_is_default_loop (r->loop))
                ev_default_destroy ();
            else
                ev_loop_destroy (r->loop);
        }
        free (r);
    }
}
Beispiel #30
0
int main()
{
    struct ev_loop* reactor=ev_loop_new(EVFLAG_AUTO);
    int fd=common::new_tcp_server(34567);
    ev_io w;
    ev_io_init(&w,do_accept,fd,EV_READ);
    ev_io_start(reactor,&w);
    cm_printf("ev run!\n");
    ev_run(reactor,0);
    cm_printf("close socket %d;\n", fd);
    close(fd);
    ev_loop_destroy(reactor);
}