示例#1
0
文件: event.c 项目: kghost/lldpd
/* Initialize libevent and start the event loop */
void
levent_loop(struct lldpd *cfg)
{
	levent_init(cfg);
	lldpd_loop(cfg);

	/* libevent loop */
	do {
		if (event_base_got_break(cfg->g_base) ||
		    event_base_got_exit(cfg->g_base))
			break;
#ifdef USE_SNMP
		if (cfg->g_snmp) {
			/* We don't use delegated requests (request
			   whose answer is delayed). However, we keep
			   the call here in case we use it some
			   day. We don't call run_alarms() here. We do
			   it on timeout only. */
			netsnmp_check_outstanding_agent_requests();
			levent_snmp_update(cfg);
		}
#endif
	} while (event_base_loop(cfg->g_base, EVLOOP_ONCE) == 0);

#ifdef USE_SNMP
	if (cfg->g_snmp)
		agent_shutdown();
#endif /* USE_SNMP */

}
示例#2
0
void EventLoop::run()
{
    __in_event_loop__ = true;

    // Block SIGPIPE in the event loop because we can not force
    // underlying implementations such as SSL bufferevents to use
    // MSG_NOSIGNAL.
    SUPPRESS(SIGPIPE) {
        do {
            int result = event_base_loop(base, EVLOOP_ONCE);
            if (result < 0) {
                LOG(FATAL) << "Failed to run event loop";
            } else if (result > 0) {
                // All events are handled, continue event loop.
                continue;
            } else {
                CHECK_EQ(0, result);
                if (event_base_got_break(base)) {
                    break;
                } else if (event_base_got_exit(base)) {
                    break;
                }
            }
        } while (true);
    }

    __in_event_loop__ = false;
}
示例#3
0
/** Event dispatcher thread */
static bool ThreadHTTP(struct event_base* base, struct evhttp* http)
{
    RenameThread("bitcoin-http");
    LogPrint(BCLog::HTTP, "Entering http event loop\n");
    event_base_dispatch(base);
    // Event loop will be interrupted by InterruptHTTPServer()
    LogPrint(BCLog::HTTP, "Exited http event loop\n");
    return event_base_got_break(base) == 0;
}
示例#4
0
static void *server_loop(void *instance) {
    ad_server_t *server = (ad_server_t *)instance;

    int *retval = NEW_OBJECT(int);
    DEBUG("Loop start");
    event_base_loop(server->evbase, 0);
    DEBUG("Loop finished");
    *retval = (event_base_got_break(server->evbase)) ? -1 : 0;

    return retval;
}
示例#5
0
static void
thread_no_events(void *arg)
{
	THREAD_T thread;
	struct basic_test_data *data = arg;
	struct timeval starttime, endtime;
	int i;
	exit_base = data->base;

	memset(times,0,sizeof(times));
	for (i=0;i<5;++i) {
		event_assign(&time_events[i], data->base,
		    -1, 0, note_time_cb, &times[i]);
	}

	evutil_gettimeofday(&starttime, NULL);
	THREAD_START(thread, register_events_subthread, data->base);
	event_base_loop(data->base, EVLOOP_NO_EXIT_ON_EMPTY);
	evutil_gettimeofday(&endtime, NULL);
	tt_assert(event_base_got_break(data->base));
	THREAD_JOIN(thread);
	for (i=0; i<5; ++i) {
		struct timeval diff;
		double sec;
		evutil_timersub(&times[i], &starttime, &diff);
		sec = diff.tv_sec + diff.tv_usec/1.0e6;
		TT_BLATHER(("event %d at %.4f seconds", i, sec));
	}
	test_timeval_diff_eq(&starttime, &times[0], 100);
	test_timeval_diff_eq(&starttime, &times[1], 200);
	test_timeval_diff_eq(&starttime, &times[2], 400);
	test_timeval_diff_eq(&starttime, &times[3], 450);
	test_timeval_diff_eq(&starttime, &times[4], 500);
	test_timeval_diff_eq(&starttime, &endtime,  500);

end:
	;
}
示例#6
0
void EventLoop::run()
{
  __in_event_loop__ = true;

  do {
    int result = event_base_loop(base, EVLOOP_ONCE);
    if (result < 0) {
      LOG(FATAL) << "Failed to run event loop";
    } else if (result > 0) {
      // All events are handled, continue event loop.
      continue;
    } else {
      CHECK_EQ(0, result);
      if (event_base_got_break(base)) {
        break;
      } else if (event_base_got_exit(base)) {
        break;
      }
    }
  } while (true);

  __in_event_loop__ = false;
}