You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/01/31 19:45:26 UTC

[incubator-nuttx] branch master updated (2def803 -> 4a238f2)

This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git.


    from 2def803  sched/sched/sched_getcpu.c:  Implement non-standard interface.
     new 9f9566c  Rename net_clone/net_dupsd[2] to psock_dup2/net_dup[2] like vfs
     new 0b86072  Ensure psock_socket and psock_accept initialize s_crefs to 1
     new 709dc19  Move the lock from psock_release to sockfd_release
     new 6e6c670  Move _SF_BOUND and _SF_CONNECTED modification to common place
     new cf2ddbb  Replace set_errno to _SO_SETERRNO
     new 7e67add  Implment SO_ACCEPTCONN
     new 0fc7668  sendto should always call send if to == NULL || tolen <= 0
     new c1b0aa1  Remove psock_send and sockfd_socket from net/socket/socket.h
     new 3ae5f52  Add FAR for pointer type for socket header files
     new 4a238f2  Fix the wrong IPv6 TCP MSS calculation

The 10 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 drivers/net/rpmsgdrv.c                 |   1 -
 drivers/net/telnet.c                   |   4 +-
 fs/nfs/rpc_clnt.c                      |   3 +-
 fs/userfs/fs_userfs.c                  |   4 --
 fs/vfs/fs_dup.c                        |   2 +-
 fs/vfs/fs_dup2.c                       |   2 +-
 graphics/vnc/server/vnc_server.c       |   2 -
 include/arpa/inet.h                    |   6 +-
 include/net/if.h                       |   3 +-
 include/net/route.h                    |   4 +-
 include/netinet/arp.h                  |  14 +----
 include/netinet/ether.h                |   2 +-
 include/netinet/ip6.h                  |   6 +-
 include/nuttx/fs/ioctl.h               |   4 +-
 include/nuttx/net/icmp.h               |   1 -
 include/nuttx/net/icmpv6.h             |   1 -
 include/nuttx/net/igmp.h               |   4 --
 include/nuttx/net/ip.h                 |  31 +++++----
 include/nuttx/net/ipv6ext.h            |   8 ++-
 include/nuttx/net/net.h                |  34 +++++-----
 include/nuttx/net/netconfig.h          |   9 ++-
 include/nuttx/net/netdev.h             |  11 ++--
 include/nuttx/net/tcp.h                |  14 ++---
 include/sys/socket.h                   |  26 ++++----
 net/bluetooth/bluetooth_sockif.c       |  10 +--
 net/ieee802154/ieee802154_sockif.c     |  10 +--
 net/inet/inet_sockif.c                 |  21 +------
 net/inet/ipv4_getpeername.c            |   2 +-
 net/inet/ipv6_getpeername.c            |   2 +-
 net/local/local_accept.c               |   1 +
 net/local/local_sockif.c               |   7 ---
 net/netlink/netlink_sockif.c           |   1 -
 net/pkt/pkt_sockif.c                   |   3 -
 net/socket/Make.defs                   |   4 +-
 net/socket/bind.c                      |   4 ++
 net/socket/connect.c                   |   9 +++
 net/socket/getsockopt.c                |  27 +++++---
 net/socket/{net_dupsd.c => net_dup.c}  |  14 ++---
 net/socket/{net_clone.c => net_dup2.c} |  71 ++++++++++++++++++---
 net/socket/net_dupsd2.c                | 111 ---------------------------------
 net/socket/net_fstat.c                 |   3 +-
 net/socket/net_sockets.c               |  45 +++++++------
 net/socket/net_sockif.c                |   2 +-
 net/socket/net_vfcntl.c                |   2 +-
 net/socket/sendto.c                    |   6 --
 net/socket/setsockopt.c                |  20 +++---
 net/socket/socket.c                    |   6 +-
 net/socket/socket.h                    | 107 +------------------------------
 net/utils/net_lock.c                   |   7 +--
 net/utils/utils.h                      |   2 +-
 sched/group/group_setuptaskfiles.c     |   2 +-
 51 files changed, 239 insertions(+), 456 deletions(-)
 rename net/socket/{net_dupsd.c => net_dup.c} (95%)
 rename net/socket/{net_clone.c => net_dup2.c} (77%)
 delete mode 100644 net/socket/net_dupsd2.c


[incubator-nuttx] 02/10: Ensure psock_socket and psock_accept initialize s_crefs to 1

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 0b860726db80019186a2f442f86fcda93b4e2adc
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Jan 31 17:27:46 2020 +0800

    Ensure psock_socket and psock_accept initialize s_crefs to 1
    
    This simplifies the caller usage
---
 drivers/net/rpmsgdrv.c           | 1 -
 fs/nfs/rpc_clnt.c                | 3 +--
 fs/userfs/fs_userfs.c            | 4 ----
 graphics/vnc/server/vnc_server.c | 2 --
 net/inet/inet_sockif.c           | 1 +
 net/local/local_accept.c         | 1 +
 net/socket/socket.c              | 6 +-----
 7 files changed, 4 insertions(+), 14 deletions(-)

diff --git a/drivers/net/rpmsgdrv.c b/drivers/net/rpmsgdrv.c
index ba451d1..56e86b4 100644
--- a/drivers/net/rpmsgdrv.c
+++ b/drivers/net/rpmsgdrv.c
@@ -489,7 +489,6 @@ static int net_rpmsg_drv_sockioctl_task(int argc, FAR char *argv[])
       protocol = IPPROTO_ICMP6;
     }
 
-  sock.s_crefs = 1; /* Initialize reference count manually */
   msg->header.result = psock_socket(domain, type, protocol, &sock);
   if (msg->header.result >= 0)
     {
diff --git a/fs/nfs/rpc_clnt.c b/fs/nfs/rpc_clnt.c
index a8d7c59..180c234 100644
--- a/fs/nfs/rpc_clnt.c
+++ b/fs/nfs/rpc_clnt.c
@@ -408,8 +408,7 @@ int rpcclnt_connect(struct rpcclnt *rpc)
       return errval;
     }
 
-  so->s_crefs     = 1;
-  rpc->rc_so      = so;
+  rpc->rc_so = so;
 
   /* Always set receive timeout to detect server crash and reconnect.
    * Otherwise, we can get stuck in psock_receive forever.
diff --git a/fs/userfs/fs_userfs.c b/fs/userfs/fs_userfs.c
index 2bcadf6..2d45a8f 100644
--- a/fs/userfs/fs_userfs.c
+++ b/fs/userfs/fs_userfs.c
@@ -1370,8 +1370,6 @@ static int userfs_bind(FAR struct inode *blkdriver, FAR const void *data,
       goto errout_with_alloc;
     }
 
-  priv->psock.s_crefs = 1;
-
   /* Bind the socket to the client address */
 
   client.sin_family      = AF_INET;
@@ -1386,8 +1384,6 @@ static int userfs_bind(FAR struct inode *blkdriver, FAR const void *data,
       goto errout_with_psock;
     }
 
-  priv->psock.s_crefs = 1;
-
   /* Mounted! */
 
   *handle = (FAR void *)priv;
