If a Unix domain socket is non-blocking, then the underlying FIFO should also be opened non-blocking

This commit is contained in:
Gregory Nutt 2015-01-30 12:43:37 -06:00
parent e8a74527a0
commit 62b706fa68
9 changed files with 69 additions and 45 deletions

View file

@ -44,6 +44,8 @@
#include <sys/types.h>
#include <sys/un.h>
#include <stdint.h>
#include <stdbool.h>
#include <semaphore.h>
#include <queue.h>
#include <stdint.h>
@ -243,26 +245,26 @@ int psock_local_bind(FAR struct socket *psock,
FAR const struct sockaddr *addr, socklen_t addrlen);
/****************************************************************************
* Name: local_connect
* Name: psock_local_connect
*
* Description:
* This function sets up a new local connection. The function will
* automatically allocate an unused local port for the new
* connection. However, another port can be chosen by using the
* psock_local_bind() call, after the local_connect() function has been
* called.
* psock_local_bind() call, after the psock_local_connect() function has
* been called.
*
* This function is called as part of the implementation of sendto
* and recvfrom.
*
* Input Parameters:
* client - A reference to the client-side local connection structure
* psock - A reference to the client-side socket structure
* addr - The address of the remote host.
*
****************************************************************************/
int local_connect(FAR struct local_conn_s *client,
FAR const struct sockaddr *addr);
int psock_local_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr);
/****************************************************************************
* Name: local_release
@ -536,7 +538,7 @@ int local_release_halfduplex(FAR struct local_conn_s *conn);
*
****************************************************************************/
int local_open_client_rx(FAR struct local_conn_s *client);
int local_open_client_rx(FAR struct local_conn_s *client, bool nonblock);
/****************************************************************************
* Name: local_open_client_tx
@ -546,7 +548,7 @@ int local_open_client_rx(FAR struct local_conn_s *client);
*
****************************************************************************/
int local_open_client_tx(FAR struct local_conn_s *client);
int local_open_client_tx(FAR struct local_conn_s *client, bool nonblock);
/****************************************************************************
* Name: local_open_server_rx
@ -556,7 +558,7 @@ int local_open_client_tx(FAR struct local_conn_s *client);
*
****************************************************************************/
int local_open_server_rx(FAR struct local_conn_s *server);
int local_open_server_rx(FAR struct local_conn_s *server, bool nonblock);
/****************************************************************************
* Name: local_open_server_tx
@ -566,7 +568,7 @@ int local_open_server_rx(FAR struct local_conn_s *server);
*
****************************************************************************/
int local_open_server_tx(FAR struct local_conn_s *server);
int local_open_server_tx(FAR struct local_conn_s *server, bool nonblock);
/****************************************************************************
* Name: local_open_receiver
@ -576,7 +578,7 @@ int local_open_server_tx(FAR struct local_conn_s *server);
*
****************************************************************************/
int local_open_receiver(FAR struct local_conn_s *conn);
int local_open_receiver(FAR struct local_conn_s *conn, bool nonblock);
/****************************************************************************
* Name: local_open_sender
@ -586,7 +588,8 @@ int local_open_receiver(FAR struct local_conn_s *conn);
*
****************************************************************************/
int local_open_sender(FAR struct local_conn_s *conn, FAR const char *path);
int local_open_sender(FAR struct local_conn_s *conn, FAR const char *path,
bool nonblock);
#undef EXTERN
#ifdef __cplusplus

View file

