In qemu-nbd and other NBD server setups where parallel clients are
supported, it is common that the caller will re-register the same
callback function as long as it has not reached its limit on
simultaneous clients. In that case, there is no need to tear down and
reinstall GSource watches in the GMainContext.
In practice, all callers currently pass NULL for notify, and no caller
ever changes context across calls (for async uses, either the caller
consistently uses qio_net_listener_set_client_func_full with the same
context, or the caller consistently uses only
qio_net_listener_set_client_func which always uses the global
context); but the time spent checking these two fields in addition to
the more important func and data is still less than the savings of not
churning through extra GSource manipulations when the result will be
unchanged.
Signed-off-by: Eric Blake <eblake@redhat.com>
---
v2: move later in series, also ensure notify and context are the same
---
io/net-listener.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/io/net-listener.c b/io/net-listener.c
index 0f16b78fbbd..a9da8e4e069 100644
--- a/io/net-listener.c
+++ b/io/net-listener.c
@@ -148,6 +148,11 @@ void qio_net_listener_set_client_func_full(QIONetListener *listener,
{
size_t i;
+ if (listener->io_func == func && listener->io_data == data &&
+ listener->io_notify == notify && listener->context == context) {
+ return;
+ }
+
trace_qio_net_listener_unwatch(listener, listener->io_func,
listener->context, "set_client_func");
--
2.51.1