diff --git a/graphics/vnc/server/vnc_server.c b/graphics/vnc/server/vnc_server.c
index c143a9a..aaf6c98 100644
--- a/graphics/vnc/server/vnc_server.c
+++ b/graphics/vnc/server/vnc_server.c
@@ -119,9 +119,7 @@ static void vnc_reset_session(FAR struct vnc_session_s *session,
   /* [Re-]initialize the session. */
 
   memset(&session->connect, 0, sizeof(struct socket));
-  session->connect.s_crefs = 1;
   memset(&session->listen, 0, sizeof(struct socket));
-  session->listen.s_crefs = 1;
 
   /* Put all of the pre-allocated update structures into the freelist */
 
diff --git a/net/inet/inet_sockif.c b/net/inet/inet_sockif.c
index 8a66b89..c42fdbb 100644
--- a/net/inet/inet_sockif.c
+++ b/net/inet/inet_sockif.c
@@ -879,6 +879,7 @@ static int inet_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
 
   /* Initialize the socket structure. */
 
+  newsock->s_crefs  = 1;
   newsock->s_domain = psock->s_domain;
   newsock->s_type   = SOCK_STREAM;
   newsock->s_sockif = psock->s_sockif;
diff --git a/net/local/local_accept.c b/net/local/local_accept.c
index 24d509a..e847f1c 100644
--- a/net/local/local_accept.c
+++ b/net/local/local_accept.c
@@ -234,6 +234,7 @@ int local_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
             {
               /* Setup the client socket structure */
 
+              newsock->s_crefs  = 1;
               newsock->s_domain = psock->s_domain;
               newsock->s_type   = SOCK_STREAM;
               newsock->s_sockif = psock->s_sockif;
diff --git a/net/socket/socket.c b/net/socket/socket.c
index bf11bbe..635ec4d 100644
--- a/net/socket/socket.c
+++ b/net/socket/socket.c
@@ -60,11 +60,6 @@
  *   socket() creates an endpoint for communication and returns a socket
  *   structure.
  *
- *   NOTE: This function does not set the reference count on the socket
- *   structure.  This down by the socket() front end when socket structure
- *   was allocated.  Internal OS users of psock_socket() must set the s_crefs
- *   field to one if psock_socket() returns success.
- *
  * Input Parameters:
  *   domain   (see sys/socket.h)
  *   type     (see sys/socket.h)
@@ -102,6 +97,7 @@ int psock_socket(int domain, int type, int protocol, FAR struct socket *psock)
 
   /* Initialize the socket structure */
 
+  psock->s_crefs  = 1;
   psock->s_domain = domain;
   psock->s_type   = type;
   psock->s_conn   = NULL;


Re: [incubator-nuttx] 07/10: sendto should always call send if to == NULL || tolen <= 0

Posted by Justin Mclean <ju...@classsoftware.com>.
Hi,

Wrong header here as well - please fix.

Thanks,
Justin

[incubator-nuttx] 07/10: sendto should always call send if to == NULL || tolen <= 0

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 0fc7668d657efca2702227a22bdcb9ea684c8519
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Jan 31 18:00:39 2020 +0800

    sendto should always call send if to == NULL || tolen <= 0
    
    Since UDP socket may bind the target with connect call
---
 net/socket/sendto.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/net/socket/sendto.c b/net/socket/sendto.c
index 55efcce..7dd2479 100644
--- a/net/socket/sendto.c
+++ b/net/socket/sendto.c
@@ -139,13 +139,7 @@ ssize_t psock_sendto(FAR struct socket *psock, FAR const void *buf,
 
   if (to == NULL || tolen <= 0)
     {
-#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_LOCAL_STREAM) || \
-    defined(CONFIG_NET_USRSOCK)
       return psock_send(psock, buf, len, flags);
-#else
-      nerr("ERROR: No 'to' address\n");
-      return -EINVAL;
-#endif
     }
 
   /* Verify that the psock corresponds to valid, allocated socket */


[incubator-nuttx] 06/10: Implment SO_ACCEPTCONN

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 7e67add99951bbd988858ee03033ca49004b10f5
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Jan 31 17:57:02 2020 +0800

    Implment SO_ACCEPTCONN
---
 net/socket/getsockopt.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/net/socket/getsockopt.c b/net/socket/getsockopt.c
index 13d8bc0..2bc1c73 100644
--- a/net/socket/getsockopt.c
+++ b/net/socket/getsockopt.c
@@ -131,6 +131,16 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
 
   switch (option)
     {
+      case SO_ACCEPTCONN: /* Reports whether socket listening is enabled */
+        if (*value_len < sizeof(int))
+          {
+            return -EINVAL;
+          }
+
+        *(FAR int *)value = _SS_ISLISTENING(psock->s_flags);
+        *value_len        = sizeof(int);
+        break;
+
       /* The following options take a point to an integer boolean value.
        * We will blindly report the bit here although the implementation
        * is outside of the scope of getsockopt.
@@ -268,7 +278,6 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
 
       /* The following are not yet implemented (return values other than {0,1) */
 
-      case SO_ACCEPTCONN: /* Reports whether socket listening is enabled */
       case SO_LINGER:     /* Lingers on a close() if data is present */
       case SO_RCVBUF:     /* Sets receive buffer size */
       case SO_RCVLOWAT:   /* Sets the minimum number of bytes to input */


[incubator-nuttx] 01/10: Rename net_clone/net_dupsd[2] to psock_dup2/net_dup[2] like vfs

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 9f9566c0eb5515d89c2324c71cc2ca4ea619f8de
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Jan 31 16:44:28 2020 +0800

    Rename net_clone/net_dupsd[2] to psock_dup2/net_dup[2] like vfs
---
 drivers/net/telnet.c                   |   4 +-
 fs/vfs/fs_dup.c                        |   2 +-
 fs/vfs/fs_dup2.c                       |   2 +-
 include/nuttx/net/net.h                |  32 +++++-----
 net/socket/Make.defs                   |   4 +-
 net/socket/{net_dupsd.c => net_dup.c}  |  14 ++---
 net/socket/{net_clone.c => net_dup2.c} |  71 ++++++++++++++++++---
 net/socket/net_dupsd2.c                | 111 ---------------------------------
 net/socket/net_vfcntl.c                |   2 +-
 net/socket/socket.h                    |  19 ------
 sched/group/group_setuptaskfiles.c     |   2 +-
 11 files changed, 93 insertions(+), 170 deletions(-)

diff --git a/drivers/net/telnet.c b/drivers/net/telnet.c
index e1bf037..9d142fe 100644
--- a/drivers/net/telnet.c
+++ b/drivers/net/telnet.c
@@ -1086,10 +1086,10 @@ static int telnet_session(FAR struct telnet_session_s *session)
       goto errout_with_dev;
     }
 
-  ret = net_clone(psock, &priv->td_psock);
+  ret = psock_dup2(psock, &priv->td_psock);
   if (ret < 0)
     {
-      nerr("ERROR: net_clone failed: %d\n", ret);
+      nerr("ERROR: psock_dup2 failed: %d\n", ret);
       goto errout_with_dev;
     }
 
diff --git a/fs/vfs/fs_dup.c b/fs/vfs/fs_dup.c
index 80f847f..a92621a 100644
--- a/fs/vfs/fs_dup.c
+++ b/fs/vfs/fs_dup.c
@@ -84,7 +84,7 @@ int dup(int fd)
         {
           /* Yes.. dup the socket descriptor.  The errno value is not set. */
 
-          ret = net_dupsd(fd, CONFIG_NFILE_DESCRIPTORS);
+          ret = net_dup(fd, CONFIG_NFILE_DESCRIPTORS);
         }
       else
 #endif
diff --git a/fs/vfs/fs_dup2.c b/fs/vfs/fs_dup2.c
index 64a8762..d7e6a90 100644
--- a/fs/vfs/fs_dup2.c
+++ b/fs/vfs/fs_dup2.c
@@ -82,7 +82,7 @@ int dup2(int fd1, int fd2)
         {
           /* Yes.. dup the socket descriptor. The errno value is not set. */
 
-          ret = net_dupsd2(fd1, fd2);
+          ret = net_dup2(fd1, fd2);
         }
       else
         {
diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h
index 7fc4154..3ad7afb 100644
--- a/include/nuttx/net/net.h
+++ b/include/nuttx/net/net.h
@@ -1308,7 +1308,7 @@ struct pollfd; /* Forward reference -- see poll.h */
 int net_poll(int sockfd, struct pollfd *fds, bool setup);
 
 /****************************************************************************
- * Name: psock_dupsd
+ * Name: psock_dup
  *
  * Description:
  *   Clone a socket descriptor to an arbitray descriptor number.  If file
@@ -1322,10 +1322,10 @@ int net_poll(int sockfd, struct pollfd *fds, bool setup);
  *
  ****************************************************************************/
 
-int psock_dupsd(FAR struct socket *psock, int minsd);
+int psock_dup(FAR struct socket *psock, int minsd);
 
 /****************************************************************************
- * Name: net_dupsd
+ * Name: net_dup
  *
  * Description:
  *   Clone a socket descriptor to an arbitray descriptor number.  If file
@@ -1339,10 +1339,20 @@ int psock_dupsd(FAR struct socket *psock, int minsd);
  *
  ****************************************************************************/
 
-int net_dupsd(int sockfd, int minsd);
+int net_dup(int sockfd, int minsd);
 
 /****************************************************************************
- * Name: net_dupsd2
+ * Name: psock_dup2
+ *
+ * Description:
+ *   Performs the low level, common portion of net_dup() and net_dup2()
+ *
+ ****************************************************************************/
+
+int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2);
+
+/****************************************************************************
+ * Name: net_dup2
  *
  * Description:
  *   Clone a socket descriptor to an arbitray descriptor number.  If file
@@ -1356,7 +1366,7 @@ int net_dupsd(int sockfd, int minsd);
  *
  ****************************************************************************/
 
-int net_dupsd2(int sockfd1, int sockfd2);
+int net_dup2(int sockfd1, int sockfd2);
 
 /****************************************************************************
  * Name: net_fstat
@@ -1379,16 +1389,6 @@ struct stat;  /* Forward reference.  See sys/stat.h */
 int net_fstat(int sockfd, FAR struct stat *buf);
 
 /****************************************************************************
- * Name: net_clone
- *
- * Description:
- *   Performs the low level, common portion of net_dupsd() and net_dupsd2()
- *
- ****************************************************************************/
-
-int net_clone(FAR struct socket *psock1, FAR struct socket *psock2);
-
-/****************************************************************************
  * Name: net_sendfile
  *
  * Description:
diff --git a/net/socket/Make.defs b/net/socket/Make.defs
index a99c5a7..47fb4d2 100644
--- a/net/socket/Make.defs
+++ b/net/socket/Make.defs
@@ -37,8 +37,8 @@
 
 SOCK_CSRCS += bind.c connect.c getsockname.c getpeername.c
 SOCK_CSRCS += recv.c recvfrom.c send.c sendto.c
-SOCK_CSRCS += socket.c net_sockets.c net_close.c net_dupsd.c
-SOCK_CSRCS += net_dupsd2.c net_sockif.c net_clone.c net_poll.c net_vfcntl.c
+SOCK_CSRCS += socket.c net_sockets.c net_close.c net_dup.c
+SOCK_CSRCS += net_dup2.c net_sockif.c net_poll.c net_vfcntl.c
 SOCK_CSRCS += net_fstat.c
 
 # TCP/IP support
diff --git a/net/socket/net_dupsd.c b/net/socket/net_dup.c
similarity index 95%
rename from net/socket/net_dupsd.c
rename to net/socket/net_dup.c
index 74616b0..09fcbca 100644
--- a/net/socket/net_dupsd.c
+++ b/net/socket/net_dup.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * net/socket/net_dupsd.c
+ * net/socket/net_dup.c
  *
  *   Copyright (C) 2009, 2017 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <gn...@nuttx.org>
@@ -51,7 +51,7 @@
  ****************************************************************************/
 
 /****************************************************************************
- * Name: psock_dupsd
+ * Name: psock_dup
  *
  * Description:
  *   Clone a socket descriptor to an arbitrary descriptor number.  If file
@@ -65,7 +65,7 @@
  *
  ****************************************************************************/
 
-int psock_dupsd(FAR struct socket *psock, int minsd)
+int psock_dup(FAR struct socket *psock, int minsd)
 {
   FAR struct socket *psock2;
   int sockfd2;
@@ -117,7 +117,7 @@ int psock_dupsd(FAR struct socket *psock, int minsd)
 
   /* Duplicate the socket state */
 
-  ret = net_clone(psock, psock2);
+  ret = psock_dup2(psock, psock2);
   if (ret < 0)
     {
       goto errout_with_sockfd;
@@ -135,7 +135,7 @@ errout:
 }
 
 /****************************************************************************
- * Name: net_dupsd
+ * Name: net_dup
  *
  * Description:
  *   Clone a socket descriptor to an arbitrary descriptor number.  If file
@@ -149,7 +149,7 @@ errout:
  *
  ****************************************************************************/
 
-int net_dupsd(int sockfd, int minsd)
+int net_dup(int sockfd, int minsd)
 {
-  return psock_dupsd(sockfd_socket(sockfd), minsd);
+  return psock_dup(sockfd_socket(sockfd), minsd);
 }
diff --git a/net/socket/net_clone.c b/net/socket/net_dup2.c
similarity index 77%
rename from net/socket/net_clone.c
rename to net/socket/net_dup2.c
index 93900c9..50a3f70 100644
--- a/net/socket/net_clone.c
+++ b/net/socket/net_dup2.c
@@ -1,5 +1,5 @@
 /****************************************************************************
- * net/socket/net_clone.c
+ * net/socket/net_dup2.c
  *
  *   Copyright (C) 2009, 2011-2015, 2017 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <gn...@nuttx.org>
@@ -41,28 +41,25 @@
 
 #include <sys/socket.h>
 #include <string.h>
+#include <sched.h>
 #include <errno.h>
 #include <debug.h>
 
-#include <nuttx/arch.h>
 #include <nuttx/net/net.h>
-#include <nuttx/net/udp.h>
 
 #include "inet/inet.h"
 #include "tcp/tcp.h"
 #include "socket/socket.h"
 
-#ifdef CONFIG_NET
-
 /****************************************************************************
  * Public Functions
  ****************************************************************************/
 
 /****************************************************************************
- * Name: net_clone
+ * Name: psock_dup2
  *
  * Description:
- *   Performs the low level, common portion of net_dupsd() and net_dupsd2()
+ *   Performs the low level, common portion of net_dup() and net_dup2()
  *
  * Input Parameters:
  *   psock1 - The existing socket that is being cloned.
@@ -75,7 +72,7 @@
  *
  ****************************************************************************/
 
-int net_clone(FAR struct socket *psock1, FAR struct socket *psock2)
+int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2)
 {
   int ret = OK;
 
@@ -155,4 +152,60 @@ int net_clone(FAR struct socket *psock1, FAR struct socket *psock2)
   return ret;
 }
 
-#endif /* CONFIG_NET */
+/****************************************************************************
+ * Name: net_dup2
+ *
+ * Description:
+ *   Clone a socket descriptor to an arbitray descriptor number.  If file
+ *   descriptors are implemented, then this is called by dup2() for the case
+ *   of socket file descriptors.  If file descriptors are not implemented,
+ *   then this function IS dup2().
+ *
+ * Returned Value:
+ *   On success, returns the number of characters sent.  On any error,
+ *   a negated errno value is returned:.
+ *
+ ****************************************************************************/
+
+int net_dup2(int sockfd1, int sockfd2)
+{
+  FAR struct socket *psock1;
+  FAR struct socket *psock2;
+  int ret;
+
+  /* Lock the scheduler throughout the following */
+
+  sched_lock();
+
+  /* Get the socket structures underly both descriptors */
+
+  psock1 = sockfd_socket(sockfd1);
+  psock2 = sockfd_socket(sockfd2);
+
+  /* Verify that the sockfd1 and sockfd2 both refer to valid socket
+   * descriptors and that sockfd2 corresponds to an allocated socket
+   */
+
+  if (psock1 == NULL || psock2 == NULL || psock1->s_crefs <= 0)
+    {
+      ret = -EBADF;
+      goto errout;
+    }
+
+  /* If sockfd2 also valid, allocated socket, then we will have to
+   * close it!
+   */
+
+  if (psock2->s_crefs > 0)
+    {
+      net_close(sockfd2);
+    }
+
+  /* Duplicate the socket state */
+
+  ret = psock_dup2(psock1, psock2);
+
+errout:
+  sched_unlock();
+  return ret;
+}
diff --git a/net/socket/net_dupsd2.c b/net/socket/net_dupsd2.c
deleted file mode 100644
index d8b1d63..0000000
--- a/net/socket/net_dupsd2.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/****************************************************************************
- * net/socket/net_dupsd2.c
- *
- *   Copyright (C) 2009, 2011, 2017 Gregory Nutt. All rights reserved.
- *   Author: Gregory Nutt <gn...@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>
-
-#include <sys/socket.h>
-#include <sched.h>
-#include <errno.h>
-#include <debug.h>
-
-#include <nuttx/net/net.h>
-
-#include "socket/socket.h"
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: net_dupsd2
- *
- * Description:
- *   Clone a socket descriptor to an arbitray descriptor number.  If file
- *   descriptors are implemented, then this is called by dup2() for the case
- *   of socket file descriptors.  If file descriptors are not implemented,
- *   then this function IS dup2().
- *
- * Returned Value:
- *   On success, returns the number of characters sent.  On any error,
- *   a negated errno value is returned:.
- *
- ****************************************************************************/
-
-int net_dupsd2(int sockfd1, int sockfd2)
-{
-  FAR struct socket *psock1;
-  FAR struct socket *psock2;
-  int ret;
-
-  /* Lock the scheduler throughout the following */
-
-  sched_lock();
-
-  /* Get the socket structures underly both descriptors */
-
-  psock1 = sockfd_socket(sockfd1);
-  psock2 = sockfd_socket(sockfd2);
-
-  /* Verify that the sockfd1 and sockfd2 both refer to valid socket
-   * descriptors and that sockfd2 corresponds to an allocated socket
-   */
-
-  if (psock1 == NULL || psock2 == NULL || psock1->s_crefs <= 0)
-    {
-      ret = -EBADF;
-      goto errout;
-    }
-
-  /* If sockfd2 also valid, allocated socket, then we will have to
-   * close it!
-   */
-
-  if (psock2->s_crefs > 0)
-    {
-      net_close(sockfd2);
-    }
-
-  /* Duplicate the socket state */
-
-  ret = net_clone(psock1, psock2);
-
-errout:
-  sched_unlock();
-  return ret;
-}
diff --git a/net/socket/net_vfcntl.c b/net/socket/net_vfcntl.c
index c1a7a3c..51592d7 100644
--- a/net/socket/net_vfcntl.c
+++ b/net/socket/net_vfcntl.c
@@ -105,7 +105,7 @@ int psock_vfcntl(FAR struct socket *psock, int cmd, va_list ap)
         {
           /* Does not set the errno value on failure */
 
-          ret = psock_dupsd(psock, va_arg(ap, int));
+          ret = psock_dup(psock, va_arg(ap, int));
         }
         break;
 
diff --git a/net/socket/socket.h b/net/socket/socket.h
index a2452f2..107e23e 100644
--- a/net/socket/socket.h
+++ b/net/socket/socket.h
@@ -336,24 +336,5 @@ int net_timeo(clock_t start_time, socktimeo_t timeo);
 ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len,
                    int flags);
 
-/****************************************************************************
- * Name: net_clone
- *
- * Description:
- *   Performs the low level, common portion of net_dupsd() and net_dupsd2()
- *
- * Input Parameters:
- *   psock1 - The existing socket that is being cloned.
- *   psock2 - A reference to an uninitialized socket structure alloated by
- *            the caller.
- *
- * Returned Value:
- *   Zero (OK) is returned on success; a negated errno value is returned on
- *   any failure.
- *
- ****************************************************************************/
-
-int net_clone(FAR struct socket *psock1, FAR struct socket *psock2);
-
 #endif /* CONFIG_NET */
 #endif /* _NET_SOCKET_SOCKET_H */
diff --git a/sched/group/group_setuptaskfiles.c b/sched/group/group_setuptaskfiles.c
index dae52b5..b632c91 100644
--- a/sched/group/group_setuptaskfiles.c
+++ b/sched/group/group_setuptaskfiles.c
@@ -174,7 +174,7 @@ static inline void sched_dupsockets(FAR struct task_tcb_s *tcb)
         {
           /* Yes... duplicate it for the child */
 
-          net_clone(&parent[i], &child[i]);
+          psock_dup2(&parent[i], &child[i]);
         }
     }
 }


