On Sat, Nov 08, 2025 at 04:59:29PM -0600, Eric Blake wrote:
> An upcoming patch needs to pass more than just sioc as the opaque
> pointer to an AioContext; but since our AioContext code in general
> (and its QIO Channel wrapper code) lacks a notify callback present
> with GSource, we do not have the trivial option of just g_malloc'ing a
> small struct to hold all that data coupled with a notify of g_free.
> Instead, the data pointer must outlive the registered handler; in
> fact, having the data pointer have the same lifetime as QIONetListener
> is adequate.
>
> But the cleanest way to stick such a helper struct in QIONetListener
> will be to rearrange internal struct members. And that in turn means
> that all existing code that currently directly accesses
> listener->nsioc and listener->sioc[] should instead go through
> accessor functions, to be immune to the upcoming struct layout
> changes. So this patch adds accessor methods qio_net_listener_nsioc()
> and qio_net_listener_sioc(), and puts them to use.
>
> Signed-off-by: Eric Blake <[email protected]>
>
> ---
> +++ b/io/net-listener.c
> @@ -298,6 +298,18 @@ bool qio_net_listener_is_connected(QIONetListener
> *listener)
> return listener->connected;
> }
>
> +size_t qio_net_listener_nsioc(QIONetListener *listener)
> +{
> + return listener->nsioc;
> +}
> +
> +QIOChannelSocket *qio_net_listener_sioc(QIONetListener *listener, size_t n)
> +{
> + if (n > listener->nsioc) {
> + return NULL;
Off-by-1; this should be 'n >= listener->nsioc'.
> + }
> + return listener->sioc[n];
> +}
--
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization: qemu.org | libguestfs.org