Beispiel #1
0
int mst_mm_init(void)
{
    mst_memmgmt_init();
    mst_membuf_init();
    //event_set_mem_functions(__mst_malloc, __mst_realloc, __mst_free);
    event_set_mem_functions(os_malloc, realloc, os_free);
    return 0;
}
Beispiel #2
0
int main (int argc, char *argv[])
{
    ClientPool *pool;
    struct event *timeout;
    struct timeval tv;
    GList *l_files = NULL;
    CBData *cb;
    gchar *in_dir;

    log_level = LOG_debug;

    event_set_mem_functions (g_malloc, g_realloc, g_free);

    in_dir = g_dir_make_tmp (NULL, NULL);
    g_assert (in_dir);

    l_files = populate_file_list (100, l_files, in_dir);
    g_assert (l_files);

    
    
    app = app_create ();
    
    
    
    app->h_clients_freq = g_hash_table_new (g_direct_hash, g_direct_equal);
    app->l_files = l_files;
    // start server
    start_srv (app->evbase, in_dir);
    
    /*
    pool = client_pool_create (app, 12,
        http_client_create,
        http_client_destroy,
        http_client_set_on_released_cb,
        http_client_check_rediness
    );
    */

    cb = g_new (CBData, 1);
    cb->pool = pool;
    cb->l_files = l_files;
    
    timeout = evtimer_new (app->evbase, on_output_timer, cb);

    evutil_timerclear(&tv);
    tv.tv_sec = 0;
    tv.tv_usec = 500;
    event_add (timeout, &tv);

    event_base_dispatch (app->evbase);

    g_hash_table_foreach (app->h_clients_freq, (GHFunc)print_foreach, NULL);

    return 0;
}
Beispiel #3
0
void _ws_set_memory_functions(ws_malloc_replacement_f malloc_replace,
							 ws_free_replacement_f free_replace,
							 ws_realloc_replacement_f realloc_replace)
{

	replaced_ws_malloc = malloc_replace;
	replaced_ws_free = free_replace;
	replaced_ws_realloc = realloc_replace;

	event_set_mem_functions(malloc_replace, realloc_replace, free_replace);

	#ifdef LIBWS_WITH_OPENSSL
	CRYPTO_set_mem_functions(malloc_replace, realloc_replace, free_replace);
	#endif
}
static void
test_fin_free_finalize(void *arg)
{
#ifdef EVENT__DISABLE_MM_REPLACEMENT
	tinytest_set_test_skipped_();
#else
	struct event_base *base = NULL;
	struct event *ev, *ev2;
	int ev_called = 0;
	int ev2_called = 0;

	(void)arg;

	event_set_mem_functions(tfff_malloc, tfff_realloc, tfff_free);

	base = event_base_new();

	ev = evtimer_new(base, timer_callback, &ev_called);
	ev2 = evtimer_new(base, timer_callback, &ev2_called);
	tfff_p1 = ev;
	tfff_p2 = ev2;
	event_free_finalize(0, ev, event_finalize_callback_1);
	event_finalize(0, ev2, event_finalize_callback_1);

	event_base_dispatch(base);

	tt_int_op(ev_called, ==, 100);
	tt_int_op(ev2_called, ==, 100);

	event_base_assert_ok_(base);
	tt_int_op(tfff_p1_freed, ==, 1);
	tt_int_op(tfff_p2_freed, ==, 0);

	event_free(ev2);

end:
	if (base)
		event_base_free(base);
#endif
}
Beispiel #5
0
void
internal_parc_initializeLibevent(void)
{
    if (_libeventInitialized) {
        return;
    }
    _libeventInitialized = 1;

    // 0x AA BB CC XX
    // AA = major
    // BB = minor
    // CC = patchlevel
    //
    uint32_t version = event_get_version_number();
    trapIllegalValueIf(version < 0x02001000UL,
                       "Libevent version must be at least 2.0.16, got %s",
                       event_get_version());

    // Make sure libevent uses our memory allocator.
    // Libevent allocates an internal object the first time a base is allocated
    // that it never releases.  In order to ensure our outstanding memory counters
    // start at zero we trigger this allocation before interposing our memory allocator.
    //
    // Create a scheduler event base, an event, then free both of them.
    //
    struct event_base *evbase = event_base_new();
    assertNotNull(evbase, "Libevent event_base_new returned NULL");
    struct event *event = event_new(evbase, -1, 0, NULL, NULL);
    assertNotNull(event, "Libevent event_new returned NULL");
    event_del(event);
    event_base_free(evbase);

    event_set_mem_functions(internal_parc_alloc,
                            internal_parc_realloc,
                            internal_parc_free);
}
int main (int argc, char *argv[])
{
    gchar *in_dir;
    GList *tmp;
    struct evhttp_uri *uri;
    struct timeval tv;

    log_level = LOG_debug;

    event_set_mem_functions (g_malloc, g_realloc, g_free);
    // init SSL libraries
    CRYPTO_set_mem_functions (g_malloc0, g_realloc, g_free);
    ENGINE_load_builtin_engines ();
    ENGINE_register_all_complete ();
    ERR_load_crypto_strings ();
    OpenSSL_add_all_algorithms ();

    SSL_load_error_strings ();
    SSL_library_init ();
    if (!RAND_poll ()) {
        fprintf(stderr, "RAND_poll() failed.\n");
        return 1;
    }
    g_random_set_seed (time (NULL));

    in_dir = g_dir_make_tmp (NULL, NULL);
    g_assert (in_dir);

    app = g_new0 (Application, 1);
    app->files_count = 10;
    app->evbase = event_base_new ();
	app->dns_base = evdns_base_new (app->evbase, 1);

        app->conf = conf_create ();
        conf_add_boolean (app->conf, "log.use_syslog", TRUE);
        
        conf_add_uint (app->conf, "auth.ttl", 85800);
        
        conf_add_int (app->conf, "pool.writers", 2);
        conf_add_int (app->conf, "pool.readers", 2);
        conf_add_int (app->conf, "pool.operations", 4);
        conf_add_uint (app->conf, "pool.max_requests_per_pool", 100);

        conf_add_int (app->conf, "connection.timeout", 20);
        conf_add_int (app->conf, "connection.retries", -1);

        conf_add_uint (app->conf, "filesystem.dir_cache_max_time", 5);
        conf_add_boolean (app->conf, "filesystem.cache_enabled", TRUE);
        conf_add_string (app->conf, "filesystem.cache_dir", "/tmp/hydrafs");
        conf_add_string (app->conf, "filesystem.cache_dir_max_size", "1Gb");

        conf_add_boolean (app->conf, "statistics.enabled", TRUE);
        conf_add_int (app->conf, "statistics.port", 8011);

    conf_add_string (app->conf, "auth.user", "test:tester");
    conf_add_string (app->conf, "auth.key", "testing");
    uri = evhttp_uri_parse ("https://10.0.0.104:8080/auth/v1.0");
    
    app->ssl_ctx = SSL_CTX_new (TLSv1_client_method ());
    
    app->stats = hfs_stats_srv_create (app);
    app->auth_client = auth_client_create (app, uri);

    app->http = http_client_create (app);

    // start server
     start_srv (app->evbase, in_dir);

    app->timeout = evtimer_new (app->evbase, on_output_timer, NULL);

    evutil_timerclear(&tv);
    tv.tv_sec = 0;
    tv.tv_usec = 500;
    event_add (app->timeout, &tv);

    event_base_dispatch (app->evbase);

    evhttp_uri_free (uri);
    event_del (app->timeout);
    event_free (app->timeout);

    evhttp_free (app->http_srv);
    auth_client_destroy (app->auth_client);

    evdns_base_free (app->dns_base, 0);
    event_base_free (app->evbase);

    conf_destroy (app->conf);
    g_free (app);

    return 0;
}
int main (int argc, char *argv[])
{
    struct event_base *evbase;
    struct evdns_base *dns_base;
    int i;
    int test_id = -1;
    struct evhttp_uri *uri;

    event_set_mem_functions (g_malloc, g_realloc, g_free);

    evbase = event_base_new ();
	dns_base = evdns_base_new (evbase, 1);

    app = g_new0 (Application, 1);
    app->evbase = evbase;
	app->dns_base = dns_base;
    app->stats = hfs_stats_srv_create (app);

        app->conf = conf_create ();
        conf_add_boolean (app->conf, "log.use_syslog", TRUE);
        
        conf_add_uint (app->conf, "auth.ttl", 85800);
        
        conf_add_int (app->conf, "pool.writers", 2);
        conf_add_int (app->conf, "pool.readers", 2);
        conf_add_int (app->conf, "pool.operations", 4);
        conf_add_uint (app->conf, "pool.max_requests_per_pool", 100);

        conf_add_int (app->conf, "connection.timeout", 20);
        conf_add_int (app->conf, "connection.retries", -1);

        conf_add_uint (app->conf, "filesystem.dir_cache_max_time", 5);
        conf_add_boolean (app->conf, "filesystem.cache_enabled", TRUE);
        conf_add_string (app->conf, "filesystem.cache_dir", "/tmp/hydrafs");
        conf_add_string (app->conf, "filesystem.cache_dir_max_size", "1Gb");

        conf_add_boolean (app->conf, "statistics.enabled", TRUE);
        conf_add_int (app->conf, "statistics.port", 8011);

    conf_add_string (app->conf, "auth.user", "test");
    conf_add_string (app->conf, "auth.key", "test");
    uri = evhttp_uri_parse ("http://127.0.0.1:8011/get_auth");
    app->auth_client = auth_client_create (app, uri);
    
    if (argc > 1)
        test_id = atoi (argv[1]);

    if (test_id >= 0)
        // run_responce_test (evbase, dns_base, test_id);
        run_request_test (evbase, dns_base, test_id);
    else {
        for (i = 0; i < TID_last_test; i++) {
            run_responce_test (evbase, dns_base, i);
        }
    }

    evdns_base_free (dns_base, 0);
    event_base_free (evbase);

    return 0;
}
Beispiel #8
0
void CXtReactor::SetupMemFun( void *(*malloc_fn)(size_t sz), void *(*realloc_fn)(void *ptr, size_t sz), void (*free_fn)(void *ptr) )
{
	event_set_mem_functions( malloc_fn, realloc_fn, free_fn );
}