[incubator-nuttx] 08/10: Remove psock_send and sockfd_socket from net/socket/socket.h

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit c1b0aa118c92f6b11645ebd8e96a8986891e79a1
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Feb 1 02:09:01 2020 +0800

    Remove psock_send and sockfd_socket from net/socket/socket.h
    
    Since both is already declared in include/nuttx/net/net.h and fix other minor issue in network socket layer.
---
 include/arpa/inet.h         |  6 ++--
 include/net/if.h            |  3 +-
 include/net/route.h         |  4 +--
 include/netinet/arp.h       | 14 ++------
 include/netinet/ether.h     |  2 +-
 include/netinet/ip6.h       |  6 ++--
 include/nuttx/fs/ioctl.h    |  4 +--
 include/nuttx/net/icmp.h    |  1 -
 include/nuttx/net/icmpv6.h  |  1 -
 include/nuttx/net/igmp.h    |  4 ---
 include/nuttx/net/ip.h      |  3 +-
 include/nuttx/net/ipv6ext.h |  8 +++--
 include/nuttx/net/net.h     |  2 +-
 include/nuttx/net/tcp.h     |  2 +-
 net/socket/net_fstat.c      |  3 +-
 net/socket/net_sockif.c     |  2 +-
 net/socket/socket.h         | 88 ++-------------------------------------------
 net/utils/net_lock.c        |  7 ++--
 net/utils/utils.h           |  2 +-
 19 files changed, 33 insertions(+), 129 deletions(-)