@ -143,7 +143,8 @@ int psock_local_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
* block.
*/
ret = local_open_server_tx(conn);
ret = local_open_server_tx(conn,
_SS_ISNONBLOCK(psock->s_flags));
if (ret < 0)
{
ndbg("ERROR: Failed to open write-only FIFOs for %s: %d\n",
@ -162,7 +163,8 @@ int psock_local_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
* for writing.
*/
ret = local_open_server_rx(conn);
ret = local_open_server_rx(conn,
_SS_ISNONBLOCK(psock->s_flags));
if (ret < 0)
{
ndbg("ERROR: Failed to open read-only FIFOs for %s: %d\n",

View file

@ -49,7 +49,10 @@
#include <nuttx/net/net.h>
#include <arch/irq.h>
#include "utils/utils.h"
#include "socket/socket.h"
#include "local/local.h"
/****************************************************************************
@ -100,7 +103,7 @@ static inline void _local_semtake(sem_t *sem)
int inline local_stream_connect(FAR struct local_conn_s *client,
FAR struct local_conn_s *server,
net_lock_t state)
bool nonblock, net_lock_t state)
{
int ret;
@ -139,7 +142,7 @@ int inline local_stream_connect(FAR struct local_conn_s *client,
* prevent the server-side from blocking as well.
*/
ret = local_open_client_tx(client);
ret = local_open_client_tx(client, nonblock);
if (ret < 0)
{
ndbg("ERROR: Failed to open write-only FIFOs for %s: %d\n",
@ -176,7 +179,7 @@ int inline local_stream_connect(FAR struct local_conn_s *client,
/* Yes.. open the read-only FIFO */
ret = local_open_client_rx(client);
ret = local_open_client_rx(client, nonblock);
if (ret < 0)
{
ndbg("ERROR: Failed to open write-only FIFOs for %s: %d\n",
@ -202,7 +205,7 @@ errout_with_fifos:
****************************************************************************/
/****************************************************************************
* Name: local_connect
* Name: psock_local_connect
*
* Description:
* Find a local connection structure that is the appropriate "server"
@ -222,14 +225,16 @@ errout_with_fifos:
*
****************************************************************************/
int local_connect(FAR struct local_conn_s *client,
FAR const struct sockaddr *addr)
int psock_local_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr)
{
FAR struct local_conn_s *client;
FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)addr;
FAR struct local_conn_s *conn;
net_lock_t state;
DEBUGASSERT(client);
DEBUGASSERT(psock && psock->s_conn);
client = (FAR struct local_conn_s *)psock->s_conn;
if (client->lc_state == LOCAL_STATE_ACCEPT ||
client->lc_state == LOCAL_STATE_CONNECTED)
@ -284,7 +289,9 @@ int local_connect(FAR struct local_conn_s *client,
if (conn->lc_proto == SOCK_STREAM)
{
ret = local_stream_connect(client, conn, state);
ret = local_stream_connect(client, conn,
_SS_ISNONBLOCK(psock->s_flags),
state);
}
net_unlock(state);

View file

@ -51,7 +51,6 @@
#include <errno.h>
#include <assert.h>
#include "local/local.h"
/****************************************************************************
@ -194,7 +193,7 @@ static int local_release_fifo(FAR const char *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.
* required to destroy the FIFO driver instance and all of its resources.
*/
#warning Missing logic
#if 0
@ -225,9 +224,12 @@ static int local_release_fifo(FAR const char *path)
*
****************************************************************************/
static int local_rx_open(FAR struct local_conn_s *conn, FAR const char *path)
static int local_rx_open(FAR struct local_conn_s *conn, FAR const char *path,
bool nonblock)
{
conn->lc_infd = open(path, O_RDONLY);
int oflags = nonblock ? O_RDONLY | O_NONBLOCK : O_RDONLY;
conn->lc_infd = open(path, oflags);
if (conn->lc_infd < 0)
{
int errcode = errno;
@ -258,9 +260,12 @@ static int local_rx_open(FAR struct local_conn_s *conn, FAR const char *path)
*
****************************************************************************/
static int local_tx_open(FAR struct local_conn_s *conn, FAR const char *path)
static int local_tx_open(FAR struct local_conn_s *conn, FAR const char *path,
bool nonblock)
{
conn->lc_outfd = open(path, O_WRONLY);
int oflags = nonblock ? O_WRONLY | O_NONBLOCK : O_WRONLY;
conn->lc_outfd = open(path, oflags);
if (conn->lc_outfd < 0)
{
int errcode = errno;
@ -418,7 +423,7 @@ int local_release_halfduplex(FAR struct local_conn_s *conn)
*
****************************************************************************/
int local_open_client_rx(FAR struct local_conn_s *client)
int local_open_client_rx(FAR struct local_conn_s *client, bool nonblock)
{
char path[LOCAL_FULLPATH_LEN];
int ret;
@ -429,7 +434,7 @@ int local_open_client_rx(FAR struct local_conn_s *client)
/* Then open the file for read-only access */
ret = local_rx_open(client, path);
ret = local_rx_open(client, path, nonblock);
if (ret == OK)
{
/* Policy: Free FIFO resources when the last reference is closed */
@ -448,7 +453,7 @@ int local_open_client_rx(FAR struct local_conn_s *client)
*
****************************************************************************/
int local_open_client_tx(FAR struct local_conn_s *client)
int local_open_client_tx(FAR struct local_conn_s *client, bool nonblock)
{
char path[LOCAL_FULLPATH_LEN];
int ret;
@ -459,7 +464,7 @@ int local_open_client_tx(FAR struct local_conn_s *client)
/* Then open the file for write-only access */
ret = local_tx_open(client, path);
ret = local_tx_open(client, path, nonblock);
if (ret == OK)
{
/* Policy: Free FIFO resources when the last reference is closed */
@ -478,7 +483,7 @@ int local_open_client_tx(FAR struct local_conn_s *client)
*
****************************************************************************/
int local_open_server_rx(FAR struct local_conn_s *server)
int local_open_server_rx(FAR struct local_conn_s *server, bool nonblock)
{
char path[LOCAL_FULLPATH_LEN];
int ret;
@ -489,7 +494,7 @@ int local_open_server_rx(FAR struct local_conn_s *server)
/* Then open the file for write-only access */
ret = local_rx_open(server, path);
ret = local_rx_open(server, path, nonblock);
if (ret == OK)
{
/* Policy: Free FIFO resources when the last reference is closed */
@ -508,7 +513,7 @@ int local_open_server_rx(FAR struct local_conn_s *server)
*
****************************************************************************/
int local_open_server_tx(FAR struct local_conn_s *server)
int local_open_server_tx(FAR struct local_conn_s *server, bool nonblock)
{
char path[LOCAL_FULLPATH_LEN];
int ret;
@ -519,7 +524,7 @@ int local_open_server_tx(FAR struct local_conn_s *server)
/* Then open the file for read-only access */
ret = local_tx_open(server, path);
ret = local_tx_open(server, path, nonblock);
if (ret == OK)
{
/* Policy: Free FIFO resources when the last reference is closed */
@ -538,7 +543,7 @@ int local_open_server_tx(FAR struct local_conn_s *server)
*
****************************************************************************/
int local_open_receiver(FAR struct local_conn_s *conn)
int local_open_receiver(FAR struct local_conn_s *conn, bool nonblock)
{
char path[LOCAL_FULLPATH_LEN];
int ret;
@ -549,7 +554,7 @@ int local_open_receiver(FAR struct local_conn_s *conn)
/* Then open the file for read-only access */
ret = local_rx_open(conn, path);
ret = local_rx_open(conn, path, nonblock);
if (ret == OK)
{
/* Policy: Free FIFO resources when the buffer is empty. */
@ -568,7 +573,8 @@ int local_open_receiver(FAR struct local_conn_s *conn)
*
****************************************************************************/
int local_open_sender(FAR struct local_conn_s *conn, FAR const char *path)
int local_open_sender(FAR struct local_conn_s *conn, FAR const char *path,
bool nonblock)
{
char fullpath[LOCAL_FULLPATH_LEN];
int ret;
@ -579,7 +585,7 @@ int local_open_sender(FAR struct local_conn_s *conn, FAR const char *path)
/* Then open the file for read-only access */
ret = local_tx_open(conn, fullpath);
ret = local_tx_open(conn, fullpath, nonblock);
if (ret == OK)
{
/* Policy: Free FIFO resources when the buffer is empty. */

View file

@ -46,6 +46,8 @@
#include <nuttx/net/net.h>
#include <arch/irq.h>
#include "local/local.h"
/****************************************************************************

View file

@ -276,7 +276,7 @@ psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Open the receiving side of the transfer */
ret = local_open_receiver(conn);
ret = local_open_receiver(conn, _SS_ISNONBLOCK(psock->s_flags));
if (ret < 0)
{
ndbg("ERROR: Failed to open FIFO for %s: %d\n",
@ -337,7 +337,7 @@ psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
/* Adjust the number of bytes remaining to be read from the packet */
DEBUGASSERT(tmplen <= remaining);
DEBUGASSERT(tmplen <= remain);
remaining -= tmplen;
}
while (remaining > 0);

View file

@ -47,6 +47,8 @@
#include <nuttx/net/net.h>
#include <arch/irq.h>
#include "local/local.h"
/****************************************************************************

View file

@ -49,6 +49,7 @@
#include <nuttx/net/net.h>
#include "socket/socket.h"
#include "local/local.h"
/****************************************************************************
@ -136,7 +137,8 @@ ssize_t psock_local_sendto(FAR struct socket *psock, FAR const void *buf,
/* Open the sending side of the transfer */
ret = local_open_sender(conn, unaddr->sun_path);
ret = local_open_sender(conn, unaddr->sun_path,
_SS_ISNONBLOCK(psock->s_flags));
if (ret < 0)
{
ndbg("ERROR: Failed to open FIFO for %s: %d\n",

View file

@ -545,7 +545,7 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
{
/* Connect to the local Unix domain server */
ret = local_connect(psock->s_conn, addr);
ret = psock_local_connect(psock, addr);
}
#endif /* CONFIG_NET_LOCAL */
@ -579,7 +579,7 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
{
/* Perform the datagram connection logic */
ret = local_connect(psock->s_conn, addr);
ret = psock_local_connect(psock, addr);
}
#endif /* CONFIG_NET_LOCAL */