MINOR: listener: define per-thr struct

Create a new structure li_per_thread. This is uses as an array in the
listener structure, with an entry allocated per thread. The new function
li_init_per_thr is responsible of the allocation.

For now, li_per_thread contains fields only useful for QUIC listeners.
As such, it is only allocated for QUIC listeners.
This commit is contained in:
Amaury Denoyelle 2022-01-25 16:21:47 +01:00
parent 2ce99fe4bf
commit f68b2cb816
5 changed files with 40 additions and 1 deletions

View File

@ -191,6 +191,16 @@ struct bind_conf {
struct rx_settings settings; /* all the settings needed for the listening socket */
};
/* Fields of a listener allocated per thread */
struct li_per_thread {
struct {
struct mt_list list; /* list element in the QUIC accept queue */
struct mt_list conns; /* list of QUIC connections from this listener ready to be accepted */
} quic_accept;
struct listener *li; /* back reference on the listener */
};
#define LI_F_QUIC_LISTENER 0x00000001 /* listener uses proto quic */
/* The listener will be directly referenced by the fdtab[] which holds its
@ -234,6 +244,8 @@ struct listener {
struct eb32_node id; /* place in the tree of used IDs */
} conf; /* config information */
struct li_per_thread *per_thr; /* per-thread fields */
EXTRA_COUNTERS(extra_counters);
};

View File

@ -31,6 +31,8 @@
struct proxy;
struct task;
int li_init_per_thr(struct listener *li);
/* adjust the listener's state and its proxy's listener counters if needed */
void listener_set_state(struct listener *l, enum li_state st);

View File

@ -3906,8 +3906,10 @@ out_uri_auth_compat:
listener->accept = session_accept_fd;
#ifdef USE_QUIC
/* override the accept callback for QUIC listeners. */
if (listener->flags & LI_F_QUIC_LISTENER)
if (listener->flags & LI_F_QUIC_LISTENER) {
listener->accept = quic_session_accept;
li_init_per_thr(listener);
}
#endif
listener->analysers |= curproxy->fe_req_ana;

View File

@ -191,6 +191,28 @@ REGISTER_CONFIG_POSTPARSER("multi-threaded accept queue", accept_queue_init);
#endif // USE_THREAD
/* Memory allocation and initialization of the per_thr field.
* Returns 0 if the field has been successfully initialized, -1 on failure.
*/
int li_init_per_thr(struct listener *li)
{
int i;
/* allocate per-thread elements for listener */
li->per_thr = calloc(global.nbthread, sizeof(*li->per_thr));
if (!li->per_thr)
return -1;
for (i = 0; i < global.nbthread; ++i) {
MT_LIST_INIT(&li->per_thr[i].quic_accept.list);
MT_LIST_INIT(&li->per_thr[i].quic_accept.conns);
li->per_thr[i].li = li;
}
return 0;
}
/* helper to get listener status for stats */
enum li_status get_li_status(struct listener *l)
{

View File

@ -309,6 +309,7 @@ void free_proxy(struct proxy *p)
LIST_DELETE(&l->by_fe);
LIST_DELETE(&l->by_bind);
free(l->name);
free(l->per_thr);
free(l->counters);
EXTRA_COUNTERS_FREE(l->extra_counters);