diff --git a/include/arpa/inet.h b/include/arpa/inet.h
index 86ea215..26b9e31 100644
--- a/include/arpa/inet.h
+++ b/include/arpa/inet.h
@@ -118,13 +118,13 @@ in_addr_t   inet_lnaof(struct in_addr in);
 in_addr_t   inet_netof(struct in_addr in);
 #else
 FAR char   *_inet_ntoa(in_addr_t in);
-# define inet_ntoa(in) _inet_ntoa(in.s_addr);
+# define inet_ntoa(in) _inet_ntoa(in.s_addr)
 
 in_addr_t   _inet_lnaof(in_addr_t in);
-# define inet_lnaof(in) _inet_lnaof(in.s_addr);
+# define inet_lnaof(in) _inet_lnaof(in.s_addr)
 
 in_addr_t   _inet_netof(in_addr_t in);
-# define inet_netof(in) _inet_netof(in.s_addr);
+# define inet_netof(in) _inet_netof(in.s_addr)
 #endif
 struct in_addr inet_makeaddr(in_addr_t net, in_addr_t host);
 
diff --git a/include/net/if.h b/include/net/if.h
index 1d06f70..9a26ec3 100644
--- a/include/net/if.h
+++ b/include/net/if.h
@@ -176,7 +176,7 @@ struct lifreq
 #define lifr_mii_val_in       lifr_ifru.lifru_mii_data.val_in  /* PHY input data */
 #define lifr_mii_val_out      lifr_ifru.lifru_mii_data.val_out /* PHY output data */
 
