From f5dbb830927d654328018fa19f6ef8bbb77ff006 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Wed, 25 Sep 2019 07:00:11 +0000 Subject: [PATCH] Feature: Added error parameter to igloo_socketaddr_new() --- include/igloo/socketaddr.h | 2 +- src/socketaddr.c | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/igloo/socketaddr.h b/include/igloo/socketaddr.h index 235e242..09446e6 100644 --- a/include/igloo/socketaddr.h +++ b/include/igloo/socketaddr.h @@ -64,7 +64,7 @@ typedef enum { igloo_SOCKETADDR_PROTOCOL_UDPLITE } igloo_socketaddr_protocol_t; -igloo_socketaddr_t * igloo_socketaddr_new(igloo_socketaddr_domain_t domain, igloo_socketaddr_type_t type, igloo_socketaddr_protocol_t protocol, const char *name, igloo_ro_t associated, igloo_ro_t instance); +igloo_socketaddr_t * igloo_socketaddr_new(igloo_socketaddr_domain_t domain, igloo_socketaddr_type_t type, igloo_socketaddr_protocol_t protocol, const char *name, igloo_ro_t associated, igloo_ro_t instance, igloo_error_t *error); igloo_error_t igloo_socketaddr_get_base(igloo_socketaddr_t *addr, igloo_socketaddr_domain_t *domain, igloo_socketaddr_type_t *type, igloo_socketaddr_protocol_t *protocol); igloo_error_t igloo_socketaddr_set_node(igloo_socketaddr_t *addr, const char *node); diff --git a/src/socketaddr.c b/src/socketaddr.c index a16b546..37945f6 100644 --- a/src/socketaddr.c +++ b/src/socketaddr.c @@ -375,12 +375,15 @@ static igloo_error_t _get_service(igloo_socketaddr_t *addr, const char *name, ui #endif -igloo_socketaddr_t * igloo_socketaddr_new(igloo_socketaddr_domain_t domain, igloo_socketaddr_type_t type, igloo_socketaddr_protocol_t protocol, const char *name, igloo_ro_t associated, igloo_ro_t instance) +igloo_socketaddr_t * igloo_socketaddr_new(igloo_socketaddr_domain_t domain, igloo_socketaddr_type_t type, igloo_socketaddr_protocol_t protocol, const char *name, igloo_ro_t associated, igloo_ro_t instance, igloo_error_t *error) { igloo_socketaddr_t *addr = igloo_ro_new_raw(igloo_socketaddr_t, name, associated, instance); - if (!addr) + if (!addr) { + if (error) + *error = igloo_ERROR_NOMEM; return NULL; + } addr->domain = domain; addr->type = type; @@ -388,6 +391,9 @@ igloo_socketaddr_t * igloo_socketaddr_new(igloo_socketaddr_domain_t domain, i igloo_socketaddr_complete(addr); + if (error) + *error = igloo_ERROR_NONE; + return addr; } @@ -406,12 +412,9 @@ igloo_socketaddr_t * igloo_socketaddr_new_from_sockaddr(igloo_socketaddr_doma domain_hint = igloo_socketaddr_get_id_domain(sysaddr->sa_family); - ret = igloo_socketaddr_new(domain_hint, type_hint, protocol_hint, name, associated, instance); - if (ret == NULL) { - if (error) - *error = igloo_ERROR_GENERIC; + ret = igloo_socketaddr_new(domain_hint, type_hint, protocol_hint, name, associated, instance, error); + if (ret == NULL) return NULL; - } if (getnameinfo(sysaddr, addr_len, ip, sizeof(ip), service, sizeof(service), NI_NUMERICHOST|NI_NUMERICSERV) == 0) { igloo_socketaddr_set_node(ret, ip);