net: Let maksock() callers perform flowopt cleanup.
authorAndre Noll <maan@systemlinux.org>
Sun, 8 Sep 2013 07:31:37 +0000 (07:31 +0000)
committerAndre Noll <maan@systemlinux.org>
Wed, 1 Jan 2014 17:50:02 +0000 (17:50 +0000)
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
net.c
net.h

index 73d9999d0408617099086e7b25248af5277839db..ca3432a31de2fc3eaadf13572cef68358f85c0a2 100644 (file)
@@ -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 9435064715cd368ac6bc04e3dbac0b4c3d0b3e69..70cf6a87dfb27bbba74912bb50467a0a74f966bd 100644 (file)
--- 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 0003fa9d57d22ad4a6ce39f530ec12348008aebb..7aaddc0c65264652c1474deb7967603612063c4a 100644 (file)
--- 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)