-/* Used only with the SIOCGLIFCONF IOCTL commnd*/
+/* Used only with the SIOCGLIFCONF IOCTL commnd */
 
 struct lifconf
 {
@@ -221,7 +221,6 @@ struct ifreq
 #define ifr_flags             ifr_ifru.ifru_flags       /* interface flags */
 #define ifr_mii_notify_pid    ifr_ifru.ifru_mii_notify.pid   /* PID to be notified */
 #define ifr_mii_notify_event  ifr_ifru.ifru_mii_notify.event /* Describes notification */
-#define ifr_mii_notify_arg    ifr_ifru.ifru_mii_notify.arg   /* sigval argument */
 #define ifr_mii_phy_id        ifr_ifru.ifru_mii_data.phy_id  /* PHY device address */
 #define ifr_mii_reg_num       ifr_ifru.ifru_mii_data.reg_num /* PHY register address */
 #define ifr_mii_val_in        ifr_ifru.ifru_mii_data.val_in  /* PHY input data */
diff --git a/include/net/route.h b/include/net/route.h
index 24f37b7..9f859d7 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -110,8 +110,8 @@ int addroute(int sockfd, FAR struct sockaddr_storage *target,
  * Name: net_delroute
  *
  * Description:
- *   Add a new route to the routing table.  This is just a convenience
- *   wrapper for the SIOCADDRT ioctl call.
+ *   Delete a route from the routing table.  This is just a convenience
+ *   wrapper for the SIOCDELRT ioctl call.
  *
  * Input Parameters:
  *   sockfd   - Any socket descriptor
diff --git a/include/netinet/arp.h b/include/netinet/arp.h
index dcaf530..c28a359 100644
--- a/include/netinet/arp.h
+++ b/include/netinet/arp.h
@@ -43,16 +43,14 @@
 #include <nuttx/config.h>
 
 #include <stdint.h>
-#include <net/if.h>
 #include <nuttx/fs/ioctl.h>
 
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
-/* Three ioctls are available on all PF_INET sockets, but only if the NuttX
- * configuration CONFIG_NET_ARPIOCTLS is defined. Each ioctl takes a pointer
- * to a 'struct arpreq' as its parameter.
+/* Three ioctls are available on all PF_INET sockets. Each ioctl takes a
+ * pointer to a 'struct arpreq' as its parameter.
  */
 
 #define SIOCSARP        _ARPIOC(1) /* Set a ARP mapping */
@@ -102,15 +100,9 @@ extern "C"
  * Public Function Prototypes
  ****************************************************************************/
 
-/* If CONFIG_NET_ARPIOCTLS is defined then the semi-standard ioctl commands
- * described above are supported.  If not, you can call the network ARP
- * interfaces directly in a very non-standard way.  See
- * include/nuttx/net/arp.h for prototypes.
- */
-
 #undef EXTERN
 #ifdef __cplusplus
 }
 #endif
 
-#endif /*   __INCLUDE_NETINET_ARP_H */
+#endif /* __INCLUDE_NETINET_ARP_H */
diff --git a/include/netinet/ether.h b/include/netinet/ether.h
index e7cb37e..63416df 100644
--- a/include/netinet/ether.h
+++ b/include/netinet/ether.h
@@ -76,4 +76,4 @@ int ether_line(FAR const char *line, FAR struct ether_addr *addr,
 }
 #endif
 
-#endif /*   __INCLUDE_NETINET_ETHER_H */
+#endif /* __INCLUDE_NETINET_ETHER_H */
diff --git a/include/netinet/ip6.h b/include/netinet/ip6.h
index be16ae7..7f486f1 100644
--- a/include/netinet/ip6.h
+++ b/include/netinet/ip6.h
@@ -33,8 +33,8 @@
  *
  ****************************************************************************/
 
-#ifndef __INCLUDE_NETINET_I6P_H
-#define __INCLUDE_NETINET_I6P_H
+#ifndef __INCLUDE_NETINET_IP6_H
+#define __INCLUDE_NETINET_IP6_H
 
 /****************************************************************************
  * Included Files
@@ -51,4 +51,4 @@
  * Public Function Prototypes
  ****************************************************************************/
 
-#endif /* __INCLUDE_NETINET_I6P_H */
+#endif /* __INCLUDE_NETINET_IP6_H */
diff --git a/include/nuttx/fs/ioctl.h b/include/nuttx/fs/ioctl.h
index a9b8cae..31809d6 100644
--- a/include/nuttx/fs/ioctl.h
+++ b/include/nuttx/fs/ioctl.h
@@ -310,7 +310,7 @@
 #define _CAIOCVALID(c)    (_IOC_TYPE(c)==_CAIOCBASE)
 #define _CAIOC(nr)        _IOC(_CAIOCBASE,nr)
 
-/* NuttX USB CDC/ACM serial driver ioctl definitions ************************/
+/* NuttX battery driver ioctl definitions ***********************************/
 
 /* (see nuttx/power/battery.h) */
 
@@ -368,7 +368,7 @@
 
 /* Discrete Joystick (see nuttx/include/input/djoystick.h */
 
-#define _JOYIOCVALID(c)   (_IOC_SMASK(c)==_JOYBASE)
+#define _JOYIOCVALID(c)   (_IOC_TYPE(c)==_JOYBASE)
 #define _JOYIOC(nr)       _IOC(_JOYBASE,nr)
 
 /* FIFOs and pipe driver ioctl definitions **********************************/
diff --git a/include/nuttx/net/icmp.h b/include/nuttx/net/icmp.h
index 9ba90bf..dacde22 100644
--- a/include/nuttx/net/icmp.h
+++ b/include/nuttx/net/icmp.h
@@ -51,7 +51,6 @@
 
 #include <nuttx/net/netconfig.h>
 #include <nuttx/net/ip.h>
-#include <nuttx/net/tcp.h>
 
 /****************************************************************************
  * Pre-processor Definitions
diff --git a/include/nuttx/net/icmpv6.h b/include/nuttx/net/icmpv6.h
index 4f3c1dc..87799f9 100644
--- a/include/nuttx/net/icmpv6.h
+++ b/include/nuttx/net/icmpv6.h
@@ -51,7 +51,6 @@
 
 #include <nuttx/net/netconfig.h>
 #include <nuttx/net/ip.h>
-#include <nuttx/net/tcp.h>
 
 /****************************************************************************
  * Pre-processor Definitions
diff --git a/include/nuttx/net/igmp.h b/include/nuttx/net/igmp.h
index 5a18cc0..132a535 100644
--- a/include/nuttx/net/igmp.h
+++ b/include/nuttx/net/igmp.h
@@ -50,12 +50,8 @@
 
 #include <stdint.h>
 #include <stdbool.h>
-#include <semaphore.h>
-
-#include <netinet/in.h>
 
 #include <nuttx/net/netconfig.h>
-#include <nuttx/net/netdev.h>
 #include <nuttx/net/ip.h>
 
 #ifdef CONFIG_NET_IGMP
diff --git a/include/nuttx/net/ip.h b/include/nuttx/net/ip.h
index 0a2d39d..af1a31e 100644
--- a/include/nuttx/net/ip.h
+++ b/include/nuttx/net/ip.h
@@ -52,7 +52,6 @@
 
 #include <stdint.h>
 #include <stdbool.h>
-#include <queue.h>
 
 #include <arpa/inet.h>
 #include <netinet/in.h>
@@ -564,7 +563,7 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
  * Name: net_is_addr_loopback
  *
  * Description:
- *   Is Ithe Pv6 address a the loopback address?  See RFC 4291 (replaces
+ *   Is the IPv6 address a the loopback address?  See RFC 4291 (replaces
  *   3513).
  *
  ****************************************************************************/
diff --git a/include/nuttx/net/ipv6ext.h b/include/nuttx/net/ipv6ext.h
index b1359f3..72fb54a 100644
--- a/include/nuttx/net/ipv6ext.h
+++ b/include/nuttx/net/ipv6ext.h
@@ -1,6 +1,6 @@
 /****************************************************************************
  * include/nuttx/net/ipv6ext.h
- * IPv4 Extension Header Definitions
+ * IPv6 Extension Header Definitions
  *
  *   Copyright (C) 2018 Gregory Nutt. All rights reserved.
  *   Author: Gregory Nutt <gn...@nuttx.org>
@@ -107,9 +107,13 @@
  */
 
 #define NEXT_HOPBYBOT_EH       0     /*   0  Hop-by-Hop Options Header */
+                                     /*   1  See IP_PROTO_ICMP in
+                                      *   include/nuttx/net/ip.h. */
+                                     /*   2  See IP_PROTO_IGMP in
+                                      *   include/nuttx/net/ip.h. */
                                      /*   6  See IP_PROTO_TCP in
                                       *   include/nuttx/net/ip.h. */
-                                     /*  17  See IP_PROTO_TCP in
+                                     /*  17  See IP_PROTO_UDP in
                                       *      include/nuttx/net/ip.h. */
 #define NEXT_ENCAP_EH          41    /*  41  Encapsulated IPv6 Header */
 #define NEXT_ROUTING_EH        43    /*  43  Routing Header */
diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h
index 3ad7afb..a711875 100644
--- a/include/nuttx/net/net.h
+++ b/include/nuttx/net/net.h
@@ -1376,7 +1376,7 @@ int net_dup2(int sockfd1, int sockfd2);
  *
  * Input Parameters:
  *   sockfd - Socket descriptor of the socket to operate on
- *   bug    - Caller-provided location in which to return the fstat data
+ *   buf    - Caller-provided location in which to return the fstat data
  *
  * Returned Value:
  *   Zero (OK) is returned on success; a negated errno value is returned on
diff --git a/include/nuttx/net/tcp.h b/include/nuttx/net/tcp.h
index 4fb4a20..3e9f6dc 100644
--- a/include/nuttx/net/tcp.h
+++ b/include/nuttx/net/tcp.h
@@ -56,7 +56,7 @@
 #include <stdint.h>
 
 #include <nuttx/net/netconfig.h>
-#include <nuttx/net/arp.h>
+#include <nuttx/net/ethernet.h>
 #include <nuttx/net/ip.h>
 
 /****************************************************************************
diff --git a/net/socket/net_fstat.c b/net/socket/net_fstat.c
index 0462ae7..46b6788 100644
--- a/net/socket/net_fstat.c
+++ b/net/socket/net_fstat.c
@@ -44,7 +44,6 @@
 #include <errno.h>
 #include <debug.h>
 
-#include <nuttx/net/netconfig.h>
 #include <nuttx/net/net.h>
 #include <nuttx/net/netdev.h>
 
@@ -64,7 +63,7 @@
  *
  * Input Parameters:
  *   sockfd - Socket descriptor of the socket to operate on
- *   bug    - Caller-provided location in which to return the fstat data
+ *   buf    - Caller-provided location in which to return the fstat data
  *
  * Returned Value:
  *   Zero (OK) is returned on success; a negated errno value is returned on
diff --git a/net/socket/net_sockif.c b/net/socket/net_sockif.c
index ef9dfbc..01e8368 100644
--- a/net/socket/net_sockif.c
+++ b/net/socket/net_sockif.c
@@ -75,7 +75,7 @@
  ****************************************************************************/
 
 FAR const struct sock_intf_s *
-  net_sockif(sa_family_t family, int type, int protocol)
+net_sockif(sa_family_t family, int type, int protocol)
 {
   FAR const struct sock_intf_s *sockif = NULL;
 
diff --git a/net/socket/socket.h b/net/socket/socket.h
index 107e23e..ee901b2 100644
--- a/net/socket/socket.h
+++ b/net/socket/socket.h
@@ -124,9 +124,9 @@
 /* Macros to convert timeout value */
 
 #ifdef CONFIG_NET_SOCKOPTS
-#define _SO_TIMEOUT(t)   ((t) ? (t) * MSEC_PER_DSEC : UINT_MAX)
+#  define _SO_TIMEOUT(t) ((t) ? (t) * MSEC_PER_DSEC : UINT_MAX)
 #else
-#define _SO_TIMEOUT(t)   (UINT_MAX)
+#  define _SO_TIMEOUT(t) (UINT_MAX)
 #endif /* CONFIG_NET_SOCKOPTS */
 
 /* Macro to set socket errors */
@@ -213,23 +213,6 @@ void psock_release(FAR struct socket *psock);
 void sockfd_release(int sockfd);
 
 /****************************************************************************
- * Name: sockfd_socket
- *
- * Description:
- *   Given a socket descriptor, return the underlying socket structure.
- *
- * Input Parameters:
- *   sockfd - The socket descriptor index to use.
- *
- * Returned Value:
- *   On success, a reference to the socket structure associated with the
- *   the socket descriptor is returned.  NULL is returned on any failure.
- *
- ****************************************************************************/
-
-FAR struct socket *sockfd_socket(int sockfd);
-
-/****************************************************************************
  * Name: net_sockif
  *
  * Description:
@@ -247,7 +230,7 @@ FAR struct socket *sockfd_socket(int sockfd);
  ****************************************************************************/
 
 FAR const struct sock_intf_s *
-  net_sockif(sa_family_t family, int type, int protocol);
+net_sockif(sa_family_t family, int type, int protocol);
 
 /****************************************************************************
  * Name: net_timeo
@@ -271,70 +254,5 @@ FAR const struct sock_intf_s *
 int net_timeo(clock_t start_time, socktimeo_t timeo);
 #endif
 
-/****************************************************************************
- * Name: psock_send
- *
- * Description:
- *   The send() call may be used only when the socket is in a connected state
- *   (so that the intended recipient is known). The only difference between
- *   send() and write() is the presence of flags. With zero flags parameter,
- *   send() is equivalent to write(). Also, send(sockfd,buf,len,flags) is
- *   equivalent to sendto(sockfd,buf,len,flags,NULL,0).
- *
- * Input Parameters:
- *   psock    An instance of the internal socket structure.
- *   buf      Data to send
- *   len      Length of data to send
- *   flags    Send flags
- *
- * Returned Value:
- *   On success, returns the number of characters sent.  On  error,
- *   -1 is returned, and errno is set appropriately:
- *
- *   EAGAIN or EWOULDBLOCK
- *     The socket is marked non-blocking and the requested operation
- *     would block.
- *   EBADF
- *     An invalid descriptor was specified.
- *   ECONNRESET
- *     Connection reset by peer.
- *   EDESTADDRREQ
- *     The socket is not connection-mode, and no peer address is set.
- *   EFAULT
- *      An invalid user space address was specified for a parameter.
- *   EINTR
- *      A signal occurred before any data was transmitted.
- *   EINVAL
- *      Invalid argument passed.
- *   EISCONN
- *     The connection-mode socket was connected already but a recipient
- *     was specified. (Now either this error is returned, or the recipient
- *     specification is ignored.)
- *   EMSGSIZE
- *     The socket type requires that message be sent atomically, and the
- *     size of the message to be sent made this impossible.
- *   ENOBUFS
- *     The output queue for a network interface was full. This generally
- *     indicates that the interface has stopped sending, but may be
- *     caused by transient congestion.
- *   ENOMEM
- *     No memory available.
- *   ENOTCONN
- *     The socket is not connected, and no target has been given.
- *   ENOTSOCK
- *     The argument s is not a socket.
- *   EOPNOTSUPP
- *     Some bit in the flags argument is inappropriate for the socket
- *     type.
- *   EPIPE
- *     The local end has been shut down on a connection oriented socket.
- *     In this case the process will also receive a SIGPIPE unless
- *     MSG_NOSIGNAL is set.
- *
- ****************************************************************************/
-
-ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len,
-                   int flags);
-
 #endif /* CONFIG_NET */
 #endif /* _NET_SOCKET_SOCKET_H */
diff --git a/net/utils/net_lock.c b/net/utils/net_lock.c
index 376bf76..ba51c4d 100644
--- a/net/utils/net_lock.c
+++ b/net/utils/net_lock.c
@@ -40,14 +40,13 @@
 #include <nuttx/config.h>
 
 #include <unistd.h>
-#include <semaphore.h>
+#include <sched.h>
 #include <assert.h>
 #include <errno.h>
 #include <debug.h>
 #include <time.h>
 
 #include <nuttx/irq.h>
-#include <nuttx/arch.h>
 #include <nuttx/clock.h>
 #include <nuttx/semaphore.h>
 #include <nuttx/mm/iob.h>
@@ -66,8 +65,8 @@
  ****************************************************************************/
 
 static sem_t        g_netlock;
-static pid_t        g_holder  = NO_HOLDER;
-static unsigned int g_count   = 0;
+static pid_t        g_holder = NO_HOLDER;
+static unsigned int g_count  = 0;
 
 /****************************************************************************
  * Private Functions
diff --git a/net/utils/utils.h b/net/utils/utils.h
index e47ded9..04bc387 100644
--- a/net/utils/utils.h
+++ b/net/utils/utils.h
@@ -98,7 +98,7 @@ void net_lockinitialize(void);
 int net_breaklock(FAR unsigned int *count);
 
 /****************************************************************************
- * Name: net_breaklock
+ * Name: net_restorelock
  *
  * Description:
  *   Restore the locked state


[incubator-nuttx] 04/10: Move _SF_BOUND and _SF_CONNECTED modification to common place

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 6e6c67019010af40dbd534885c641dd7fad6611b
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Jan 31 17:34:28 2020 +0800

    Move _SF_BOUND and _SF_CONNECTED modification to common place
---
 net/bluetooth/bluetooth_sockif.c   | 10 +---------
 net/ieee802154/ieee802154_sockif.c | 10 +---------
 net/inet/inet_sockif.c             | 20 ++------------------
 net/inet/ipv4_getpeername.c        |  2 +-
 net/inet/ipv6_getpeername.c        |  2 +-
 net/local/local_sockif.c           |  7 -------
 net/netlink/netlink_sockif.c       |  1 -
 net/pkt/pkt_sockif.c               |  3 ---
 net/socket/bind.c                  |  4 ++++
 net/socket/connect.c               |  9 +++++++++
 10 files changed, 19 insertions(+), 49 deletions(-)

diff --git a/net/bluetooth/bluetooth_sockif.c b/net/bluetooth/bluetooth_sockif.c
index 350208e..adf6125 100644
--- a/net/bluetooth/bluetooth_sockif.c
+++ b/net/bluetooth/bluetooth_sockif.c
@@ -271,7 +271,7 @@ static int bluetooth_connect(FAR struct socket *psock,
 {
   FAR struct bluetooth_conn_s *conn;
   FAR struct sockaddr_bt_s *btaddr;
-  int ret;
+  int ret = OK;
 
   DEBUGASSERT(psock != NULL || addr != NULL);
   conn = (FAR struct bluetooth_conn_s *)psock->s_conn;
@@ -286,11 +286,6 @@ static int bluetooth_connect(FAR struct socket *psock,
       btaddr = (FAR struct sockaddr_bt_s *)addr;
       memcpy(&conn->bc_raddr, &btaddr->bt_bdaddr, sizeof(bt_addr_t));
       conn->bc_channel = btaddr->bt_channel;
-
-      /* Mark the socket as connected. */
-
-      psock->s_flags |= _SF_CONNECTED;
-      ret = OK;
     }
   else
     {
@@ -437,9 +432,6 @@ static int bluetooth_bind(FAR struct socket *psock,
 
   memcpy(&conn->bc_laddr, &iaddr->bt_bdaddr, sizeof(bt_addr_t));
 
-  /* Mark the socket bound */
-
-  psock->s_flags |= _SF_BOUND;
   return OK;
 }
 
diff --git a/net/ieee802154/ieee802154_sockif.c b/net/ieee802154/ieee802154_sockif.c
index 597673e..0acad43 100644
--- a/net/ieee802154/ieee802154_sockif.c
+++ b/net/ieee802154/ieee802154_sockif.c
@@ -275,7 +275,7 @@ static int ieee802154_connect(FAR struct socket *psock,
 {
   FAR struct ieee802154_conn_s *conn;
   FAR struct sockaddr_ieee802154_s *ieeeaddr;
-  int ret;
+  int ret = OK;
 
   DEBUGASSERT(psock != NULL || addr != NULL);
   conn = (FAR struct ieee802154_conn_s *)psock->s_conn;
@@ -290,11 +290,6 @@ static int ieee802154_connect(FAR struct socket *psock,
       ieeeaddr = (FAR struct sockaddr_ieee802154_s *)addr;
       memcpy(&conn->raddr, &ieeeaddr->sa_addr,
              sizeof(struct ieee802154_saddr_s));
-
-      /* Mark the socket as connected. */
-
-      psock->s_flags |= _SF_CONNECTED;
-      ret = OK;
     }
   else
     {
@@ -444,9 +439,6 @@ static int ieee802154_bind(FAR struct socket *psock,
 
   memcpy(&conn->laddr, &iaddr->sa_addr, sizeof(struct ieee802154_saddr_s));
 
-  /* Mark the socket bound */
-
-  psock->s_flags |= _SF_BOUND;
   return OK;
 }
 
diff --git a/net/inet/inet_sockif.c b/net/inet/inet_sockif.c
index c42fdbb..27f2acf 100644
--- a/net/inet/inet_sockif.c
+++ b/net/inet/inet_sockif.c
@@ -409,13 +409,6 @@ static int inet_bind(FAR struct socket *psock,
           /* Bind a TCP/IP stream socket. */
 
           ret = tcp_bind(psock->s_conn, addr);
-
-          /* Mark the socket bound */
-
-          if (ret >= 0)
-            {
-              psock->s_flags |= _SF_BOUND;
-            }
 #else
           nwarn("WARNING: TCP/IP stack is not available in this configuration\n");
           return -ENOSYS;
@@ -431,13 +424,6 @@ static int inet_bind(FAR struct socket *psock,
           /* Bind a UDP/IP datagram socket */
 
           ret = udp_bind(psock->s_conn, addr);
-
-          /* Mark the socket bound */
-
-          if (ret >= 0)
-            {
-              psock->s_flags |= _SF_BOUND;
-            }
 #else
           nwarn("WARNING: UDP stack is not available in this configuration\n");
           ret = -ENOSYS;
@@ -757,15 +743,13 @@ static int inet_connect(FAR struct socket *psock,
             {
               /* Failed to connect or explicitly disconnected */
 
-              psock->s_flags &= ~_SF_CONNECTED;
-              conn->flags    &= ~_UDP_FLAG_CONNECTMODE;
+              conn->flags &= ~_UDP_FLAG_CONNECTMODE;
             }
           else
             {
               /* Successfully connected */
 
-              psock->s_flags |= _SF_CONNECTED;
-              conn->flags    |= _UDP_FLAG_CONNECTMODE;
+              conn->flags |= _UDP_FLAG_CONNECTMODE;
             }
 
           return ret;
diff --git a/net/inet/ipv4_getpeername.c b/net/inet/ipv4_getpeername.c
index 1560b2f..c63480e 100644
--- a/net/inet/ipv4_getpeername.c
+++ b/net/inet/ipv4_getpeername.c
@@ -102,7 +102,7 @@ int ipv4_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
 
   /* Verify that the socket has been connected */
 
-  if ((psock->s_flags & _SF_CONNECTED) == 0)
+  if (_SS_ISCONNECTED(psock->s_flags) == 0)
     {
       return -ENOTCONN;
     }
diff --git a/net/inet/ipv6_getpeername.c b/net/inet/ipv6_getpeername.c
index ab6329c..9728e28 100644
--- a/net/inet/ipv6_getpeername.c
+++ b/net/inet/ipv6_getpeername.c
@@ -101,7 +101,7 @@ int ipv6_getpeername(FAR struct socket *psock, FAR struct sockaddr *addr,
 
   /* Verify that the socket has been connected */
 
-  if ((psock->s_flags & _SF_CONNECTED) == 0)
+  if (_SS_ISCONNECTED(psock->s_flags) == 0)
     {
       return -ENOTCONN;
     }
diff --git a/net/local/local_sockif.c b/net/local/local_sockif.c
index 97f0922..5b2f533 100644
--- a/net/local/local_sockif.c
+++ b/net/local/local_sockif.c
@@ -309,13 +309,6 @@ static int local_bind(FAR struct socket *psock,
           /* Bind the Unix domain connection structure */
 
           ret = psock_local_bind(psock, addr, addrlen);
-
-          /* Mark the socket bound */
-
-          if (ret >= 0)
-            {
-              psock->s_flags |= _SF_BOUND;
-            }
         }
         break;
 #endif /* CONFIG_NET_LOCAL_STREAM || CONFIG_NET_LOCAL_DGRAM */
diff --git a/net/netlink/netlink_sockif.c b/net/netlink/netlink_sockif.c
index 40d8d3d..cff507a 100644
--- a/net/netlink/netlink_sockif.c
+++ b/net/netlink/netlink_sockif.c
@@ -287,7 +287,6 @@ static int netlink_bind(FAR struct socket *psock,
   conn->pid       = nladdr->nl_pid;
   conn->groups    = nladdr->nl_groups;
 
-  psock->s_flags |= _SF_BOUND;
   return OK;
 }
 
diff --git a/net/pkt/pkt_sockif.c b/net/pkt/pkt_sockif.c
index a6429c3..6541dbc 100644
--- a/net/pkt/pkt_sockif.c
+++ b/net/pkt/pkt_sockif.c
@@ -387,9 +387,6 @@ static int pkt_bind(FAR struct socket *psock, FAR const struct sockaddr *addr,
       conn->ifindex = ifindex;
       memcpy(conn->lmac, dev->d_mac.ether.ether_addr_octet, 6);
 
-      /* Mark the socket bound */
-
-      psock->s_flags |= _SF_BOUND;
       return OK;
     }
   else
diff --git a/net/socket/bind.c b/net/socket/bind.c
index 00e0796..572622d 100644
--- a/net/socket/bind.c
+++ b/net/socket/bind.c
@@ -112,6 +112,10 @@ int psock_bind(FAR struct socket *psock, const struct sockaddr *addr,
       return ret;
     }
 
+  /* Mark the socket bound */
+
+  psock->s_flags |= _SF_BOUND;
+
   return OK;
 }
 
diff --git a/net/socket/connect.c b/net/socket/connect.c
index 9e3ff5b..ed8b78a 100644
--- a/net/socket/connect.c
+++ b/net/socket/connect.c
@@ -156,6 +156,15 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
       return ret;
     }
 
+  if (addr != NULL)
+    {
+      psock->s_flags |= _SF_CONNECTED;
+    }
+  else
+    {
+      psock->s_flags &= ~_SF_CONNECTED;
+    }
+
   return OK;
 }
 


[incubator-nuttx] 09/10: Add FAR for pointer type for socket header files

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 3ae5f5275742d17b5781288109792fcf81c8651f
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Feb 1 02:47:00 2020 +0800

    Add FAR for pointer type for socket header files
---
 include/nuttx/net/ip.h     | 28 ++++++++++++++--------------
 include/nuttx/net/netdev.h | 11 ++++-------
 include/sys/socket.h       | 26 +++++++++++++-------------
 3 files changed, 31 insertions(+), 34 deletions(-)

diff --git a/include/nuttx/net/ip.h b/include/nuttx/net/ip.h
index af1a31e..6ab63b5 100644
--- a/include/nuttx/net/ip.h
+++ b/include/nuttx/net/ip.h
@@ -261,12 +261,12 @@ extern "C"
 
 #ifdef CONFIG_ENDIAN_BIG
 #  define net_ip4addr_conv32(addr) \
-    (((in_addr_t)((uint16_t*)addr)[0] << 16) | \
-     (in_addr_t)((uint16_t*)addr)[1])
+    (((in_addr_t)((FAR uint16_t *)addr)[0] << 16) | \
+     (in_addr_t)((FAR uint16_t *)addr)[1])
 #else
 #  define net_ip4addr_conv32(addr) \
-    (((in_addr_t)((uint16_t*)addr)[1] << 16) | \
-     (in_addr_t)((uint16_t*)addr)[0])
+    (((in_addr_t)((FAR uint16_t *)addr)[1] << 16) | \
+     (in_addr_t)((FAR uint16_t *)addr)[0])
 #endif
 
 /****************************************************************************
@@ -304,14 +304,14 @@ extern "C"
 
 #define ip6_addr(addr, addr0,addr1,addr2,addr3,addr4,addr5,addr6,addr7) \
   do { \
-    ((uint16_t*)(addr))[0] = HTONS((addr0)); \
-    ((uint16_t*)(addr))[1] = HTONS((addr1)); \
-    ((uint16_t*)(addr))[2] = HTONS((addr2)); \
-    ((uint16_t*)(addr))[3] = HTONS((addr3)); \
-    ((uint16_t*)(addr))[4] = HTONS((addr4)); \
-    ((uint16_t*)(addr))[5] = HTONS((addr5)); \
-    ((uint16_t*)(addr))[6] = HTONS((addr6)); \
-    ((uint16_t*)(addr))[7] = HTONS((addr7)); \
+    ((FAR uint16_t *)(addr))[0] = HTONS((addr0)); \
+    ((FAR uint16_t *)(addr))[1] = HTONS((addr1)); \
+    ((FAR uint16_t *)(addr))[2] = HTONS((addr2)); \
+    ((FAR uint16_t *)(addr))[3] = HTONS((addr3)); \
+    ((FAR uint16_t *)(addr))[4] = HTONS((addr4)); \
+    ((FAR uint16_t *)(addr))[5] = HTONS((addr5)); \
+    ((FAR uint16_t *)(addr))[6] = HTONS((addr6)); \
+    ((FAR uint16_t *)(addr))[7] = HTONS((addr7)); \
   } while (0)
 
 /****************************************************************************
@@ -415,8 +415,8 @@ extern "C"
    } while (0)
 #  define net_ipv4addr_hdrcopy(dest, src) \
    do { \
-     ((uint16_t*)(dest))[0] = ((uint16_t*)(src))[0]; \
-     ((uint16_t*)(dest))[1] = ((uint16_t*)(src))[1]; \
+     ((FAR uint16_t *)(dest))[0] = ((FAR uint16_t *)(src))[0]; \
+     ((FAR uint16_t *)(dest))[1] = ((FAR uint16_t *)(src))[1]; \
    } while (0)
 #endif
 
diff --git a/include/nuttx/net/netdev.h b/include/nuttx/net/netdev.h
index 3ab2fc9..360f7af 100644
--- a/include/nuttx/net/netdev.h
+++ b/include/nuttx/net/netdev.h
@@ -51,10 +51,7 @@
 
 #include <sys/ioctl.h>
 #include <stdint.h>
-
-#ifdef CONFIG_NET_MCASTGROUP
-#  include <queue.h>
-#endif
+#include <queue.h>
 
 #include <net/if.h>
 #include <net/ethernet.h>
@@ -308,14 +305,14 @@ struct net_driver_s
    * or written to in the packet buffer.
    */
 
-  uint8_t *d_appdata;
+  FAR uint8_t *d_appdata;
 
 #ifdef CONFIG_NET_TCPURGDATA
   /* This pointer points to any urgent TCP data that has been received. Only
    * present if compiled with support for urgent data (CONFIG_NET_TCPURGDATA).
    */
 
-  uint8_t *d_urgdata;
+  FAR uint8_t *d_urgdata;
 
   /* Length of the (received) urgent data */
 
@@ -400,7 +397,7 @@ struct net_driver_s
 
   /* Drivers may attached device-specific, private information */
 
-  void *d_private;
+  FAR void *d_private;
 };
 
 typedef CODE int (*devif_poll_callback_t)(FAR struct net_driver_s *dev);
diff --git a/include/sys/socket.h b/include/sys/socket.h
index b462cda..bbf350a 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -107,7 +107,7 @@
 #define SOCK_PACKET    10 /* Obsolete and should not be used in new programs */
 
 /* Bits in the FLAGS argument to `send', `recv', et al. These are the bits
- * recognized by Linus, not all are supported by NuttX.
+ * recognized by Linux, not all are supported by NuttX.
  */
 
 #define MSG_OOB        0x0001 /* Process out-of-band data.  */
@@ -238,7 +238,7 @@
 #define CMSG_ALIGN(len) \
   (((len)+sizeof(long)-1) & ~(sizeof(long)-1))
 #define CMSG_DATA(cmsg) \
-  ((void *)((char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr))))
+  ((FAR void *)((FAR char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr))))
 #define CMSG_SPACE(len) \
   (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len))
 #define CMSG_LEN(len)   \
@@ -298,11 +298,11 @@ struct linger
 
 struct msghdr
 {
-  void *msg_name;               /* Socket name */
+  FAR void *msg_name;           /* Socket name */
   int msg_namelen;              /* Length of name */
-  struct iovec *msg_iov;        /* Data blocks */
+  FAR struct iovec *msg_iov;    /* Data blocks */
   unsigned long msg_iovlen;     /* Number of blocks */
-  void *msg_control;            /* Per protocol magic (eg BSD file descriptor passing) */
+  FAR void *msg_control;        /* Per protocol magic (eg BSD file descriptor passing) */
   unsigned long msg_controllen; /* Length of cmsg list */
   unsigned int msg_flags;
 };
@@ -318,23 +318,23 @@ struct cmsghdr
  * Inline Functions
  ****************************************************************************/
 
-static inline struct cmsghdr *__cmsg_nxthdr(FAR void *__ctl,
-                                            unsigned int __size,
-                                            FAR struct cmsghdr *__cmsg)
+static inline FAR struct cmsghdr *__cmsg_nxthdr(FAR void *__ctl,
+                                                unsigned int __size,
+                                                FAR struct cmsghdr *__cmsg)
 {
   FAR struct cmsghdr *__ptr;
 
-  __ptr = (struct cmsghdr *)(((unsigned char *)__cmsg) + CMSG_ALIGN(__cmsg->cmsg_len));
-  if ((unsigned long)((char *)(__ptr + 1) - (char *)__ctl) > __size)
+  __ptr = (FAR struct cmsghdr *)(((FAR char *)__cmsg) + CMSG_ALIGN(__cmsg->cmsg_len));
+  if ((unsigned long)((FAR char *)(__ptr + 1) - (FAR char *)__ctl) > __size)
     {
-      return (struct cmsghdr *)0;
+      return (FAR struct cmsghdr *)NULL;
     }
 
   return __ptr;
 }
 
-static inline struct cmsghdr *cmsg_nxthdr(FAR struct msghdr *__msg,
-                                          FAR struct cmsghdr *__cmsg)
+static inline FAR struct cmsghdr *cmsg_nxthdr(FAR struct msghdr *__msg,
+                                              FAR struct cmsghdr *__cmsg)
 {
   return __cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg);
 }


