mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 16:50:55 +08:00
Revert "net/local: bypass the message field to support SCM further"
This reverts commit 2394394401.
Change-Id: Ia13bc67c4181e0e7cd06a875c0516a2c2c627315
Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
+5
-4
@@ -401,8 +401,9 @@ ssize_t local_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
* Send a packet on the write-only FIFO.
|
||||
*
|
||||
* Input Parameters:
|
||||
* conn The connection
|
||||
* msg Message to send
|
||||
* filep File structure of write-only FIFO.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* preamble Flag to indicate the preamble sync header assembly
|
||||
*
|
||||
* Returned Value:
|
||||
@@ -411,8 +412,8 @@ ssize_t local_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int local_send_packet(FAR struct local_conn_s *conn,
|
||||
FAR struct msghdr *msg, bool preamble);
|
||||
int local_send_packet(FAR struct file *filep, FAR const struct iovec *buf,
|
||||
size_t len, bool preamble);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: local_recvmsg
|
||||
|
||||
+35
-23
@@ -106,15 +106,18 @@ static int psock_fifo_read(FAR struct socket *psock, FAR void *buf,
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_stream_recvmsg
|
||||
* Name: psock_stream_recvfrom
|
||||
*
|
||||
* Description:
|
||||
* psock_stream_recvmsg() receives messages from a local stream socket.
|
||||
* psock_stream_recvfrom() receives messages from a local stream socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* msg Buffer to receive the message
|
||||
* 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
|
||||
@@ -126,11 +129,12 @@ static int psock_fifo_read(FAR struct socket *psock, FAR void *buf,
|
||||
|
||||
#ifdef CONFIG_NET_LOCAL_STREAM
|
||||
static inline ssize_t
|
||||
psock_stream_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
psock_stream_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;
|
||||
size_t readlen;
|
||||
size_t readlen = len;
|
||||
int ret;
|
||||
|
||||
/* Verify that this is a connected peer socket */
|
||||
@@ -152,8 +156,7 @@ psock_stream_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
|
||||
/* Read the packet */
|
||||
|
||||
readlen = msg->msg_iov->iov_len;
|
||||
ret = psock_fifo_read(psock, msg->msg_iov->iov_base, &readlen, true);
|
||||
ret = psock_fifo_read(psock, buf, &readlen, true);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
@@ -161,9 +164,9 @@ psock_stream_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
|
||||
/* Return the address family */
|
||||
|
||||
if (msg->msg_name)
|
||||
if (from)
|
||||
{
|
||||
ret = local_getaddr(conn, msg->msg_name, &msg->msg_namelen);
|
||||
ret = local_getaddr(conn, from, fromlen);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
@@ -175,15 +178,18 @@ psock_stream_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
#endif /* CONFIG_NET_LOCAL_STREAM */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: psock_dgram_recvmsg
|
||||
* Name: psock_dgram_recvfrom
|
||||
*
|
||||
* Description:
|
||||
* psock_dgram_recvmsg() receives messages from a local datagram socket.
|
||||
* psock_dgram_recvfrom() receives messages from a local datagram socket.
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* msg Buffer to receive the message
|
||||
* 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
|
||||
@@ -194,8 +200,9 @@ psock_stream_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
|
||||
#ifdef CONFIG_NET_LOCAL_DGRAM
|
||||
static inline ssize_t
|
||||
psock_dgram_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
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;
|
||||
@@ -206,7 +213,7 @@ psock_dgram_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
* 'len' that can be supported.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(msg->msg_iov->iov_len <= UINT16_MAX);
|
||||
DEBUGASSERT(len <= UINT16_MAX);
|
||||
|
||||
/* Verify that this is a bound, un-connected peer socket */
|
||||
|
||||
@@ -263,8 +270,8 @@ psock_dgram_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
|
||||
/* Read the packet */
|
||||
|
||||
readlen = MIN(pktlen, msg->msg_iov->iov_len);
|
||||
ret = psock_fifo_read(psock, msg->msg_iov->iov_base, &readlen, false);
|
||||
readlen = MIN(pktlen, len);
|
||||
ret = psock_fifo_read(psock, buf, &readlen, false);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto errout_with_infd;
|
||||
@@ -314,9 +321,9 @@ psock_dgram_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
|
||||
/* Return the address family */
|
||||
|
||||
if (msg->msg_name)
|
||||
if (from)
|
||||
{
|
||||
ret = local_getaddr(conn, msg->msg_name, &msg->msg_namelen);
|
||||
ret = local_getaddr(conn, from, fromlen);
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
@@ -373,14 +380,19 @@ errout_with_halfduplex:
|
||||
ssize_t local_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
DEBUGASSERT(psock && psock->s_conn && msg);
|
||||
FAR void *buf = msg->msg_iov->iov_base;
|
||||
size_t len = msg->msg_iov->iov_len;
|
||||
FAR struct sockaddr *from = msg->msg_name;
|
||||
FAR socklen_t *fromlen = &msg->msg_namelen;
|
||||
|
||||
DEBUGASSERT(psock && psock->s_conn && buf);
|
||||
|
||||
/* Check for a stream socket */
|
||||
|
||||
#ifdef CONFIG_NET_LOCAL_STREAM
|
||||
if (psock->s_type == SOCK_STREAM)
|
||||
{
|
||||
return psock_stream_recvmsg(psock, msg, flags);
|
||||
return psock_stream_recvfrom(psock, buf, len, flags, from, fromlen);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@@ -388,7 +400,7 @@ ssize_t local_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
#ifdef CONFIG_NET_LOCAL_DGRAM
|
||||
if (psock->s_type == SOCK_DGRAM)
|
||||
{
|
||||
return psock_dgram_recvmsg(psock, msg, flags);
|
||||
return psock_dgram_recvfrom(psock, buf, len, flags, from, fromlen);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
||||
+29
-17
@@ -49,7 +49,8 @@
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock An instance of the internal socket structure.
|
||||
* msg Message to send
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags (ignored for now)
|
||||
*
|
||||
* Returned Value:
|
||||
@@ -59,8 +60,9 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t psock_local_send(FAR struct socket *psock,
|
||||
FAR struct msghdr *msg, int flags)
|
||||
static ssize_t local_send(FAR struct socket *psock,
|
||||
FAR const struct iovec *buf,
|
||||
size_t len, int flags)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
@@ -73,7 +75,7 @@ static ssize_t psock_local_send(FAR struct socket *psock,
|
||||
|
||||
/* Local TCP packet send */
|
||||
|
||||
DEBUGASSERT(psock && psock->s_conn && msg);
|
||||
DEBUGASSERT(psock && psock->s_conn && buf);
|
||||
peer = (FAR struct local_conn_s *)psock->s_conn;
|
||||
|
||||
/* Verify that this is a connected peer socket and that it has
|
||||
@@ -94,7 +96,7 @@ static ssize_t psock_local_send(FAR struct socket *psock,
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
ret = local_send_packet(peer, msg, false);
|
||||
ret = local_send_packet(&peer->lc_outfile, buf, len, false);
|
||||
}
|
||||
break;
|
||||
#endif /* CONFIG_NET_LOCAL_STREAM */
|
||||
@@ -134,8 +136,11 @@ static ssize_t psock_local_send(FAR struct socket *psock,
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* msg Message to send
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* flags Send flags
|
||||
* to Address of recipient
|
||||
* tolen The length of the address structure
|
||||
*
|
||||
* NOTE: All input parameters were verified by sendto() before this
|
||||
* function was called.
|
||||
@@ -147,21 +152,23 @@ static ssize_t psock_local_send(FAR struct socket *psock,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t psock_local_sendto(FAR struct socket *psock,
|
||||
FAR struct msghdr *msg, int flags)
|
||||
static ssize_t local_sendto(FAR struct socket *psock,
|
||||
FAR const struct iovec *buf,
|
||||
size_t len, int flags,
|
||||
FAR const struct sockaddr *to,
|
||||
socklen_t tolen)
|
||||
{
|
||||
#ifdef CONFIG_NET_LOCAL_DGRAM
|
||||
FAR struct local_conn_s *conn = (FAR struct local_conn_s *)psock->s_conn;
|
||||
FAR struct sockaddr_un *unaddr = msg->msg_name;
|
||||
FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)to;
|
||||
ssize_t ret;
|
||||
|
||||
/* Verify that a valid address has been provided */
|
||||
|
||||
if (unaddr->sun_family != AF_LOCAL ||
|
||||
msg->msg_namelen < sizeof(sa_family_t))
|
||||
if (to->sa_family != AF_LOCAL || tolen < sizeof(sa_family_t))
|
||||
{
|
||||
nerr("ERROR: Unrecognized address family: %d\n",
|
||||
unaddr->sun_family);
|
||||
to->sa_family);
|
||||
return -EAFNOSUPPORT;
|
||||
}
|
||||
|
||||
@@ -193,7 +200,7 @@ static ssize_t psock_local_sendto(FAR struct socket *psock,
|
||||
|
||||
/* At present, only standard pathname type address are support */
|
||||
|
||||
if (msg->msg_namelen < sizeof(sa_family_t) + 2)
|
||||
if (tolen < sizeof(sa_family_t) + 2)
|
||||
{
|
||||
/* EFAULT
|
||||
* - An invalid user space address was specified for a parameter
|
||||
@@ -229,7 +236,7 @@ static ssize_t psock_local_sendto(FAR struct socket *psock,
|
||||
|
||||
/* Send the packet */
|
||||
|
||||
ret = local_send_packet(conn, msg, true);
|
||||
ret = local_send_packet(&conn->lc_outfile, buf, len, true);
|
||||
if (ret < 0)
|
||||
{
|
||||
nerr("ERROR: Failed to send the packet: %zd\n", ret);
|
||||
@@ -264,7 +271,7 @@ errout_with_halfduplex:
|
||||
*
|
||||
* Input Parameters:
|
||||
* psock A pointer to a NuttX-specific, internal socket structure
|
||||
* msg Message to send
|
||||
* msg msg to send
|
||||
* flags Send flags
|
||||
*
|
||||
* Returned Value:
|
||||
@@ -277,8 +284,13 @@ errout_with_halfduplex:
|
||||
ssize_t local_sendmsg(FAR struct socket *psock, FAR struct msghdr *msg,
|
||||
int flags)
|
||||
{
|
||||
return msg->msg_name ? psock_local_sendto(psock, msg, flags) :
|
||||
psock_local_send(psock, msg, flags);
|
||||
FAR const struct iovec *buf = msg->msg_iov;
|
||||
size_t len = msg->msg_iovlen;
|
||||
FAR const struct sockaddr *to = msg->msg_name;
|
||||
socklen_t tolen = msg->msg_namelen;
|
||||
|
||||
return to ? local_sendto(psock, buf, len, flags, to, tolen) :
|
||||
local_send(psock, buf, len, flags);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET && CONFIG_NET_LOCAL */
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include "devif/devif.h"
|
||||
|
||||
#include "socket/socket.h"
|
||||
#include "local/local.h"
|
||||
|
||||
#if defined(CONFIG_NET) && defined(CONFIG_NET_LOCAL)
|
||||
@@ -113,8 +112,9 @@ static int local_fifo_write(FAR struct file *filep, FAR const uint8_t *buf,
|
||||
* Send a packet on the write-only FIFO.
|
||||
*
|
||||
* Input Parameters:
|
||||
* conn The connection
|
||||
* msg Message to send
|
||||
* filep File structure of write-only FIFO.
|
||||
* buf Data to send
|
||||
* len Length of data to send
|
||||
* preamble Flag to indicate the preamble sync header assembly
|
||||
*
|
||||
* Returned Value:
|
||||
@@ -123,12 +123,11 @@ static int local_fifo_write(FAR struct file *filep, FAR const uint8_t *buf,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int local_send_packet(FAR struct local_conn_s *conn,
|
||||
FAR struct msghdr *msg, bool preamble)
|
||||
int local_send_packet(FAR struct file *filep, FAR const struct iovec *buf,
|
||||
size_t len, bool preamble)
|
||||
{
|
||||
FAR struct iovec *end = msg->msg_iov + msg->msg_iovlen;
|
||||
FAR struct file *filep = &conn->lc_outfile;
|
||||
FAR struct iovec *iov;
|
||||
FAR const struct iovec *end = buf + len;
|
||||
FAR const struct iovec *iov;
|
||||
int ret = -EINVAL;
|
||||
uint16_t len16;
|
||||
|
||||
@@ -142,13 +141,13 @@ int local_send_packet(FAR struct local_conn_s *conn,
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (len16 = 0, iov = msg->msg_iov; iov != end; iov++)
|
||||
/* Send the packet length */
|
||||
|
||||
for (len16 = 0, iov = buf; iov != end; iov++)
|
||||
{
|
||||
len16 += iov->iov_len;
|
||||
}
|
||||
|
||||
/* Send the data packet length */
|
||||
|
||||
ret = local_fifo_write(filep, (FAR const uint8_t *)&len16,
|
||||
sizeof(uint16_t));
|
||||
if (ret != sizeof(uint16_t))
|
||||
@@ -157,9 +156,7 @@ int local_send_packet(FAR struct local_conn_s *conn,
|
||||
}
|
||||
}
|
||||
|
||||
/* Send the packet data */
|
||||
|
||||
for (len16 = 0, iov = msg->msg_iov; iov != end; iov++)
|
||||
for (len16 = 0, iov = buf; iov != end; iov++)
|
||||
{
|
||||
ret = local_fifo_write(filep, iov->iov_base, iov->iov_len);
|
||||
if (ret < 0)
|
||||
|
||||
Reference in New Issue
Block a user