//network_connection_pool_entry *network_connection_pool_add(network_connection_pool *pool, network_socket *sock, nc_pool_add_position_t pos) {
network_connection_pool_entry *network_connection_pool_add(network_connection_pool *pool, network_socket *sock) {
	network_connection_pool_entry *entry;
	GTimeVal now_tv;
	GQueue *conns = NULL;

	entry = network_connection_pool_entry_new();
	entry->sock = sock;
	entry->pool = pool;
	g_get_current_time(&now_tv);
	entry->added_ts = now_tv;
	entry->last_connect = now_tv;
	
#ifdef DEBUG_CONN_POOL
	g_debug("%s: (add) adding socket to pool for user '%s' -> %p fd=%d", G_STRLOC, sock->response->username->str, sock, sock->fd);
#endif

	g_mutex_lock(&(pool->connection_pool_mutex));
	if (NULL == (conns = g_hash_table_lookup(pool->users, sock->response->username))) {
		conns = g_queue_new();

		g_hash_table_insert(pool->users, g_string_dup(sock->response->username), conns);
	}

//	if (pos != NC_POOL_ADD_PREPEND) {
//		g_queue_push_tail(conns, entry);
//	} else {
		g_queue_push_head(conns, entry);
//	}
	g_mutex_unlock(&(pool->connection_pool_mutex));

	return entry;
}
Example #2
0
/**
 * add a connection to the connection pool
 *
 */
network_connection_pool_entry *network_connection_pool_add(network_connection_pool *pool, 
        network_socket *sock, guint64 key) 
{
	network_connection_pool_entry *entry;
	GQueue *conns = NULL;

	entry = network_connection_pool_entry_new();
	entry->sock = sock;
	entry->pool = pool;
    entry->key = key;

	g_get_current_time(&(entry->added_ts));
	
	g_debug("%s: (add) adding socket to pool for user '%s' -> %p", G_STRLOC, sock->response->username->str, sock);

	if (NULL == (conns = g_hash_table_lookup(pool->users, sock->response->username))) {
		conns = g_queue_new();

		g_hash_table_insert(pool->users, g_string_dup(sock->response->username), conns);
	}

	g_queue_push_tail(conns, entry);

	return entry;
}
Example #3
0
/**
 * add a connection to the connection pool
 *
 */
network_connection_pool_entry *network_connection_pool_add(network_connection_pool *pool, network_socket *sock) {
	if (pool) {
		network_connection_pool_entry *entry = network_connection_pool_entry_new();
		if (entry) {
			entry->sock = sock;
			entry->pool = pool;
			g_queue_push_tail(pool, entry);

			return entry;
		}
	}

	network_socket_free(sock);
	return NULL;
}