This is an automated email from the ASF dual-hosted git repository.
ligd pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new addfe127a9 socketpair.c:Replace kmm with fs heap
addfe127a9 is described below
commit addfe127a901747951f2bca29b2b972b676f8f9c
Author: wangchen <[email protected]>
AuthorDate: Sun Sep 29 20:19:40 2024 +0800
socketpair.c:Replace kmm with fs heap
due to https://github.com/apache/nuttx/pull/13722/commits, In the
socketpair.c,fs_heap interface replaces kmm interface
Signed-off-by: wangchen <[email protected]>
---
fs/socket/CMakeLists.txt | 2 +-
fs/socket/Make.defs | 2 +-
{net => fs}/socket/socketpair.c | 83 ++++++-----------------------------
net/socket/socketpair.c | 96 -----------------------------------------
4 files changed, 16 insertions(+), 167 deletions(-)
diff --git a/fs/socket/CMakeLists.txt b/fs/socket/CMakeLists.txt
index 8b8064b473..0e905a5efe 100644
--- a/fs/socket/CMakeLists.txt
+++ b/fs/socket/CMakeLists.txt
@@ -18,5 +18,5 @@
#
#
##############################################################################
if(CONFIG_NET)
- target_sources(fs PRIVATE socket.c accept.c)
+ target_sources(fs PRIVATE socket.c accept.c socketpair.c)
endif()
diff --git a/fs/socket/Make.defs b/fs/socket/Make.defs
index 68db89cc6d..4a300e338c 100644
--- a/fs/socket/Make.defs
+++ b/fs/socket/Make.defs
@@ -22,7 +22,7 @@
ifeq ($(CONFIG_NET),y)
-CSRCS += socket.c accept.c
+CSRCS += socket.c accept.c socketpair.c
# Include socket build support
diff --git a/net/socket/socketpair.c b/fs/socket/socketpair.c
similarity index 66%
copy from net/socket/socketpair.c
copy to fs/socket/socketpair.c
index fb06d06daf..c50bea3158 100644
--- a/net/socket/socketpair.c
+++ b/fs/socket/socketpair.c
@@ -1,7 +1,5 @@
/****************************************************************************
- * net/socket/socketpair.c
- *
- * SPDX-License-Identifier: Apache-2.0
+ * fs/socket/socketpair.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -24,79 +22,26 @@
* Included Files
****************************************************************************/
-#include <netinet/in.h>
-#include <arpa/inet.h>
+#include <nuttx/config.h>
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/net/net.h>
+#include <nuttx/fs/fs.h>
+#include <nuttx/mm/mm.h>
+
#include <sys/socket.h>
-#include <sys/types.h>
+#include <assert.h>
#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
#include <errno.h>
+#include <debug.h>
-#include <nuttx/kmalloc.h>
-#include <nuttx/net/net.h>
+#include "inode/inode.h"
+#include "fs_heap.h"
/****************************************************************************
* Public Functions
****************************************************************************/
-/****************************************************************************
- * Name: psock_socketpair
- *
- * Description:
- * Create an unbound pair of connected sockets in a specified domain, of a
- * specified type, under the protocol optionally specified by the protocol
- * argument. The two sockets shall be identical. The file descriptors used
- * in referencing the created sockets shall be returned in
- * sv[0] and sv[1].
- *
- * Input Parameters:
- * domain - (see sys/socket.h)
- * type - (see sys/socket.h)
- * protocol - (see sys/socket.h)
- * psocks - The array to catch the pair descriptors
- *
- ****************************************************************************/
-
-int psock_socketpair(int domain, int type, int protocol,
- FAR struct socket *psocks[2])
-{
- int ret;
-
- /* Initialize the socket structure */
-
- ret = psock_socket(domain, type, protocol, psocks[0]);
- if (ret < 0)
- {
- return ret;
- }
-
- if (psocks[0]->s_sockif->si_socketpair == NULL)
- {
- ret = -EAFNOSUPPORT;
- goto errsock;
- }
-
- ret = psock_socket(domain, type, protocol, psocks[1]);
- if (ret < 0)
- {
- goto errsock;
- }
-
- /* Perform socketpair process */
-
- ret = psocks[0]->s_sockif->si_socketpair(psocks);
- if (ret == 0)
- {
- return ret;
- }
-
- psock_close(psocks[1]);
-errsock:
- psock_close(psocks[0]);
- return ret;
-}
-
/****************************************************************************
* Name: socketpair
*
@@ -133,7 +78,7 @@ int socketpair(int domain, int type, int protocol, int sv[2])
for (k = 0; k < 2; k++)
{
- psocks[k] = kmm_zalloc(sizeof(*psocks[k]));
+ psocks[k] = fs_heap_zalloc(sizeof(*psocks[k]));
if (psocks[k] == NULL)
{
ret = -ENOMEM;
@@ -185,7 +130,7 @@ errout_with_psock:
errout_with_alloc:
for (i = j; i < k; i++)
{
- kmm_free(psocks[i]);
+ fs_heap_free(psocks[i]);
}
errout:
diff --git a/net/socket/socketpair.c b/net/socket/socketpair.c
index fb06d06daf..59824630e8 100644
--- a/net/socket/socketpair.c
+++ b/net/socket/socketpair.c
@@ -96,99 +96,3 @@ errsock:
psock_close(psocks[0]);
return ret;
}
-
-/****************************************************************************
- * Name: socketpair
- *
- * Description:
- * Create an unbound pair of connected sockets in a specified domain, of a
- * specified type, under the protocol optionally specified by the protocol
- * argument. The two sockets shall be identical. The file descriptors used
- * in referencing the created sockets shall be returned in
- * sv[0] and sv[1].
- *
- * Input Parameters:
- * domain - (see sys/socket.h)
- * type - (see sys/socket.h)
- * protocol - (see sys/socket.h)
- * sv[2] - The user provided array in which to catch the pair
- * descriptors
- *
- ****************************************************************************/
-
-int socketpair(int domain, int type, int protocol, int sv[2])
-{
- FAR struct socket *psocks[2];
- int oflags = O_RDWR;
- int ret;
- int i;
- int j = 0;
- int k;
-
- if (sv == NULL)
- {
- ret = -EINVAL;
- goto errout;
- }
-
- for (k = 0; k < 2; k++)
- {
- psocks[k] = kmm_zalloc(sizeof(*psocks[k]));
- if (psocks[k] == NULL)
- {
- ret = -ENOMEM;
- goto errout_with_alloc;
- }
- }
-
- ret = psock_socketpair(domain, type, protocol, psocks);
- if (ret < 0)
- {
- goto errout_with_alloc;
- }
-
- if (type & SOCK_CLOEXEC)
- {
- oflags |= O_CLOEXEC;
- }
-
- if (type & SOCK_NONBLOCK)
- {
- oflags |= O_NONBLOCK;
- }
-
- /* Allocate a socket descriptor */
-
- for (; j < 2; j++)
- {
- sv[j] = sockfd_allocate(psocks[j], oflags);
- if (sv[j] < 0)
- {
- ret = sv[j];
- goto errout_with_psock;
- }
- }
-
- return OK;
-
-errout_with_psock:
- for (i = 0; i < j; i++)
- {
- nx_close(sv[i]);
- }
-
- for (i = j; i < k; i++)
- {
- psock_close(psocks[i]);
- }
-
-errout_with_alloc:
- for (i = j; i < k; i++)
- {
- kmm_free(psocks[i]);
- }
-
-errout:
- set_errno(-ret);
- return ERROR;
-}