[incubator-nuttx] 10/10: Fix the wrong IPv6 TCP MSS calculation

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 4a238f2e7b27d285c0771933e64e255f573a792f
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sat Feb 1 02:59:54 2020 +0800

    Fix the wrong IPv6 TCP MSS calculation
    
    1280(MTU) - 40(IPv6_HDRLEN) - 20(TCP_HDRLEN) = 1220
---
 include/nuttx/net/netconfig.h |  9 ++++++---
 include/nuttx/net/tcp.h       | 12 ++++++------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/include/nuttx/net/netconfig.h b/include/nuttx/net/netconfig.h
index 780290f..1fdb71f 100644
--- a/include/nuttx/net/netconfig.h
+++ b/include/nuttx/net/netconfig.h
@@ -76,7 +76,7 @@
  */
 
 #define __IPv4_HDRLEN 20  /* Must match IPv4_HDRLEN in include/nuttx/net/ip.h */
-#define __IPv6_HDRLEN 40  /* Must match IPv4_HDRLEN in include/nuttx/net/ip.h */
+#define __IPv6_HDRLEN 40  /* Must match IPv6_HDRLEN in include/nuttx/net/ip.h */
 #define __UDP_HDRLEN  8   /* Must match UDP_HDRLEN in include/nuttx/net/udp.h */
 #define __TCP_HDRLEN  20  /* Must match TCP_HDRLEN in include/nuttx/net/tcp.h */
                           /* REVISIT: Not really a constant */
