From d93de755a5cbfc86b3149e08ad735eb5321471d4 Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: Fri, 21 May 2021 16:36:32 +0100 Subject: [PATCH] dns_sd.c: Scanning doesn't require context Remove functions dnssd_context_scan_init() and dnssd_context_scan_free(), as the context structure is actually never used. Signed-off-by: Paul Cercueil --- dns_sd.c | 25 +------------------------ iio-private.h | 6 +----- scan.c | 12 +++++------- 3 files changed, 7 insertions(+), 36 deletions(-) diff --git a/dns_sd.c b/dns_sd.c index aacc6fb25..b739ab580 100644 --- a/dns_sd.c +++ b/dns_sd.c @@ -77,10 +77,6 @@ static void dnssd_remove_node(struct dns_sd_discovery_data **ddata, int n) * DNS Service Discovery is turned on */ -struct iio_scan_backend_context { - struct addrinfo *res; -}; - static int dnssd_fill_context_info(struct iio_context_info *info, char *hostname, char *addr_str, int port) { @@ -144,24 +140,6 @@ static int dnssd_fill_context_info(struct iio_context_info *info, return 0; } -struct iio_scan_backend_context * dnssd_context_scan_init(void) -{ - struct iio_scan_backend_context *ctx; - - ctx = malloc(sizeof(*ctx)); - if (!ctx) { - errno = ENOMEM; - return NULL; - } - - return ctx; -} - -void dnssd_context_scan_free(struct iio_scan_backend_context *ctx) -{ - free(ctx); -} - /* * remove the ones in the list that you can't connect to * This is sort of silly, but we have seen non-iio devices advertised @@ -255,8 +233,7 @@ void remove_dup_discovery_data(struct dns_sd_discovery_data **ddata) *ddata = d; } -int dnssd_context_scan(struct iio_scan_backend_context *ctx, - struct iio_scan_result *scan_result) +int dnssd_context_scan(struct iio_scan_result *scan_result) { struct iio_context_info **info; struct dns_sd_discovery_data *ddata, *ndata; diff --git a/iio-private.h b/iio-private.h index 312d0343e..063c32426 100644 --- a/iio-private.h +++ b/iio-private.h @@ -252,11 +252,7 @@ void usb_context_scan_free(struct iio_scan_backend_context *ctx); int usb_context_scan(struct iio_scan_backend_context *ctx, struct iio_scan_result *scan_result); -struct iio_scan_backend_context * dnssd_context_scan_init(void); -void dnssd_context_scan_free(struct iio_scan_backend_context *ctx); - -int dnssd_context_scan(struct iio_scan_backend_context *ctx, - struct iio_scan_result *scan_result); +int dnssd_context_scan(struct iio_scan_result *scan_result); ssize_t iio_device_get_sample_size_mask(const struct iio_device *dev, const uint32_t *mask, size_t words); diff --git a/scan.c b/scan.c index 63fffbe27..b0ebf416d 100644 --- a/scan.c +++ b/scan.c @@ -15,7 +15,7 @@ struct iio_scan_context { struct iio_scan_backend_context *usb_ctx; - struct iio_scan_backend_context *dnssd_ctx; + bool scan_network; bool scan_local; }; @@ -54,8 +54,8 @@ ssize_t iio_scan_context_get_info_list(struct iio_scan_context *ctx, } } - if (HAVE_DNS_SD && ctx->dnssd_ctx) { - int ret = dnssd_context_scan(ctx->dnssd_ctx, &scan_result); + if (HAVE_DNS_SD && ctx->scan_network) { + int ret = dnssd_context_scan(&scan_result); if (ret < 0) { if (scan_result.info) iio_context_info_list_free(scan_result.info); @@ -138,8 +138,8 @@ struct iio_scan_context * iio_create_scan_context( if (WITH_USB_BACKEND && (!backend || strstr(backend, "usb"))) ctx->usb_ctx = usb_context_scan_init(); - if (HAVE_DNS_SD && (!backend || strstr(backend, "ip"))) - ctx->dnssd_ctx = dnssd_context_scan_init(); + if (!backend || strstr(backend, "ip")) + ctx->scan_network = true; return ctx; } @@ -148,8 +148,6 @@ void iio_scan_context_destroy(struct iio_scan_context *ctx) { if (WITH_USB_BACKEND && ctx->usb_ctx) usb_context_scan_free(ctx->usb_ctx); - if (HAVE_DNS_SD && ctx->dnssd_ctx) - dnssd_context_scan_free(ctx->dnssd_ctx); free(ctx); }