/** * 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; }
//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; }
/** * @author sohu-inc.com * 向连接池队列头部添加一个连接实体,更新(或不更新)添加时间 */ gboolean network_connection_pool_add_entry (network_connection_pool *pool, network_connection_pool_entry * entry, gboolean update_add_ts) { GQueue *conns = NULL; network_socket *sock = NULL; g_assert(entry); g_assert(entry->pool); g_assert(entry->sock); g_assert(entry->pool == pool); sock = entry->sock; if (update_add_ts == TRUE) { g_get_current_time(&(entry->added_ts)); } #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 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 TRUE; }
static void pool_users_name_queue_add_foreach(gpointer key, gpointer UNUSED_PARAM(val), gpointer userdata) { GString *username = NULL; GQueue *users = (GQueue *)userdata; g_assert(key); if (users != NULL) { username = g_string_dup(key); g_queue_push_tail(users, username); } return; }