From 2a39105b3f5a2172ba0db196d1b5a016b54910fe Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 30 Jan 2015 09:28:55 -0600 Subject: [PATCH] Unix domain: Add logic to release references to the half duplex FIFO after sendto and recvfrom --- net/local/local.h | 12 ++++++------ net/local/local_conn.c | 2 +- net/local/local_connect.c | 2 +- net/local/local_fifo.c | 36 +++++++++++++++++++----------------- net/local/local_recvfrom.c | 14 +++++++++++++- net/local/local_sendto.c | 8 +++++++- 6 files changed, 47 insertions(+), 27 deletions(-) diff --git a/net/local/local.h b/net/local/local.h index 30f08ca6919..b38eea9178b 100644 --- a/net/local/local.h +++ b/net/local/local.h @@ -509,24 +509,24 @@ int local_create_halfduplex(FAR struct local_conn_s *conn, FAR const char *path); /**************************************************************************** - * Name: local_destroy_fifos + * Name: local_release_fifos * * Description: - * Destroy the FIFO pair used for a SOCK_STREAM connection. + * Release references to the FIFO pair used for a SOCK_STREAM connection. * ****************************************************************************/ -int local_destroy_fifos(FAR struct local_conn_s *conn); +int local_release_fifos(FAR struct local_conn_s *conn); /**************************************************************************** - * Name: local_destroy_halfduplex + * Name: local_release_halfduplex * * Description: - * Destroy the FIFO used for SOCK_DGRAM communication + * Release a reference to the FIFO used for SOCK_DGRAM communication * ****************************************************************************/ -int local_destroy_halfduplex(FAR struct local_conn_s *conn); +int local_release_halfduplex(FAR struct local_conn_s *conn); /**************************************************************************** * Name: local_open_client_rx diff --git a/net/local/local_conn.c b/net/local/local_conn.c index 171313b2952..d3f021f9261 100644 --- a/net/local/local_conn.c +++ b/net/local/local_conn.c @@ -125,7 +125,7 @@ void local_free(FAR struct local_conn_s *conn) /* Destroy all FIFOs associted with the connection */ - local_destroy_fifos(conn); + local_release_fifos(conn); sem_destroy(&conn->lc_waitsem); /* And free the connection structure */ diff --git a/net/local/local_connect.c b/net/local/local_connect.c index 57e32a1b1ae..40f5c77b42f 100644 --- a/net/local/local_connect.c +++ b/net/local/local_connect.c @@ -192,7 +192,7 @@ errout_with_outfd: (void)close(client->lc_outfd); errout_with_fifos: - (void)local_destroy_fifos(client); + (void)local_release_fifos(client); client->lc_state = LOCAL_STATE_BOUND; return ret; } diff --git a/net/local/local_fifo.c b/net/local/local_fifo.c index 85e2468b0e1..bd9b141d957 100644 --- a/net/local/local_fifo.c +++ b/net/local/local_fifo.c @@ -176,26 +176,27 @@ static int local_create_fifo(FAR const char *path) } /**************************************************************************** - * Name: local_destroy_fifo + * Name: local_release_fifo * * Description: - * Destroy one of the FIFOs used in a connection. + * Release a reference from one of the FIFOs used in a connection. * ****************************************************************************/ -static int local_destroy_fifo(FAR const char *path) +static int local_release_fifo(FAR const char *path) { int ret; - /* Unlink the client-to-server FIFO if it exists. - * REVISIT: This is wrong! Un-linking the FIFO does not eliminate it. - * it only removes it from the namespace. A new interface will be required - * to remove the FIFO and all of its resources. - */ -#warning Missing logic + /* Unlink the client-to-server FIFO if it exists. */ if (local_fifo_exists(path)) { + /* REVISIT: This is wrong! Un-linking the FIFO does not eliminate it; + * it only removes it from the namespace. A new interface will be + * required to destory the FIFO driver instance and all of its resources. + */ +#warning Missing logic +#if 0 ret = unlink(path); if (ret < 0) { @@ -205,6 +206,7 @@ static int local_destroy_fifo(FAR const char *path) ndbg("ERROR: Failed to unlink FIFO %s: %d\n", path, errcode); return -errcode; } +#endif } /* The FIFO does not exist or we successfully unlinked it. */ @@ -331,14 +333,14 @@ int local_create_halfduplex(FAR struct local_conn_s *conn, FAR const char *path) } /**************************************************************************** - * Name: local_destroy_fifos + * Name: local_release_fifos * * Description: - * Destroy the FIFO pair used for a SOCK_STREAM connection. + * Release references to the FIFO pair used for a SOCK_STREAM connection. * ****************************************************************************/ -int local_destroy_fifos(FAR struct local_conn_s *conn) +int local_release_fifos(FAR struct local_conn_s *conn) { char path[LOCAL_FULLPATH_LEN]; int ret1; @@ -347,7 +349,7 @@ int local_destroy_fifos(FAR struct local_conn_s *conn) /* Destroy the client-to-server FIFO if it exists. */ local_sc_name(conn, path); - ret1 = local_destroy_fifo(path); + ret1 = local_release_fifo(path); /* Destroy the server-to-client FIFO if it exists. */ @@ -360,21 +362,21 @@ int local_destroy_fifos(FAR struct local_conn_s *conn) } /**************************************************************************** - * Name: local_destroy_halfduplex + * Name: local_release_halfduplex * * Description: - * Destroy the FIFO used for SOCK_DGRAM communication + * Release a reference to the FIFO used for SOCK_DGRAM communication * ****************************************************************************/ -int local_destroy_halfduplex(FAR struct local_conn_s *conn) +int local_release_halfduplex(FAR struct local_conn_s *conn) { char path[LOCAL_FULLPATH_LEN]; /* Destroy the half duplex FIFO if it exists. */ local_hd_name(conn->lc_path, path); - return local_destroy_fifo(path); + return local_release_fifo(path); } /**************************************************************************** diff --git a/net/local/local_recvfrom.c b/net/local/local_recvfrom.c index cfcf7f325e6..97109ea1ade 100644 --- a/net/local/local_recvfrom.c +++ b/net/local/local_recvfrom.c @@ -281,6 +281,7 @@ psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, { ndbg("ERROR: Failed to open FIFO for %s: %d\n", conn->lc_path, ret); + goto errout_with_halfduplex; return ret; } @@ -342,11 +343,15 @@ psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, while (remaining > 0); } - /* Now we can close the read-only socket descriptor */ + /* Now we can close the read-only file descriptor */ close(conn->lc_infd); conn->lc_infd = -1; + /* Release our reference to the half duplex FIFO*/ + + (void)local_release_halfduplex(conn); + /* Return the address family */ if (from) @@ -361,8 +366,15 @@ psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len, return readlen; errout_with_infd: + /* Close the read-only file descriptor */ + close(conn->lc_infd); conn->lc_infd = -1; + +errout_with_halfduplex: + /* Release our reference to the half duplex FIFO*/ + + (void)local_release_halfduplex(conn); return ret; } diff --git a/net/local/local_sendto.c b/net/local/local_sendto.c index 9c242c87a4d..449441759b2 100644 --- a/net/local/local_sendto.c +++ b/net/local/local_sendto.c @@ -141,7 +141,9 @@ ssize_t psock_local_sendto(FAR struct socket *psock, FAR const void *buf, { ndbg("ERROR: Failed to open FIFO for %s: %d\n", unaddr->sun_path, ret); - return ret; + + nsent = ret; + goto errout_with_halfduplex; } /* Send the packet */ @@ -163,6 +165,10 @@ ssize_t psock_local_sendto(FAR struct socket *psock, FAR const void *buf, close(conn->lc_outfd); conn->lc_outfd = -1; +errout_with_halfduplex: + /* Release our reference to the half duplex FIFO*/ + + (void)local_release_halfduplex(conn); return nsent; }