Avoid duplicated iteration over services when announcing
authorRafał Miłecki <rafal@milecki.pl>
Fri, 10 Feb 2017 13:44:39 +0000 (14:44 +0100)
committerRafał Miłecki <rafal@milecki.pl>
Fri, 10 Feb 2017 14:19:33 +0000 (15:19 +0100)
In function service_announce_services we iterate over services and
handle every single one so calling service_reply which also iterates
doesn't make sense.

In simple cases it was just wasting CPU cycles. We got service, we were
passing its name and we were looking for it again comparing names.
In cases with one service available on few different ports it was worse.
For every iterated service we were announcing that one and all other
sharing the same name. It resulted in sending n^2 records.

Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
Acked-by: John Crispin <john@phrozen.org>
service.c

index 182b2b2bfaa4496cc35eedecf570f1df20127acf..bb87aff954aa0cc7dd95f5a90ecd5a2b5a2b7daa 100644 (file)
--- a/service.c
+++ b/service.c
@@ -179,7 +179,7 @@ service_announce_services(struct interface *iface, const char *service, int ttl)
                        else
                                dns_send_answer(iface, sdudp);
                }
-               service_reply(iface, s->service, ttl);
+               service_reply_single(iface, s, ttl, 0);
        }
 }