void pool_user_query(TDS_POOL * pool, TDS_POOL_USER * puser) { TDS_POOL_MEMBER *pmbr; tdsdump_log(TDS_DBG_FUNC, "pool_user_query\n"); assert(puser->assigned_member == NULL); assert(puser->login); puser->user_state = TDS_SRV_QUERY; pmbr = pool_assign_idle_member(pool, puser); if (!pmbr) { /* * put into wait state * check when member is deallocated */ tdsdump_log(TDS_DBG_INFO1, "Not enough free members...placing user in WAIT\n"); puser->user_state = TDS_SRV_WAIT; puser->sock.poll_recv = false; puser->sock.poll_send = false; dlist_user_remove(&pool->users, puser); dlist_user_append(&pool->waiters, puser); } }
/* * pool_free_user * close out a disconnected user. */ void pool_free_user(TDS_POOL *pool, TDS_POOL_USER * puser) { TDS_POOL_MEMBER *pmbr = puser->assigned_member; if (pmbr) { pool_deassign_member(pmbr); pool_reset_member(pool, pmbr); } tds_free_socket(puser->sock.tds); tds_free_login(puser->login); /* make sure to decrement the waiters list if he is waiting */ if (puser->user_state == TDS_SRV_WAIT) dlist_user_remove(&pool->waiters, puser); else dlist_user_remove(&pool->users, puser); pool->num_users--; free(puser); }
static void pool_schedule_waiters(TDS_POOL * pool) { TDS_POOL_USER *puser; /* first see if there are free members to do the request */ if (!dlist_member_first(&pool->idle_members)) return; while ((puser = dlist_user_first(&pool->waiters)) != NULL) { if (puser->user_state == TDS_SRV_WAIT) { /* place back in query state */ puser->user_state = TDS_SRV_QUERY; dlist_user_remove(&pool->waiters, puser); dlist_user_append(&pool->users, puser); /* now try again */ pool_user_query(pool, puser); return; } } }