2015-01-27 00:28:36 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* net/local/local_recvfrom.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/types.h>
|
|
|
|
#include <sys/socket.h>
|
2015-01-29 14:47:09 +01:00
|
|
|
#include <unistd.h>
|
2015-01-27 00:28:36 +01:00
|
|
|
#include <errno.h>
|
2015-01-27 18:51:24 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <debug.h>
|
2015-01-27 00:28:36 +01:00
|
|
|
|
|
|
|
#include <nuttx/net/net.h>
|
|
|
|
|
2015-01-27 18:51:24 +01:00
|
|
|
#include "socket/socket.h"
|
2015-01-27 00:28:36 +01:00
|
|
|
#include "local/local.h"
|
|
|
|
|
2015-01-27 18:51:24 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Pre-processor Definitions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef MIN
|
|
|
|
# define MIN(a,b) ((a) < (b) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-01-29 14:47:09 +01:00
|
|
|
* Private Functions
|
2015-01-27 18:51:24 +01:00
|
|
|
****************************************************************************/
|
2015-01-29 14:47:09 +01:00
|
|
|
|
2015-01-27 18:51:24 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: psock_fifo_read
|
|
|
|
*
|
|
|
|
* Description:
|
2015-01-29 14:47:09 +01:00
|
|
|
* A thin layer around local_fifo_read that handles socket-related loss-of-
|
2015-01-27 18:51:24 +01:00
|
|
|
* connection events.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static int psock_fifo_read(FAR struct socket *psock, FAR void *buf,
|
|
|
|
FAR size_t *readlen)
|
|
|
|
{
|
|
|
|
FAR struct local_conn_s *conn = (FAR struct local_conn_s *)psock->s_conn;
|
|
|
|
int ret;
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
ret = local_fifo_read(&conn->lc_infile, buf, readlen);
|
2015-01-27 18:51:24 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
/* -ECONNRESET is a special case. We may or not have received
|
|
|
|
* data, then the peer closed the connection.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ret == -ECONNRESET)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Lost connection: %d\n", ret);
|
2015-01-27 18:51:24 +01:00
|
|
|
|
|
|
|
/* Report an ungraceful loss of connection. This should
|
|
|
|
* eventually be reported as ENOTCONN.
|
|
|
|
*/
|
|
|
|
|
2015-10-08 23:10:04 +02:00
|
|
|
psock->s_flags &= ~(_SF_CONNECTED | _SF_CLOSED);
|
2015-01-27 18:51:24 +01:00
|
|
|
conn->lc_state = LOCAL_STATE_DISCONNECTED;
|
|
|
|
|
|
|
|
/* Did we receive any data? */
|
|
|
|
|
|
|
|
if (*readlen <= 0)
|
|
|
|
{
|
|
|
|
/* No.. return the ECONNRESET error now. Otherwise,
|
|
|
|
* process the received data and return ENOTCONN the
|
2020-02-23 09:50:23 +01:00
|
|
|
* next time that psock_recvfrom() is called.
|
2015-01-27 18:51:24 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Failed to read packet: %d\n", ret);
|
2015-01-27 18:51:24 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2015-10-04 23:28:54 +02:00
|
|
|
|
2015-01-27 18:51:24 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2015-01-27 00:28:36 +01:00
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: psock_stream_recvfrom
|
2015-01-27 00:28:36 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2015-01-29 14:47:09 +01:00
|
|
|
* psock_stream_recvfrom() receives messages from a local stream socket.
|
2015-01-27 00:28:36 +01:00
|
|
|
*
|
2015-01-29 14:47:09 +01:00
|
|
|
* Input Parameters:
|
2015-01-27 00:28:36 +01:00
|
|
|
* psock A pointer to a NuttX-specific, internal socket structure
|
|
|
|
* buf Buffer to receive data
|
|
|
|
* len Length of buffer
|
|
|
|
* flags Receive flags
|
|
|
|
* from Address of source (may be NULL)
|
|
|
|
* fromlen The length of the address structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
2015-01-29 14:47:09 +01:00
|
|
|
* On success, returns the number of characters received. If no data is
|
2015-01-27 00:28:36 +01:00
|
|
|
* available to be received and the peer has performed an orderly shutdown,
|
|
|
|
* recv() will return 0. Otherwise, on errors, -1 is returned, and errno
|
2015-01-27 18:51:24 +01:00
|
|
|
* is set appropriately (see receive from for the complete list).
|
2015-01-27 00:28:36 +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 ssize_t
|
|
|
|
psock_stream_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|
|
|
int flags, FAR struct sockaddr *from,
|
|
|
|
FAR socklen_t *fromlen)
|
2015-01-27 00:28:36 +01:00
|
|
|
{
|
2015-01-29 14:47:09 +01:00
|
|
|
FAR struct local_conn_s *conn = (FAR struct local_conn_s *)psock->s_conn;
|
2015-01-27 18:51:24 +01:00
|
|
|
size_t readlen;
|
|
|
|
int ret;
|
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
/* Verify that this is a connected peer socket */
|
2015-01-27 18:51:24 +01:00
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
if (conn->lc_state != LOCAL_STATE_CONNECTED)
|
2015-01-27 18:51:24 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: not connected\n");
|
2015-01-27 18:51:24 +01:00
|
|
|
return -ENOTCONN;
|
|
|
|
}
|
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
/* The incoming FIFO should be open */
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
DEBUGASSERT(conn->lc_infile.f_inode != NULL);
|
2015-01-29 14:47:09 +01:00
|
|
|
|
2015-01-27 18:51:24 +01:00
|
|
|
/* Are there still bytes in the FIFO from the last packet? */
|
|
|
|
|
|
|
|
if (conn->u.peer.lc_remaining == 0)
|
|
|
|
{
|
|
|
|
/* No.. Sync to the start of the next packet in the stream and get
|
|
|
|
* the size of the next packet.
|
|
|
|
*/
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
ret = local_sync(&conn->lc_infile);
|
2015-01-27 18:51:24 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Failed to get packet length: %d\n", ret);
|
2015-01-27 18:51:24 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2015-01-29 14:47:09 +01:00
|
|
|
else if (ret > UINT16_MAX)
|
2015-01-27 18:51:24 +01:00
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Packet is too big: %d\n", ret);
|
2015-01-27 18:51:24 +01:00
|
|
|
return -E2BIG;
|
|
|
|
}
|
|
|
|
|
|
|
|
conn->u.peer.lc_remaining = (uint16_t)ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read the packet */
|
|
|
|
|
|
|
|
readlen = MIN(conn->u.peer.lc_remaining, len);
|
|
|
|
ret = psock_fifo_read(psock, buf, &readlen);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust the number of bytes remaining to be read from the packet */
|
|
|
|
|
|
|
|
DEBUGASSERT(readlen <= conn->u.peer.lc_remaining);
|
|
|
|
conn->u.peer.lc_remaining -= readlen;
|
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
/* Return the address family */
|
|
|
|
|
|
|
|
if (from)
|
|
|
|
{
|
|
|
|
ret = local_getaddr(conn, from, fromlen);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return readlen;
|
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_STREAM */
|
2015-01-29 14:47:09 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
2017-04-22 00:33:14 +02:00
|
|
|
* Name: psock_dgram_recvfrom
|
2015-01-29 14:47:09 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* psock_dgram_recvfrom() receives messages from a local datagram socket.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* psock A pointer to a NuttX-specific, internal socket structure
|
|
|
|
* buf Buffer to receive data
|
|
|
|
* len Length of buffer
|
|
|
|
* flags Receive flags
|
|
|
|
* from Address of source (may be NULL)
|
|
|
|
* fromlen The length of the address structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, returns the number of characters received. Otherwise, on
|
|
|
|
* errors, -1 is returned, and errno is set appropriately (see receive
|
|
|
|
* from for the complete list).
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_DGRAM
|
2015-01-29 14:47:09 +01:00
|
|
|
static inline ssize_t
|
|
|
|
psock_dgram_recvfrom(FAR struct socket *psock, FAR void *buf, size_t len,
|
|
|
|
int flags, FAR struct sockaddr *from,
|
|
|
|
FAR socklen_t *fromlen)
|
|
|
|
{
|
|
|
|
FAR struct local_conn_s *conn = (FAR struct local_conn_s *)psock->s_conn;
|
|
|
|
uint16_t pktlen;
|
|
|
|
size_t readlen;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* We keep packet sizes in a uint16_t, so there is a upper limit to the
|
|
|
|
* 'len' that can be supported.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEBUGASSERT(len <= UINT16_MAX);
|
|
|
|
|
|
|
|
/* Verify that this is a bound, un-connected peer socket */
|
|
|
|
|
|
|
|
if (conn->lc_state != LOCAL_STATE_BOUND)
|
|
|
|
{
|
|
|
|
/* Either not bound to address or it is connected */
|
|
|
|
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Connected or not bound\n");
|
2015-01-29 14:47:09 +01:00
|
|
|
return -EISCONN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The incoming FIFO should not be open */
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
DEBUGASSERT(conn->lc_infile.f_inode == NULL);
|
2015-01-29 14:47:09 +01:00
|
|
|
|
|
|
|
/* Make sure that half duplex FIFO has been created */
|
|
|
|
|
2015-01-29 18:05:04 +01:00
|
|
|
ret = local_create_halfduplex(conn, conn->lc_path);
|
2015-01-29 14:47:09 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Failed to create FIFO for %s: %d\n",
|
2015-01-29 14:47:09 +01:00
|
|
|
conn->lc_path, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Open the receiving side of the transfer */
|
|
|
|
|
2020-02-19 19:21:28 +01:00
|
|
|
ret = local_open_receiver(conn, _SS_ISNONBLOCK(psock->s_flags) ||
|
|
|
|
(flags & MSG_DONTWAIT) != 0);
|
2015-01-29 14:47:09 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Failed to open FIFO for %s: %d\n",
|
2015-01-29 14:47:09 +01:00
|
|
|
conn->lc_path, ret);
|
2015-01-30 16:28:55 +01:00
|
|
|
goto errout_with_halfduplex;
|
2015-01-29 14:47:09 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sync to the start of the next packet in the stream and get the size of
|
|
|
|
* the next packet.
|
2015-01-27 18:51:24 +01:00
|
|
|
*/
|
|
|
|
|
2017-11-02 15:23:38 +01:00
|
|
|
ret = local_sync(&conn->lc_infile);
|
2015-01-29 14:47:09 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Failed to get packet length: %d\n", ret);
|
2015-01-29 14:47:09 +01:00
|
|
|
goto errout_with_infd;
|
|
|
|
}
|
|
|
|
else if (ret > UINT16_MAX)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Packet is too big: %d\n", ret);
|
2015-01-29 14:47:09 +01:00
|
|
|
goto errout_with_infd;
|
|
|
|
}
|
|
|
|
|
|
|
|
pktlen = ret;
|
|
|
|
|
|
|
|
/* Read the packet */
|
|
|
|
|
|
|
|
readlen = MIN(pktlen, len);
|
|
|
|
ret = psock_fifo_read(psock, buf, &readlen);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
goto errout_with_infd;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If there are unread bytes remaining in the packet, flush the remainder
|
|
|
|
* of the packet to the bit bucket.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DEBUGASSERT(readlen <= pktlen);
|
|
|
|
if (readlen < pktlen)
|
2015-01-27 18:51:24 +01:00
|
|
|
{
|
|
|
|
uint8_t bitbucket[32];
|
2015-01-29 14:47:09 +01:00
|
|
|
uint16_t remaining;
|
2015-01-27 18:51:24 +01:00
|
|
|
size_t tmplen;
|
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
remaining = pktlen - readlen;
|
2015-01-27 18:51:24 +01:00
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Read 32 bytes into the bit bucket */
|
|
|
|
|
2015-01-29 14:47:09 +01:00
|
|
|
readlen = MIN(remaining, 32);
|
|
|
|
ret = psock_fifo_read(psock, bitbucket, &tmplen);
|
2015-01-27 18:51:24 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2015-01-29 14:47:09 +01:00
|
|
|
goto errout_with_infd;
|
2015-01-27 18:51:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Adjust the number of bytes remaining to be read from the packet */
|
|
|
|
|
2015-01-30 20:29:56 +01:00
|
|
|
DEBUGASSERT(tmplen <= remaining);
|
2015-01-29 14:47:09 +01:00
|
|
|
remaining -= tmplen;
|
2015-01-27 18:51:24 +01:00
|
|
|
}
|
2015-01-29 14:47:09 +01:00
|
|
|
while (remaining > 0);
|
2015-01-27 18:51:24 +01:00
|
|
|
}
|
|
|
|
|
2015-01-30 16:28:55 +01:00
|
|
|
/* Now we can close the read-only file descriptor */
|
2015-01-29 14:47:09 +01:00
|
|
|
|
2018-09-15 21:04:56 +02:00
|
|
|
file_close(&conn->lc_infile);
|
2017-11-02 15:23:38 +01:00
|
|
|
conn->lc_infile.f_inode = NULL;
|
2015-01-29 14:47:09 +01:00
|
|
|
|
2015-10-08 23:10:04 +02:00
|
|
|
/* Release our reference to the half duplex FIFO */
|
2015-01-30 16:28:55 +01:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
local_release_halfduplex(conn);
|
2015-01-30 16:28:55 +01:00
|
|
|
|
2015-01-27 18:51:24 +01:00
|
|
|
/* Return the address family */
|
|
|
|
|
|
|
|
if (from)
|
|
|
|
{
|
|
|
|
ret = local_getaddr(conn, from, fromlen);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return readlen;
|
2015-01-29 14:47:09 +01:00
|
|
|
|
|
|
|
errout_with_infd:
|
2019-10-25 19:31:42 +02:00
|
|
|
|
2015-01-30 16:28:55 +01:00
|
|
|
/* Close the read-only file descriptor */
|
|
|
|
|
2018-09-15 21:04:56 +02:00
|
|
|
file_close(&conn->lc_infile);
|
2017-11-02 15:23:38 +01:00
|
|
|
conn->lc_infile.f_inode = NULL;
|
2015-01-30 16:28:55 +01:00
|
|
|
|
|
|
|
errout_with_halfduplex:
|
2019-10-25 19:31:42 +02:00
|
|
|
|
2015-10-08 23:10:04 +02:00
|
|
|
/* Release our reference to the half duplex FIFO */
|
2015-01-30 16:28:55 +01:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
local_release_halfduplex(conn);
|
2015-01-29 14:47:09 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_STREAM */
|
2015-01-29 14:47:09 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-07-13 01:36:05 +02:00
|
|
|
* Name: local_recvfrom
|
2015-01-29 14:47:09 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2017-07-13 01:36:05 +02:00
|
|
|
* local_recvfrom() receives messages from a local socket and may be used
|
|
|
|
* to receive data on a socket whether or not it is connection-oriented.
|
2015-01-29 14:47:09 +01:00
|
|
|
*
|
|
|
|
* If from is not NULL, and the underlying protocol provides the source
|
|
|
|
* address, this source address is filled in. The argument fromlen
|
|
|
|
* initialized to the size of the buffer associated with from, and modified
|
|
|
|
* on return to indicate the actual size of the address stored there.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* psock A pointer to a NuttX-specific, internal socket structure
|
|
|
|
* buf Buffer to receive data
|
|
|
|
* len Length of buffer
|
|
|
|
* flags Receive flags
|
|
|
|
* from Address of source (may be NULL)
|
|
|
|
* fromlen The length of the address structure
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* On success, returns the number of characters received. If no data is
|
|
|
|
* available to be received and the peer has performed an orderly shutdown,
|
2017-07-13 01:36:05 +02:00
|
|
|
* recv() will return 0. Otherwise, on errors, a negated errno value is
|
|
|
|
* returned (see recv_from() for the complete list of appropriate error
|
|
|
|
* values).
|
2015-01-29 14:47:09 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-07-13 01:36:05 +02:00
|
|
|
ssize_t local_recvfrom(FAR struct socket *psock, FAR void *buf,
|
|
|
|
size_t len, int flags, FAR struct sockaddr *from,
|
|
|
|
FAR socklen_t *fromlen)
|
2015-01-29 14:47:09 +01:00
|
|
|
{
|
|
|
|
DEBUGASSERT(psock && psock->s_conn && buf);
|
|
|
|
|
|
|
|
/* Check for a stream socket */
|
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_STREAM
|
2015-01-29 14:47:09 +01:00
|
|
|
if (psock->s_type == SOCK_STREAM)
|
|
|
|
{
|
|
|
|
return psock_stream_recvfrom(psock, buf, len, flags, from, fromlen);
|
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_LOCAL_DGRAM
|
|
|
|
if (psock->s_type == SOCK_DGRAM)
|
2015-01-29 14:47:09 +01:00
|
|
|
{
|
|
|
|
return psock_dgram_recvfrom(psock, buf, len, flags, from, fromlen);
|
|
|
|
}
|
|
|
|
else
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif
|
2015-01-29 14:47:09 +01:00
|
|
|
{
|
|
|
|
DEBUGPANIC();
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Unrecognized socket type: %s\n", psock->s_type);
|
2015-01-29 14:47:09 +01:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2015-01-27 00:28:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET && CONFIG_NET_LOCAL */
|