Example #1
0
int setupListeners()
{
  evthread_use_pthreads();
  evBase = event_base_new();
  const char **methods = event_get_supported_methods();
  lprintf("Starting Libevent %s. Supported methods are:\n",
      event_get_version());
  for (int i=0;methods[i] != NULL; i++){
    lprintf("\t%s\n",methods[i]);
  }
  free((char**)methods);
  lprintf("Using %s.\n",event_base_get_method(evBase));

  struct event *signalEvent;
  signalEvent = evsignal_new(evBase, SIGINT, signalCallback, (void*) evBase);
  if (!signalEvent || event_add(signalEvent, NULL) < 0){
    lprintf("Could not create / add a signal event!\n");
    return -1;
  }
  lprintf("done\n");

  try{
    contConnection = new ControllerLink();
    mtc = new MTCModel();
    for (int i=0;i<MAX_XL3_CON;i++){
      xl3s[i] = new XL3Model(i);
    }
    tubii = new TUBIIModel();
  }
  catch(int e){
    return -1;
  }

  return 0;
}
Example #2
0
EventBase::EventBase(const char* method)
{
    // enable locking for libevent structure
    if (evthread_use_pthreads())
    {
        throw std::exception();
    }

#ifdef DEBUG
    evthread_enable_lock_debuging();
    event_enable_debug_mode();
#endif

    struct event_config *config;
    config = event_config_new();

    int i = 0;
    const char** availMethods = event_get_supported_methods();

    for (i = 0; availMethods[i] != NULL; i++)
    {
        if (strcmp(availMethods[i], method)) {
            event_config_avoid_method(config, availMethods[i]);
        }
    }
    base_ = event_base_new_with_config(config);

    if (!base_)
    {
        throw BadBaseException();
    }
    event_base_get_method(base_);
    event_config_free(config);
}
Example #3
0
File: main.c Project: nexie/ed2kd
static void display_libevent_info( void )
{
        int i;
        const char **methods = event_get_supported_methods();
        if ( NULL == methods ) {
                ED2KD_LOGERR("failed to get supported libevent methods");
                return;
        }
        ED2KD_LOGNFO("using libevent %s. available methods are:", event_get_version());
        for ( i=0; methods[i] != NULL; ++i ) {
                ED2KD_LOGNFO("    %s", methods[i]);
        }
}
Example #4
0
static int event_external_register (void) {
    const char **all_available_eventops;
    char *avail = NULL;
    char *help_msg = NULL;
    int ret;

    // Get supported methods
    all_available_eventops = event_get_supported_methods();

#ifdef __APPLE__
    ompi_event_module_include ="select";
#else
    ompi_event_module_include = "poll";
#endif

    avail = opal_argv_join((char**)all_available_eventops, ',');
    asprintf( &help_msg,
              "Comma-delimited list of libevent subsystems "
              "to use (%s -- available on your platform)",
              avail );

    ret = mca_base_component_var_register (&mca_event_external_component.base_version,
                                           "event_include", help_msg,
                                           MCA_BASE_VAR_TYPE_STRING, NULL, 0,
                                           MCA_BASE_VAR_FLAG_SETTABLE,
                                           OPAL_INFO_LVL_3,
                                           MCA_BASE_VAR_SCOPE_LOCAL,
                                           &ompi_event_module_include);
    free(help_msg);  /* release the help message */
    free(avail);
    avail = NULL;

    if (0 > ret) {
        return ret;
    }

    ret = mca_base_var_register_synonym (ret, "opal", "opal", "event", "include", 0);
    if (0 > ret) {
        return ret;
    }

    return OPAL_SUCCESS;
}
Example #5
0
void feature_test ()
{
    /* supported async */
    const char ** methods = event_get_supported_methods(); 
    if (methods) {
        int i = 0;
        while(methods[i]) {
            printf ("method %d : <%s>\n", i+1, methods[i]);
            i++;
        }
    }

    /* get the default async method */
	base = event_base_new();
    const char * bb = event_base_get_method(base);
    printf("default method is <%s>\n", bb);     /* epoll */

	print_features(base);

	event_base_free(base);
}
Example #6
0
int main(int argc, char*argv[]) {
	printf("Hello, world!\n");

	event_config *conf = event_config_new();

#ifdef WIN32
	WORD wVersionRequested;
	WSADATA wsaData;
	int err;

	/* Use the MAKEWORD(lowbyte, highbyte) macro declared in Windef.h */
	wVersionRequested = MAKEWORD(2, 2);

	err = WSAStartup(wVersionRequested, &wsaData);
	if (err != 0) {
		/* Tell the user that we could not find a usable */
		/* Winsock DLL.                                  */
		printf("WSAStartup failed with error: %d\n", err);
		return 1;
	}

	evthread_use_windows_threads();

	event_config_set_flag(conf, EVENT_BASE_FLAG_STARTUP_IOCP);
#endif

	base = event_base_new_with_config(conf);
	const char ** methods = event_get_supported_methods();
	int loop;

	std::cout << "Version: " << event_get_version() << std::endl;
	std::cout << "Method: " << event_base_get_method(base) << std::endl;
	std::cout << "Features: 0x" << std::hex << event_base_get_features(base)
			<< std::endl;
	std::cout << "Base: " << base << std::endl;
	while (*methods) {
		std::cout << "Method: " << *methods++ << std::endl;
	}

	event_set_log_callback(_log_cb);

	/* The caller has already set up fd1, fd2 somehow, and make them
	 nonblocking. */

	if (0) {
		evutil_socket_t fd1 = 1;
		evutil_socket_t fd2 = 1;
		struct timeval five_seconds = { 5, 0 };
		struct event *ev1 = event_new(base, fd1,
				EV_TIMEOUT | EV_READ/*|EV_PERSIST*/, cb_func,
				(char*) "Reading event");
		struct event *ev2 = event_new(base, fd2, EV_WRITE/*|EV_PERSIST*/, cb_func,
				(char*) "Writing event");

		event_add(ev1, &five_seconds);
		event_add(ev2, NULL);

		std::cout << "\nEntering loop" << std::endl;
		loop = event_base_loop(base, 0);
		std::cout << "Exiting loop: " << loop << std::endl;
	}

	// http server
	evhttp *ev_http = evhttp_new(base);
	int http_port = 9090;

	// evhttp_bind_socket expects its PORT param in host byte order. Sigh.
	int r = evhttp_bind_socket(ev_http, "0.0.0.0", http_port);
	// This return value is undocumented (!), but this seems to work.
	if (r == -1) {
		std::cerr << "could not open port " << http_port << std::endl;
		return 3;
	}

	evhttp_set_gencb(ev_http, http_handle_generic, 0);
	//evhttp_set_cb(ev_http, "/", http_handle_root);

	std::cout << "\nEntering loop" << std::endl;
	loop = event_base_loop(base, 0);
	std::cout << "Exiting loop: " << loop << std::endl;

	evhttp_free(ev_http);

	event_base_free(base);
	event_config_free(conf);

	return 0;
}