From ae5e9dbcaaad643039e44c85891b3d7b383b23dd Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 8 Sep 2013 07:31:37 +0000 Subject: [PATCH 1/1] net: Let maksock() callers perform flowopt cleanup. Currently the flowopt user allocates the flowopt structure but cleanup is performed in makesock(). This commit makes the API symmetric by dropping the cleanup part in makesock() and exporting flowopt_cleanup(). Now callers have to perform both the allocation and the cleanup. The single user (ddcp_recv) is adjusted accordingly. --- dccp_recv.c | 1 + net.c | 12 +++++++++--- net.h | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/dccp_recv.c b/dccp_recv.c index 73d9999d..ca3432a3 100644 --- a/dccp_recv.c +++ b/dccp_recv.c @@ -58,6 +58,7 @@ static int dccp_recv_open(struct receiver_node *rn) } fd = makesock(IPPROTO_DCCP, 0, conf->host_arg, conf->port_arg, fo); + flowopt_cleanup(fo); free(ccids); if (fd < 0) return fd; diff --git a/net.c b/net.c index 94350647..70cf6a87 100644 --- a/net.c +++ b/net.c @@ -333,7 +333,14 @@ static void flowopt_setopts(int sockfd, struct flowopts *fo) } } -static void flowopt_cleanup(struct flowopts *fo) +/** + * Deallocate all resources of a flowopts structure. + * + * \param fo A pointer as returned from flowopt_new(). + * + * It's OK to pass \p NULL here in which case the function does nothing. + */ +void flowopt_cleanup(struct flowopts *fo) { struct pre_conn_opt *cur, *next; @@ -412,7 +419,7 @@ static int lookup_address(unsigned l4type, bool passive, const char *host, * * bind(2) is called on passive sockets, and connect(2) on active sockets. The * algorithm tries all possible address combinations until it succeeds. If \a - * fo is supplied, options are set and cleanup is performed. + * fo is supplied, options are set but cleanup must be performed in the caller. * * \return File descriptor on success, \p E_MAKESOCK on errors. * @@ -485,7 +492,6 @@ int makesock(unsigned l4type, bool passive, const char *host, uint16_t port_numb ret = makesock_addrinfo(l4type, passive, ai, fo); if (ai) freeaddrinfo(ai); - flowopt_cleanup(fo); if (ret < 0) { PARA_ERROR_LOG("can not create %s socket %s#%d.\n", layer4_name(l4type), host? host : (passive? diff --git a/net.h b/net.h index 0003fa9d..7aaddc0c 100644 --- a/net.h +++ b/net.h @@ -61,6 +61,7 @@ struct flowopts; extern struct flowopts *flowopt_new(void); extern void flowopt_add(struct flowopts *fo, int level, int opt, const char *name, const void *val, int len); +void flowopt_cleanup(struct flowopts *fo); /** Flowopt shortcut macros */ #define OPT_ADD(fo, lev, opt, val, len) flowopt_add(fo, lev, opt, #opt, val, len) -- 2.30.2