@@ -150,8 +150,8 @@
 #endif
 
 #ifdef CONFIG_NET_LOOPBACK
-#  define _MIN_LO_PKTSIZE      MIN(_MIN_ETH_PKTSIZE,  1518)
-#  define _MAX_LO_PKTSIZE      MAX(_MAX_ETH_PKTSIZE, 574)
+#  define _MIN_LO_PKTSIZE      MIN(_MIN_ETH_PKTSIZE, 574)
+#  define _MAX_LO_PKTSIZE      MAX(_MAX_ETH_PKTSIZE, 1518)
 #else
 #  define _MIN_LO_PKTSIZE      _MIN_ETH_PKTSIZE
 #  define _MAX_LO_PKTSIZE      _MAX_ETH_PKTSIZE
@@ -344,6 +344,9 @@
 #  undef  MIN_UDP_MSS
 #  define MIN_IPv6_UDP_MSS      __MIN_UDP_MSS(__IPv6_HDRLEN)
 #  define MIN_UDP_MSS           __MIN_UDP_MSS(__IPv6_HDRLEN)
+#  ifndef MAX_UDP_MSS
+#    define MAX_UDP_MSS         __MAX_UDP_MSS(__IPv6_HDRLEN)
+#  endif
 #endif
 
 /* TCP configuration options */
