예제 #1
0
void test_queue()
{
    MsgEnv msg_a = { NULL, 0, 0, 1, (char *)malloc(100) };
    MsgEnv msg_b = { NULL, 0, 0, 1, (char *)malloc(100) };
    MsgEnv msg_c = { NULL, 0, 0, 1, (char *)malloc(100) };

	*((int *) msg_a.msg) = 100;
	*((int *) msg_b.msg) = 1000;
	*((int *) msg_c.msg) = 10;
	
    timeout_queue_insert(&msg_a);
    timeout_queue_insert(&msg_b);
    timeout_queue_insert(&msg_c);

	MsgEnv* queue = get_timeout_queue();
	
    while (queue->next != NULL)
    {
		int chk1 = *((int *) queue->msg) == 10 + 1;
        utest_assert(chk1, "The first block is not 10");
		
		queue = queue->next;
		int chk2 = *((int *) queue->msg) == 100 + 1;
		utest_assert(chk2, "The first block is not 100");
		
		queue = queue->next;
		int chk3 = *((int *) queue->msg) == 1000 + 1;
		utest_assert(chk3, "The first block is not 1000");
    }
}
예제 #2
0
파일: usermanager.c 프로젝트: Nyogtha/uhub
int uman_init(struct hub_info* hub)
{
	struct hub_user_manager* users = NULL;
	if (!hub)
		return -1;

	users = (struct hub_user_manager*) hub_malloc_zero(sizeof(struct hub_user_manager));
	if (!users)
		return -1;

	users->list = list_create();
	users->sids = sid_pool_create(net_get_max_sockets());

	if (!users->list)
	{
		list_destroy(users->list);
		hub_free(users);
		return -1;
	}

	if (net_backend_get_timeout_queue())
	{
		users->timeout = hub_malloc_zero(sizeof(struct timeout_evt));
		timeout_evt_initialize(users->timeout, timer_statistics, hub);
		timeout_queue_insert(net_backend_get_timeout_queue(), users->timeout, TIMEOUT_STATS);
	}

	hub->users = users;
	return 0;
}
예제 #3
0
파일: timer.c 프로젝트: Nyogtha/uhub
void net_con_set_timeout(struct net_connection* con, int seconds)
{
	if (!con->timeout)
	{
		con->timeout = hub_malloc_zero(sizeof(struct timeout_evt));
		timeout_evt_initialize(con->timeout, timeout_callback, con);
		timeout_queue_insert(net_backend_get_timeout_queue(), con->timeout, seconds);
	}
	else
	{
		timeout_queue_reschedule(net_backend_get_timeout_queue(), con->timeout, seconds);
	}
}
예제 #4
0
void test_check()
{
	MsgEnv msg_a = { NULL, 0, 0, 1, (char *)malloc(100) };
    MsgEnv msg_b = { NULL, 0, 0, 1, (char *)malloc(100) };
    MsgEnv msg_c = { NULL, 0, 0, 1, (char *)malloc(100) };

	*((int *) msg_a.msg) = 100;
	*((int *) msg_b.msg) = 1000;
	*((int *) msg_c.msg) = 10;
	
    timeout_queue_insert(&msg_a);
    timeout_queue_insert(&msg_b);
    timeout_queue_insert(&msg_c);

	k_set_system_time(500);
	
	MsgEnv msg_a2 = { NULL, 0, 0, 1, (char *)malloc(100) };

	MsgEnv* msg_env = check_timeout_queue(&msg_a2);
	
	int chk1 = msg_env != NULL;
    utest_assert(chk1, "The msg env is NULL");
	
	if(msg_env)
	{
		int chk2 = *((int *) msg_env->msg) == 10 + 1;
		utest_assert(chk2, "The first block is not 10 + 1");	
		
		MsgEnv* msg_env2 = check_timeout_queue(&msg_a2);
		int chk3 = *((int *) msg_env2->msg) == 100 + 1;
		utest_assert(chk3, "The first block is not 100 + 1");		
		
		MsgEnv* msg_env3 = check_timeout_queue(&msg_a2);
		int chk4 = msg_env3 == NULL;
		utest_assert(chk4, "The first block is not NULL");
	}
}
예제 #5
0
파일: timeout.c 프로젝트: junaidk/uhub
void timeout_queue_reschedule(struct timeout_queue* t, struct timeout_evt* evt, size_t seconds)
{
	if (timeout_evt_is_scheduled(evt))
		timeout_queue_remove(t, evt);
	timeout_queue_insert(t, evt, seconds);
}
예제 #6
0
파일: hub.c 프로젝트: imobilis/uhub
struct hub_info* hub_start_service(struct hub_config* config)
{
	struct hub_info* hub = 0;
	int ipv6_supported;

	hub = hub_malloc_zero(sizeof(struct hub_info));
	if (!hub)
	{
		LOG_FATAL("Unable to allocate memory for hub");
		return 0;
	}

	hub->tm_started = time(0);
	ipv6_supported = net_is_ipv6_supported();
	if (ipv6_supported)
		LOG_DEBUG("IPv6 supported.");
	else
		LOG_DEBUG("IPv6 not supported.");

	hub->server = start_listening_socket(config->server_bind_addr, config->server_port, config->server_listen_backlog, hub);
	if (!hub->server)
	{
		hub_free(hub);
		LOG_FATAL("Unable to start hub service");
		return 0;
	}
	LOG_INFO("Starting " PRODUCT "/" VERSION ", listening on %s:%d...", net_get_local_address(hub->server->sd), config->server_port);

#ifdef SSL_SUPPORT
	if (!load_ssl_certificates(hub, config))
	{
		hub_free(hub);
		return 0;
	}
#endif

	hub->config = config;
	hub->users = NULL;
	hub->muxes = list_create();

	hub->users = uman_init();
	if (!hub->users)
	{
		net_con_close(hub->server);
		hub_free(hub);
		return 0;
	}

	if (event_queue_initialize(&hub->queue, hub_event_dispatcher, (void*) hub) == -1)
	{
		net_con_close(hub->server);
		uman_shutdown(hub->users);
		hub_free(hub);
		return 0;
	}

	hub->recvbuf = hub_malloc(MAX_RECV_BUF);
	hub->sendbuf = hub_malloc(MAX_SEND_BUF);
	if (!hub->recvbuf || !hub->sendbuf)
	{
		net_con_close(hub->server);
		hub_free(hub->recvbuf);
		hub_free(hub->sendbuf);
		uman_shutdown(hub->users);
		hub_free(hub);
		return 0;
	}

	hub->logout_info  = (struct linked_list*) list_create();
	server_alt_port_start(hub, config);

	hub->status = hub_status_running;

	g_hub = hub;

	if (net_backend_get_timeout_queue())
	{
		hub->stats.timeout = hub_malloc_zero(sizeof(struct timeout_evt));
		timeout_evt_initialize(hub->stats.timeout, hub_timer_statistics, hub);
		timeout_queue_insert(net_backend_get_timeout_queue(), hub->stats.timeout, TIMEOUT_STATS);
	}

	// Start the hub command sub-system
	hub->commands = command_initialize(hub);
	return hub;
}
예제 #7
0
void test_create()
{
	MsgEnv* msg_env = NULL;
    timeout_queue_insert(msg_env);
    utest_assert(get_timeout_queue() == NULL, "Timeout Queue was not Null");
}