Unix domain: Add logic to release references to the half duplex FIFO after sendto and recvfrom
This commit is contained in:
parent
a5b6ddbc64
commit
2a39105b3f
@ -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
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user