MINOR: listener: add listener_get_next_id() to find next free listener ID

This was previously achieved via the generic get_next_id() but we'll soon
get rid of generic ID trees so let's have a dedicated listener_get_next_id().
As a bonus it reduces the exposure of the tree's root outside of the functions.
This commit is contained in:
Willy Tarreau 2025-08-23 19:25:03 +02:00
parent b2402d67b7
commit 23605eddb1
3 changed files with 24 additions and 1 deletions

View file

@ -82,6 +82,12 @@ int relax_listener(struct listener *l, int lpx, int lli);
*/
void stop_listener(struct listener *l, int lpx, int lpr, int lli);
/* This function returns the first unused listener ID greater than or equal to
* <from> in the proxy <px>. Zero is returned if no spare one is found (should
* never happen).
*/
uint listener_get_next_id(const struct proxy *px, uint from);
/* This function adds the specified listener's file descriptor to the polling
* lists if it is in the LI_LISTEN state. The listener enters LI_READY or
* LI_FULL state depending on its number of connections. In daemon mode, we

View file

@ -4290,7 +4290,7 @@ init_proxies_list_stage2:
if (prev_li->luid)
next_id = prev_li->luid + 1;
}
next_id = get_next_id(&curproxy->conf.used_listener_id, next_id);
next_id = listener_get_next_id(curproxy, next_id);
listener->conf.id.key = listener->luid = next_id;
eb32_insert(&curproxy->conf.used_listener_id, &listener->conf.id);
}

View file

@ -399,6 +399,23 @@ void stop_listener(struct listener *l, int lpx, int lpr, int lli)
HA_RWLOCK_WRUNLOCK(PROXY_LOCK, &px->lock);
}
/* This function returns the first unused listener ID greater than or equal to
* <from> in the proxy <px>. Zero is returned if no spare one is found (should
* never happen).
*/
uint listener_get_next_id(const struct proxy *px, uint from)
{
const struct eb32_node *used;
do {
used = eb32_lookup_ge((struct eb_root*)&px->conf.used_listener_id, from);
if (!used || used->key > from)
return from; /* available */
from++;
} while (from);
return from;
}
/* This function adds the specified <listener> to the protocol <proto>. It
* does nothing if the protocol was already added. The listener's state is
* automatically updated from LI_INIT to LI_ASSIGNED. The number of listeners