Unix domain: Enable logic to clean up the FIFOs underlying stream sockets with those sockets are disconnected. Tehre is still no corresponding clean-up logic in place for Unix domain datagram sockets because the life of the FIFO is not as well known in that case

This commit is contained in:
Gregory Nutt
2015-02-01 08:52:26 -06:00
parent f472041ce2
commit f8bb77365a
2 changed files with 48 additions and 28 deletions
+23 -21
View File
@@ -826,13 +826,12 @@ o Network (net/, drivers/net)
Title: SOCKETS DO NOT ALWAYS SUPPORT O_NONBLOCK Title: SOCKETS DO NOT ALWAYS SUPPORT O_NONBLOCK
Description: sockets do not support all modes for O_NONBLOCK. Sockets Description: sockets do not support all modes for O_NONBLOCK. Sockets
support only (1) TCP/IP non-blocking read operations when read-ahead support nonblocking operations only (1) for TCP/IP non-
buffering is enabled, (2) TCP/IP accept() operations when TCP/IP blocking read operations when read-ahead buffering is
connection backlog is enabled, and (3) nonblocking operations on enabled, (2) TCP/IP accept() operations when TCP/IP
Unix domain sockets. connection backlog is enabled, (2) UDP/IP read() operations
REVISIT: UDP read-ahead buffering has been implemented. But I when UDP read-ahead is enabled, and (3) non-blocking
do not think that the necessary bits of logic are in place to operations on Unix domain sockets.
permit non-clocking UDP reads.
Status: Open Status: Open
Priority: Low. Priority: Low.
@@ -923,20 +922,23 @@ o Network (net/, drivers/net)
Status: Open Status: Open
Priority: Low, this is just a nuisance in most cases. Priority: Low, this is just a nuisance in most cases.
Title: FIFO CLEAN-UP AFTER CLOSING UNIX DOMAIN SOCKET Title: FIFO CLEAN-UP AFTER CLOSING UNIX DOMAIN DATAGRAM SOCKET
Description: FIFOs are used as the IPC underlying local Unix domain sockets. Description: FIFOs are used as the IPC underlying all local Unix domain
In NuttX, FIFOs are implemented as device drivers (not as sockets. In NuttX, FIFOs are implemented as device drivers
special files). The FIFO device driver is instantiated when (not as a special FIFO files). The FIFO device driver is
the Unix domain socket communications begin and will instantiated when the Unix domain socket communications begin
automatically be released when (1) the driver is unlinked and and will automatically be released when (1) the driver is
(2) all open references to the driver have been closed. But unlinked and (2) all open references to the driver have been
there is no mechanism in place now to unline the FIFO when closed. But there is no mechanism in place now to unlink the
the Unix domain socket is no longer used. The primary issue FIFO when the Unix domain datagram socket is no longer used.
is timing.. the FIFO should persist until it is no longer The primary issue is timing.. the FIFO should persist until
needed. Perhaps there should be a delayed call to unlink() it is no longer needed. Perhaps there should be a delayed
(using a watchdog or the work queue). If the driver is re- call to unlink() (using a watchdog or the work queue). If
opened, the delayed unlink could be canceled? Needs more the driver is re-opened, the delayed unlink could be
thought. cancelled? Needs more thought.
NOTE: This is not an issue for Unix domain streams sockets:
The end-of-life of the FIFO is well determined when sockets
are disconnected and support for that case is fully implemented.
Status: Open Status: Open
Priority: Low for now because I don't have a situation where this is a Priority: Low for now because I don't have a situation where this is a
problem for me. If you use the same Unix domain paths, then problem for me. If you use the same Unix domain paths, then
+25 -7
View File
@@ -193,17 +193,17 @@ static int local_create_fifo(FAR const char *path)
static int local_release_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. */ /* Unlink the client-to-server FIFO if it exists. */
if (local_fifo_exists(path)) if (local_fifo_exists(path))
{ {
/* REVISIT: This is wrong! Un-linking the FIFO does not eliminate it; /* Un-linking the FIFO removes the FIFO from the namespace. It will
* it only removes it from the namespace. A new interface will be * also mark the FIFO device "unlinked". When all of the open
* required to destroy the FIFO driver instance and all of its resources. * references to the FIFO device are closed, the resources consumed
* by the device instance will also be freed.
*/ */
#warning Missing logic
#if 0
int ret;
ret = unlink(path); ret = unlink(path);
if (ret < 0) if (ret < 0)
@@ -214,7 +214,6 @@ static int local_release_fifo(FAR const char *path)
ndbg("ERROR: Failed to unlink FIFO %s: %d\n", path, errcode); ndbg("ERROR: Failed to unlink FIFO %s: %d\n", path, errcode);
return -errcode; return -errcode;
} }
#endif
} }
/* The FIFO does not exist or we successfully unlinked it. */ /* The FIFO does not exist or we successfully unlinked it. */
@@ -440,6 +439,24 @@ int local_release_halfduplex(FAR struct local_conn_s *conn)
#ifdef CONFIG_NET_LOCAL_STREAM #ifdef CONFIG_NET_LOCAL_STREAM
int local_open_client_rx(FAR struct local_conn_s *client, bool nonblock) int local_open_client_rx(FAR struct local_conn_s *client, bool nonblock)
{ {
#if 1
/* REVIST: We need to think about this carefully. Unlike the connection-
* oriented Unix domain socket, we don't really know the best time to
* release the FIFO resource. It would be extremely inefficient to create
* and destroy the FIFO on each packet. But, on the other hand, failing
* to destory the FIFO will leave the FIFO resources in place after the
* communications have completed.
*
* I am thinking that ther should be something like a timer. The timer
* would be started at the completion of each transfer and cancelled at
* the beginning of each transfer. If the timer expires, then the FIFO
* would be destroyed.
*/
# warning Missing logic
return OK;
#else
char path[LOCAL_FULLPATH_LEN]; char path[LOCAL_FULLPATH_LEN];
int ret; int ret;
@@ -458,6 +475,7 @@ int local_open_client_rx(FAR struct local_conn_s *client, bool nonblock)
} }
return ret; return ret;
#endif
} }
#endif /* CONFIG_NET_LOCAL_STREAM */ #endif /* CONFIG_NET_LOCAL_STREAM */