diff --git a/include/nuttx/net/tcp.h b/include/nuttx/net/tcp.h
index 3e9f6dc..a3f3750 100644
--- a/include/nuttx/net/tcp.h
+++ b/include/nuttx/net/tcp.h
@@ -125,11 +125,11 @@
  * These defaults correspond to the minimum MTU values:
  *
  *   IPv4:  MTU=576;  MSS=536  (MTU - IPv4_HDRLEN - TCP_HDRLEN)
- *   IPv6:  MTU=1280; MSS=1200 (MTU - IPv5_HDRLEN - TCP_HDRLEN)
+ *   IPv6:  MTU=1280; MSS=1220 (MTU - IPv6_HDRLEN - TCP_HDRLEN)
  */
 
 #define TCP_DEFAULT_IPv4_MSS  536
-#define TCP_DEFAULT_IPv6_MSS  1200
+#define TCP_DEFAULT_IPv6_MSS  1220
 
 /* However, we do need to make allowance for certain links such as SLIP that
  * have unusually small MTUs.
@@ -142,16 +142,16 @@
 #  define MIN_IPv4_TCP_INITIAL_MSS \
      (__MIN_TCP_MSS(IPv4_HDRLEN) > 536 ? 536 : __MIN_TCP_MSS(IPv4_HDRLEN))
 #  define MAX_IPv4_TCP_INITIAL_MSS  \
-     (__MAX_TCP_MSS(IPv4_HDRLEN) > 536 ? 536 : __MAX_TCP_MSS(h))
+     (__MAX_TCP_MSS(IPv4_HDRLEN) > 536 ? 536 : __MAX_TCP_MSS(IPv4_HDRLEN))
 #endif
 
 #ifdef CONFIG_NET_IPv6
 #  define TCP_IPv6_INITIAL_MSS(d) \
-     (TCP_MSS(d,IPv6_HDRLEN) > 1200 ? 1200 : TCP_MSS(d,IPv6_HDRLEN))
+     (TCP_MSS(d,IPv6_HDRLEN) > 1220 ? 1220 : TCP_MSS(d,IPv6_HDRLEN))
 #  define MIN_IPv6_TCP_INITIAL_MSS \
-     (__MIN_TCP_MSS(IPv6_HDRLEN) > 1200 ? 1200 : __MIN_TCP_MSS(IPv6_HDRLEN))
+     (__MIN_TCP_MSS(IPv6_HDRLEN) > 1220 ? 1220 : __MIN_TCP_MSS(IPv6_HDRLEN))
 #  define MAX_IPv6_TCP_INITIAL_MSS  \
-     (__MAX_TCP_MSS(IPv6_HDRLEN) > 1200 ? 1200 : __MAX_TCP_MSS(IPv6_HDRLEN))
+     (__MAX_TCP_MSS(IPv6_HDRLEN) > 1220 ? 1220 : __MAX_TCP_MSS(IPv6_HDRLEN))
 #endif
 
 /****************************************************************************


[incubator-nuttx] 05/10: Replace set_errno to _SO_SETERRNO

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit cf2ddbb2b1aeb6500afd4d043f17af6994cd6d8c
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Jan 31 17:48:46 2020 +0800

    Replace set_errno to _SO_SETERRNO
    
    Missed in a previous commit
---
 net/socket/getsockopt.c | 16 ++++++++--------
 net/socket/setsockopt.c | 20 ++++++++------------
 2 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/net/socket/getsockopt.c b/net/socket/getsockopt.c
index 487642c..13d8bc0 100644
--- a/net/socket/getsockopt.c
+++ b/net/socket/getsockopt.c
@@ -101,13 +101,6 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
       return -EINVAL;
     }
 
-  /* Verify that the sockfd corresponds to valid, allocated socket */
-
-  if (psock == NULL || psock->s_crefs <= 0)
-    {
-      return -EBADF;
-    }
-
 #ifdef CONFIG_NET_USRSOCK
   if (psock->s_type == SOCK_USRSOCK_TYPE)
     {
@@ -342,6 +335,13 @@ int psock_getsockopt(FAR struct socket *psock, int level, int option,
 {
   int ret;
 
+  /* Verify that the sockfd corresponds to valid, allocated socket */
+
+  if (psock == NULL || psock->s_crefs <= 0)
+    {
+      return -EBADF;
+    }
+
   /* Handle retrieval of the socket option according to the level at which
    * option should be applied.
    */
@@ -436,7 +436,7 @@ int getsockopt(int sockfd, int level, int option, void *value, socklen_t *value_
   ret = psock_getsockopt(psock, level, option, value, value_len);
   if (ret < 0)
     {
-      set_errno(-ret);
+      _SO_SETERRNO(psock, -ret);
       return ERROR;
     }
 
diff --git a/net/socket/setsockopt.c b/net/socket/setsockopt.c
index 4169f30..e968467 100644
--- a/net/socket/setsockopt.c
+++ b/net/socket/setsockopt.c
@@ -96,13 +96,6 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option,
       return -EINVAL;
     }
 
-  /* Verify that the sockfd corresponds to valid, allocated socket */
-
-  if (psock == NULL || psock->s_crefs <= 0)
-    {
-      return -EBADF;
-    }
-
 #ifdef CONFIG_NET_USRSOCK
   if (psock->s_type == SOCK_USRSOCK_TYPE)
     {
@@ -362,6 +355,13 @@ int psock_setsockopt(FAR struct socket *psock, int level, int option,
 {
   int ret;
 
+  /* Verify that the sockfd corresponds to valid, allocated socket */
+
+  if (psock == NULL || psock->s_crefs <= 0)
+    {
+      return -EBADF;
+    }
+
   /* Handle setting of the socket option according to the level at which
    * option should be applied.
    */
@@ -384,10 +384,6 @@ int psock_setsockopt(FAR struct socket *psock, int level, int option,
         break;
 #endif
 
-      /* These levels are defined in sys/socket.h, but are not yet
-       * implemented.
-       */
-
 #ifdef CONFIG_NET_IPv4
       case SOL_IP:     /* TCP protocol socket options (see include/netinet/in.h) */
         ret = ipv4_setsockopt(psock, option, value, value_len);
@@ -474,7 +470,7 @@ int setsockopt(int sockfd, int level, int option, const void *value,
   ret = psock_setsockopt(psock, level, option, value, value_len);
   if (ret < 0)
     {
-      set_errno(-ret);
+      _SO_SETERRNO(psock, -ret);
       return ERROR;
     }
 


[incubator-nuttx] 03/10: Move the lock from psock_release to sockfd_release

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 709dc1935036dc44481e93cf842e91898212e34f
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Fri Jan 31 17:43:41 2020 +0800

    Move the lock from psock_release to sockfd_release
    
    Since the kernel psock doesn't bind to any socketlist
---
 net/socket/net_sockets.c | 45 +++++++++++++++++++++------------------------
 1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/net/socket/net_sockets.c b/net/socket/net_sockets.c
index d6523ed..233d48e 100644
--- a/net/socket/net_sockets.c
+++ b/net/socket/net_sockets.c
@@ -40,7 +40,6 @@
 #include <nuttx/config.h>
 
 #include <string.h>
-#include <semaphore.h>
 #include <assert.h>
 #include <sched.h>
 #include <errno.h>
@@ -48,6 +47,7 @@
 
 #include <nuttx/net/net.h>
 #include <nuttx/kmalloc.h>
+#include <nuttx/semaphore.h>
 
 #include "socket/socket.h"
 
@@ -192,30 +192,19 @@ void psock_release(FAR struct socket *psock)
 {
   if (psock != NULL)
     {
-      /* Take the list semaphore so that there will be no accesses
-       * to this socket structure.
+      /* Decrement the count if there the socket will persist
+       * after this.
        */
 
-      FAR struct socketlist *list = sched_getsockets();
-      if (list)
+      if (psock->s_crefs > 1)
         {
-          /* Decrement the count if there the socket will persist
-           * after this.
-           */
-
-          _net_semtake(list);
-          if (psock->s_crefs > 1)
-            {
-              psock->s_crefs--;
-            }
-          else
-            {
-              /* The socket will not persist... reset it */
-
-              memset(psock, 0, sizeof(struct socket));
-            }
+          psock->s_crefs--;
+        }
+      else
+        {
+          /* The socket will not persist... reset it */
 
-          _net_semgive(list);
+          memset(psock, 0, sizeof(struct socket));
         }
     }
 }
@@ -240,11 +229,19 @@ void sockfd_release(int sockfd)
 
   FAR struct socket *psock = sockfd_socket(sockfd);
 
-  /* Get the socket structure for this sockfd */
-
   if (psock)
     {
-      psock_release(psock);
+      /* Take the list semaphore so that there will be no accesses
+       * to this socket structure.
+       */
+
+      FAR struct socketlist *list = sched_getsockets();
+      if (list)
+        {
+          _net_semtake(list);
+          psock_release(psock);
+          _net_semgive(list);
+        }
     }
 }