2015-01-26 20:30:27 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* net/local/local_fifo.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#if defined(CONFIG_NET) && defined(CONFIG_NET_LOCAL)
|
|
|
|
|
|
|
|
#include <sys/stat.h>
|
2015-01-30 18:14:24 +01:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
2015-01-26 20:30:27 +01:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include "local/local.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
#define LOCAL_CS_SUFFIX "CS" /* Name of the client-to-server FIFO */
|
|
|
|
#define LOCAL_SC_SUFFIX "SC" /* Name of the server-to-client FIFO */
|
|
|
|
#define LOCAL_HD_SUFFIX "HD" /* Name of the half duplex datagram FIFO */
|
2015-01-26 20:30:27 +01:00
|
|
|
#define LOCAL_SUFFIX_LEN 2
|
|
|
|
|
|
|
|
#define LOCAL_FULLPATH_LEN (UNIX_PATH_MAX + LOCAL_SUFFIX_LEN)
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-01-29 14:47:09 +01:00
|
|
|
* Name: local_cs_name
|
2015-01-26 20:30:27 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2015-01-29 14:47:09 +01:00
|
|
|
* Create the name of the client-to-server FIFO.
|
2015-01-26 20:30:27 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_STREAM
|
2015-01-29 14:47:09 +01:00
|
|
|
static inline void local_cs_name(FAR struct local_conn_s *conn,
|
2015-01-26 20:30:27 +01:00
|
|
|
FAR char *path)
|
|
|
|
{
|
2015-05-12 15:47:32 +02:00
|
|
|
if (conn->lc_instance_id < 0)
|
|
|
|
{
|
|
|
|
(void)snprintf(path, LOCAL_FULLPATH_LEN-1, "%s" LOCAL_CS_SUFFIX,
|
|
|
|
conn->lc_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
(void)snprintf(path, LOCAL_FULLPATH_LEN-1, "%s" LOCAL_CS_SUFFIX "%x",
|
|
|
|
conn->lc_path, conn->lc_instance_id);
|
|
|
|
}
|
|
|
|
|
2015-01-29 17:40:10 +01:00
|
|
|
path[LOCAL_FULLPATH_LEN-1] = '\0';
|
2015-01-26 20:30:27 +01:00
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_STREAM */
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-01-29 14:47:09 +01:00
|
|
|
* Name: local_sc_name
|
2015-01-26 20:30:27 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2015-01-29 14:47:09 +01:00
|
|
|
* Create the name of the server-to-client FIFO.
|
2015-01-26 20:30:27 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_STREAM
|
2015-01-29 14:47:09 +01:00
|
|
|
static inline void local_sc_name(FAR struct local_conn_s *conn,
|
2015-01-26 20:30:27 +01:00
|
|
|
FAR char *path)
|
|
|
|
{
|
2015-05-12 15:47:32 +02:00
|
|
|
if (conn->lc_instance_id < 0)
|
|
|
|
{
|
|
|
|
(void)snprintf(path, LOCAL_FULLPATH_LEN-1, "%s" LOCAL_SC_SUFFIX,
|
|
|
|
conn->lc_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
(void)snprintf(path, LOCAL_FULLPATH_LEN-1, "%s" LOCAL_SC_SUFFIX "%x",
|
|
|
|
conn->lc_path, conn->lc_instance_id);
|
|
|
|
}
|
|
|
|
|
2015-01-29 17:40:10 +01:00
|
|
|
path[LOCAL_FULLPATH_LEN-1] = '\0';
|
2015-01-29 14:47:09 +01:00
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_STREAM */
|
2015-01-29 14:47:09 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: local_hd_name
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Create the name of the half duplex, datagram FIFO.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_DGRAM
|
2015-01-29 17:40:10 +01:00
|
|
|
static inline void local_hd_name(FAR const char *inpath, FAR char *outpath)
|
2015-01-29 14:47:09 +01:00
|
|
|
{
|
2015-01-29 17:40:10 +01:00
|
|
|
(void)snprintf(outpath, LOCAL_FULLPATH_LEN-1, "%s" LOCAL_HD_SUFFIX, inpath);
|
|
|
|
outpath[LOCAL_FULLPATH_LEN-1] = '\0';
|
2015-01-26 20:30:27 +01:00
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_DGRAM */
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: local_fifo_exists
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Check if a FIFO exists.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static bool local_fifo_exists(FAR const char *path)
|
|
|
|
{
|
|
|
|
struct stat buf;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Create the client-to-server FIFO */
|
|
|
|
|
|
|
|
ret = stat(path, &buf);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIFOs are character devices in NuttX. Return true if what we found
|
|
|
|
* is a FIFO. What if it is something else? In that case, we will
|
|
|
|
* return false and mkfifo() will fail.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return (bool)S_ISCHR(buf.st_mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: local_create_fifo
|
|
|
|
*
|
|
|
|
* Description:
|
2015-01-29 14:47:09 +01:00
|
|
|
* Create the one FIFO.
|
2015-01-26 20:30:27 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int local_create_fifo(FAR const char *path)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Create the client-to-server FIFO if it does not already exist. */
|
|
|
|
|
|
|
|
if (!local_fifo_exists(path))
|
|
|
|
{
|
|
|
|
ret = mkfifo(path, 0644);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2015-07-05 19:18:56 +02:00
|
|
|
int errcode = get_errno();
|
2015-01-26 20:30:27 +01:00
|
|
|
DEBUGASSERT(errcode > 0);
|
|
|
|
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Failed to create FIFO %s: %d\n", path, errcode);
|
2015-01-26 20:30:27 +01:00
|
|
|
return -errcode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The FIFO (or some character driver) exists at PATH or we successfully
|
|
|
|
* created the FIFO at that location.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-01-30 16:28:55 +01:00
|
|
|
* Name: local_release_fifo
|
2015-01-26 20:30:27 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2015-01-30 16:28:55 +01:00
|
|
|
* Release a reference from one of the FIFOs used in a connection.
|
2015-01-26 20:30:27 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-02-01 16:16:55 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_STREAM /* Currently not used by datagram code */
|
2015-01-30 16:28:55 +01:00
|
|
|
static int local_release_fifo(FAR const char *path)
|
2015-01-26 20:30:27 +01:00
|
|
|
{
|
2015-02-01 15:52:26 +01:00
|
|
|
int ret;
|
|
|
|
|
2015-01-30 16:28:55 +01:00
|
|
|
/* Unlink the client-to-server FIFO if it exists. */
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
if (local_fifo_exists(path))
|
|
|
|
{
|
2015-02-01 15:52:26 +01:00
|
|
|
/* Un-linking the FIFO removes the FIFO from the namespace. It will
|
|
|
|
* also mark the FIFO device "unlinked". When all of the open
|
|
|
|
* references to the FIFO device are closed, the resources consumed
|
|
|
|
* by the device instance will also be freed.
|
2015-01-30 16:28:55 +01:00
|
|
|
*/
|
2015-01-30 18:14:24 +01:00
|
|
|
|
2015-01-26 20:30:27 +01:00
|
|
|
ret = unlink(path);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2015-07-05 19:18:56 +02:00
|
|
|
int errcode = get_errno();
|
2015-01-26 20:30:27 +01:00
|
|
|
DEBUGASSERT(errcode > 0);
|
|
|
|
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Failed to unlink FIFO %s: %d\n", path, errcode);
|
2015-01-26 20:30:27 +01:00
|
|
|
return -errcode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The FIFO does not exist or we successfully unlinked it. */
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
2015-02-01 16:16:55 +01:00
|
|
|
#endif
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: local_rx_open
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Open a FIFO for read-only access.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-30 19:43:37 +01:00
|
|
|
static int local_rx_open(FAR struct local_conn_s *conn, FAR const char *path,
|
|
|
|
bool nonblock)
|
2015-01-26 20:30:27 +01:00
|
|
|
{
|
2015-01-30 19:43:37 +01:00
|
|
|
int oflags = nonblock ? O_RDONLY | O_NONBLOCK : O_RDONLY;
|
2017-11-02 15:23:38 +01:00
|
|
|
int ret;
|
|
|
|
int fd;
|
2015-01-30 19:43:37 +01:00
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
fd = open(path, oflags);
|
|
|
|
if (fd < 0)
|
2015-01-26 20:30:27 +01:00
|
|
|
{
|
2015-07-05 19:18:56 +02:00
|
|
|
int errcode = get_errno();
|
2015-01-26 20:30:27 +01:00
|
|
|
DEBUGASSERT(errcode > 0);
|
|
|
|
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Failed on open %s for reading: %d\n",
|
2015-01-26 20:30:27 +01:00
|
|
|
path, errcode);
|
|
|
|
|
|
|
|
/* Map the errcode to something consistent with the return
|
|
|
|
* error codes from connect():
|
|
|
|
*
|
|
|
|
* If errcode is ENOENT, meaning that the FIFO does exist,
|
|
|
|
* return EFAULT meaning that the socket structure address is
|
|
|
|
* outside the user's address space.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return errcode == ENOENT ? -EFAULT : -errcode;
|
|
|
|
}
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
/* Detach the file descriptor from the open file instance */
|
|
|
|
|
|
|
|
ret = file_detach(fd, &conn->lc_infile);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-01-26 20:30:27 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: local_tx_open
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Open a FIFO for write-only access.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-30 19:43:37 +01:00
|
|
|
static int local_tx_open(FAR struct local_conn_s *conn, FAR const char *path,
|
|
|
|
bool nonblock)
|
2015-01-26 20:30:27 +01:00
|
|
|
{
|
2015-01-30 19:43:37 +01:00
|
|
|
int oflags = nonblock ? O_WRONLY | O_NONBLOCK : O_WRONLY;
|
2017-11-02 15:23:38 +01:00
|
|
|
int ret;
|
|
|
|
int fd;
|
2015-01-30 19:43:37 +01:00
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
fd = open(path, oflags);
|
|
|
|
if (fd < 0)
|
2015-01-26 20:30:27 +01:00
|
|
|
{
|
2015-07-05 19:18:56 +02:00
|
|
|
int errcode = get_errno();
|
2015-01-26 20:30:27 +01:00
|
|
|
DEBUGASSERT(errcode > 0);
|
|
|
|
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Failed on open %s for writing: %d\n",
|
2015-01-26 20:30:27 +01:00
|
|
|
path, errcode);
|
|
|
|
|
|
|
|
/* Map the errcode to something consistent with the return
|
|
|
|
* error codes from connect():
|
|
|
|
*
|
|
|
|
* If errcode is ENOENT, meaning that the FIFO does exist,
|
|
|
|
* return EFAULT meaning that the socket structure address is
|
|
|
|
* outside the user's address space.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return errcode == ENOENT ? -EFAULT : -errcode;
|
|
|
|
}
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
/* Detach the file descriptor from the open file instance */
|
|
|
|
|
|
|
|
ret = file_detach(fd, &conn->lc_outfile);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-01-26 20:30:27 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2015-01-30 18:14:24 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: local_set_policy
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Set the FIFO buffer policy:
|
|
|
|
*
|
|
|
|
* 0=Free FIFO resources when the last reference is closed
|
|
|
|
* 1=Free FIFO resources when the buffer is empty.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
static int local_set_policy(FAR struct file *filep, unsigned long policy)
|
2015-01-30 18:14:24 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Set the buffer policy */
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
ret = file_ioctl(filep, PIPEIOC_POLICY, policy);
|
2015-01-30 18:14:24 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2017-11-02 15:23:38 +01:00
|
|
|
nerr("ERROR: Failed to set FIFO buffer policty: %d\n", ret);
|
2015-01-30 18:14:24 +01:00
|
|
|
}
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
return ret;
|
2015-01-30 18:14:24 +01:00
|
|
|
}
|
|
|
|
|
2015-01-26 20:30:27 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: local_create_fifos
|
|
|
|
*
|
|
|
|
* Description:
|
2015-01-29 14:47:09 +01:00
|
|
|
* Create the FIFO pair needed for a SOCK_STREAM connection.
|
2015-01-26 20:30:27 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_STREAM
|
2015-01-29 14:47:09 +01:00
|
|
|
int local_create_fifos(FAR struct local_conn_s *conn)
|
2015-01-26 20:30:27 +01:00
|
|
|
{
|
|
|
|
char path[LOCAL_FULLPATH_LEN];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Create the client-to-server FIFO if it does not already exist. */
|
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
local_cs_name(conn, path);
|
2015-01-26 20:30:27 +01:00
|
|
|
ret = local_create_fifo(path);
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
/* Create the server-to-client FIFO if it does not already exist. */
|
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
local_sc_name(conn, path);
|
2015-01-26 20:30:27 +01:00
|
|
|
ret = local_create_fifo(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_STREAM */
|
2015-01-26 20:30:27 +01:00
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: local_create_halfduplex
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Create the half-duplex FIFO needed for SOCK_DGRAM communication.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_DGRAM
|
2015-01-29 18:05:04 +01:00
|
|
|
int local_create_halfduplex(FAR struct local_conn_s *conn, FAR const char *path)
|
2015-01-29 14:47:09 +01:00
|
|
|
{
|
2015-01-29 18:05:04 +01:00
|
|
|
char fullpath[LOCAL_FULLPATH_LEN];
|
2015-01-29 14:47:09 +01:00
|
|
|
|
|
|
|
/* Create the half duplex FIFO if it does not already exist. */
|
|
|
|
|
2015-01-29 18:05:04 +01:00
|
|
|
local_hd_name(path, fullpath);
|
|
|
|
return local_create_fifo(fullpath);
|
2015-01-29 14:47:09 +01:00
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_DGRAM */
|
2015-01-29 14:47:09 +01:00
|
|
|
|
2015-01-26 20:30:27 +01:00
|
|
|
/****************************************************************************
|
2015-01-30 16:28:55 +01:00
|
|
|
* Name: local_release_fifos
|
2015-01-26 20:30:27 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2015-01-30 16:28:55 +01:00
|
|
|
* Release references to the FIFO pair used for a SOCK_STREAM connection.
|
2015-01-26 20:30:27 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_STREAM
|
2015-01-30 16:28:55 +01:00
|
|
|
int local_release_fifos(FAR struct local_conn_s *conn)
|
2015-01-26 20:30:27 +01:00
|
|
|
{
|
|
|
|
char path[LOCAL_FULLPATH_LEN];
|
|
|
|
int ret1;
|
|
|
|
int ret2;
|
|
|
|
|
|
|
|
/* Destroy the client-to-server FIFO if it exists. */
|
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
local_sc_name(conn, path);
|
2015-01-30 16:28:55 +01:00
|
|
|
ret1 = local_release_fifo(path);
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/* Destroy the server-to-client FIFO if it exists. */
|
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
local_cs_name(conn, path);
|
2015-02-01 16:16:55 +01:00
|
|
|
ret2 = local_release_fifo(path);
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/* Return a failure if one occurred. */
|
|
|
|
|
|
|
|
return ret1 < 0 ? ret1 : ret2;
|
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_STREAM */
|
2015-01-26 20:30:27 +01:00
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
/****************************************************************************
|
2015-01-30 16:28:55 +01:00
|
|
|
* Name: local_release_halfduplex
|
2015-01-29 14:47:09 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2015-01-30 16:28:55 +01:00
|
|
|
* Release a reference to the FIFO used for SOCK_DGRAM communication
|
2015-01-29 14:47:09 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_DGRAM
|
2015-01-30 16:28:55 +01:00
|
|
|
int local_release_halfduplex(FAR struct local_conn_s *conn)
|
2015-01-29 14:47:09 +01:00
|
|
|
{
|
2015-02-01 16:16:55 +01:00
|
|
|
#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.
|
|
|
|
*
|
2015-02-01 19:23:57 +01:00
|
|
|
* I am thinking that there should be something like a timer. The timer
|
2015-02-01 16:16:55 +01:00
|
|
|
* 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
|
2015-01-29 14:47:09 +01:00
|
|
|
char path[LOCAL_FULLPATH_LEN];
|
|
|
|
|
|
|
|
/* Destroy the half duplex FIFO if it exists. */
|
|
|
|
|
2015-01-29 17:40:10 +01:00
|
|
|
local_hd_name(conn->lc_path, path);
|
2015-01-30 16:28:55 +01:00
|
|
|
return local_release_fifo(path);
|
2015-02-01 16:16:55 +01:00
|
|
|
#endif
|
2015-01-29 14:47:09 +01:00
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_DGRAM */
|
2015-01-29 14:47:09 +01:00
|
|
|
|
2015-01-26 20:30:27 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: local_open_client_rx
|
|
|
|
*
|
|
|
|
* Description:
|
2015-01-29 14:47:09 +01:00
|
|
|
* Open the client-side of the server-to-client FIFO.
|
2015-01-26 20:30:27 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_STREAM
|
2015-01-30 19:43:37 +01:00
|
|
|
int local_open_client_rx(FAR struct local_conn_s *client, bool nonblock)
|
2015-01-26 20:30:27 +01:00
|
|
|
{
|
|
|
|
char path[LOCAL_FULLPATH_LEN];
|
2015-01-30 18:14:24 +01:00
|
|
|
int ret;
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/* Get the server-to-client path name */
|
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
local_sc_name(client, path);
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/* Then open the file for read-only access */
|
|
|
|
|
2015-01-30 19:43:37 +01:00
|
|
|
ret = local_rx_open(client, path, nonblock);
|
2015-01-30 18:14:24 +01:00
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
/* Policy: Free FIFO resources when the last reference is closed */
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
ret = local_set_policy(&client->lc_infile, 0);
|
2015-01-30 18:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2015-01-26 20:30:27 +01:00
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_STREAM */
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: local_open_client_tx
|
|
|
|
*
|
|
|
|
* Description:
|
2015-01-29 14:47:09 +01:00
|
|
|
* Open the client-side of the client-to-server FIFO.
|
2015-01-26 20:30:27 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_STREAM
|
2015-01-30 19:43:37 +01:00
|
|
|
int local_open_client_tx(FAR struct local_conn_s *client, bool nonblock)
|
2015-01-26 20:30:27 +01:00
|
|
|
{
|
|
|
|
char path[LOCAL_FULLPATH_LEN];
|
2015-01-30 18:14:24 +01:00
|
|
|
int ret;
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/* Get the client-to-server path name */
|
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
local_cs_name(client, path);
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/* Then open the file for write-only access */
|
|
|
|
|
2015-01-30 19:43:37 +01:00
|
|
|
ret = local_tx_open(client, path, nonblock);
|
2015-01-30 18:14:24 +01:00
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
/* Policy: Free FIFO resources when the last reference is closed */
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
ret = local_set_policy(&client->lc_outfile, 0);
|
2015-01-30 18:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2015-01-26 20:30:27 +01:00
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_STREAM */
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: local_open_server_rx
|
|
|
|
*
|
|
|
|
* Description:
|
2015-01-29 14:47:09 +01:00
|
|
|
* Open the server-side of the client-to-server FIFO.
|
2015-01-26 20:30:27 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_STREAM
|
2015-01-30 19:43:37 +01:00
|
|
|
int local_open_server_rx(FAR struct local_conn_s *server, bool nonblock)
|
2015-01-26 20:30:27 +01:00
|
|
|
{
|
|
|
|
char path[LOCAL_FULLPATH_LEN];
|
2015-01-30 18:14:24 +01:00
|
|
|
int ret;
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/* Get the client-to-server path name */
|
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
local_cs_name(server, path);
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/* Then open the file for write-only access */
|
|
|
|
|
2015-01-30 19:43:37 +01:00
|
|
|
ret = local_rx_open(server, path, nonblock);
|
2015-01-30 18:14:24 +01:00
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
/* Policy: Free FIFO resources when the last reference is closed */
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
ret = local_set_policy(&server->lc_infile, 0);
|
2015-01-30 18:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2015-01-26 20:30:27 +01:00
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_STREAM */
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: local_open_server_tx
|
|
|
|
*
|
|
|
|
* Description:
|
2015-01-29 14:47:09 +01:00
|
|
|
* Only the server-side of the server-to-client FIFO.
|
2015-01-26 20:30:27 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_STREAM
|
2015-01-30 19:43:37 +01:00
|
|
|
int local_open_server_tx(FAR struct local_conn_s *server, bool nonblock)
|
2015-01-26 20:30:27 +01:00
|
|
|
{
|
|
|
|
char path[LOCAL_FULLPATH_LEN];
|
2015-01-30 18:14:24 +01:00
|
|
|
int ret;
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/* Get the server-to-client path name */
|
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
local_sc_name(server, path);
|
2015-01-26 20:30:27 +01:00
|
|
|
|
|
|
|
/* Then open the file for read-only access */
|
|
|
|
|
2015-01-30 19:43:37 +01:00
|
|
|
ret = local_tx_open(server, path, nonblock);
|
2015-01-30 18:14:24 +01:00
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
/* Policy: Free FIFO resources when the last reference is closed */
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
ret = local_set_policy(&server->lc_outfile, 0);
|
2015-01-30 18:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2015-01-26 20:30:27 +01:00
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_STREAM */
|
2015-01-29 14:47:09 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: local_open_receiver
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Only the receiving side of the half duplex FIFO.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_DGRAM
|
2015-01-30 19:43:37 +01:00
|
|
|
int local_open_receiver(FAR struct local_conn_s *conn, bool nonblock)
|
2015-01-29 14:47:09 +01:00
|
|
|
{
|
|
|
|
char path[LOCAL_FULLPATH_LEN];
|
2015-01-30 18:14:24 +01:00
|
|
|
int ret;
|
2015-01-29 14:47:09 +01:00
|
|
|
|
|
|
|
/* Get the server-to-client path name */
|
|
|
|
|
2015-01-29 17:40:10 +01:00
|
|
|
local_hd_name(conn->lc_path, path);
|
2015-01-29 14:47:09 +01:00
|
|
|
|
|
|
|
/* Then open the file for read-only access */
|
|
|
|
|
2015-01-30 19:43:37 +01:00
|
|
|
ret = local_rx_open(conn, path, nonblock);
|
2015-01-30 18:14:24 +01:00
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
/* Policy: Free FIFO resources when the buffer is empty. */
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
ret = local_set_policy(&conn->lc_infile, 1);
|
2015-01-30 18:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2015-01-29 14:47:09 +01:00
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_DGRAM */
|
2015-01-29 14:47:09 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: local_open_sender
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Only the sending side of the half duplex FIFO.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_DGRAM
|
2015-01-30 19:43:37 +01:00
|
|
|
int local_open_sender(FAR struct local_conn_s *conn, FAR const char *path,
|
|
|
|
bool nonblock)
|
2015-01-29 14:47:09 +01:00
|
|
|
{
|
2015-01-29 17:40:10 +01:00
|
|
|
char fullpath[LOCAL_FULLPATH_LEN];
|
2015-01-30 18:14:24 +01:00
|
|
|
int ret;
|
2015-01-29 14:47:09 +01:00
|
|
|
|
|
|
|
/* Get the server-to-client path name */
|
|
|
|
|
2015-01-29 17:40:10 +01:00
|
|
|
local_hd_name(path, fullpath);
|
2015-01-29 14:47:09 +01:00
|
|
|
|
|
|
|
/* Then open the file for read-only access */
|
|
|
|
|
2015-01-30 19:43:37 +01:00
|
|
|
ret = local_tx_open(conn, fullpath, nonblock);
|
2015-01-30 18:14:24 +01:00
|
|
|
if (ret == OK)
|
|
|
|
{
|
|
|
|
/* Policy: Free FIFO resources when the buffer is empty. */
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
ret = local_set_policy(&conn->lc_outfile, 1);
|
2015-01-30 18:14:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
2015-01-29 14:47:09 +01:00
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_DGRAM */
|
2015-01-29 14:47:09 +01:00
|
|
|
|
2015-01-26 20:30:27 +01:00
|
|
|
#endif /* CONFIG_NET && CONFIG_NET_LOCAL */
|