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

xiaoxiang 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 9869181761e tcp.h: add TCP_CORK definition
9869181761e is described below

commit 9869181761e50967ff7759887de828d50e91944d
Author: zhanghongyu <[email protected]>
AuthorDate: Tue Jan 14 15:19:00 2025 +0800

    tcp.h: add TCP_CORK definition
    
    TCP_CORK and TCP_NODELAY behave almost exactly the opposite,
    so first provide simple support for TCP_CORK.
    
    Signed-off-by: zhanghongyu <[email protected]>
---
 include/netinet/tcp.h    | 1 +
 net/tcp/tcp_getsockopt.c | 3 ++-
 net/tcp/tcp_setsockopt.c | 7 +++++--
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/include/netinet/tcp.h b/include/netinet/tcp.h
index 0af530e563d..d8b8535e09c 100644
--- a/include/netinet/tcp.h
+++ b/include/netinet/tcp.h
@@ -57,5 +57,6 @@
 #define TCP_KEEPCNT   (__SO_PROTOCOL + 3) /* Number of keepalives before death
                                            * Argument: max retry count */
 #define TCP_MAXSEG    (__SO_PROTOCOL + 4) /* The maximum segment size */
+#define TCP_CORK      (__SO_PROTOCOL + 5) /* Coalescing of small segments */
 
 #endif /* __INCLUDE_NETINET_TCP_H */
diff --git a/net/tcp/tcp_getsockopt.c b/net/tcp/tcp_getsockopt.c
index 8448787e18d..17a35653368 100644
--- a/net/tcp/tcp_getsockopt.c
+++ b/net/tcp/tcp_getsockopt.c
@@ -204,6 +204,7 @@ int tcp_getsockopt(FAR struct socket *psock, int option,
 #endif /* CONFIG_NET_TCP_KEEPALIVE */
 
       case TCP_NODELAY:  /* Avoid coalescing of small segments. */
+      case TCP_CORK:     /* coalescing of small segments. */
         if (*value_len < sizeof(int))
           {
             ret                = -EINVAL;
@@ -214,7 +215,7 @@ int tcp_getsockopt(FAR struct socket *psock, int option,
 
             /* Always true here since we do not support Nagle. */
 
-            *nodelay           = 1;
+            *nodelay           = option == TCP_NODELAY ? 1 : 0;
             *value_len         = sizeof(int);
             ret                = OK;
           }
diff --git a/net/tcp/tcp_setsockopt.c b/net/tcp/tcp_setsockopt.c
index 49fa51a5c80..928e5602c9f 100644
--- a/net/tcp/tcp_setsockopt.c
+++ b/net/tcp/tcp_setsockopt.c
@@ -216,6 +216,7 @@ int tcp_setsockopt(FAR struct socket *psock, int option,
 #endif /* CONFIG_NET_TCP_KEEPALIVE */
 
       case TCP_NODELAY: /* Avoid coalescing of small segments. */
+      case TCP_CORK:    /* coalescing of small segments. */
         if (value_len != sizeof(int))
           {
             ret = -EDOM;
@@ -224,9 +225,11 @@ int tcp_setsockopt(FAR struct socket *psock, int option,
           {
             int nodelay = *(FAR int *)value;
 
-            if (!nodelay)
+            if ((!nodelay && option == TCP_NODELAY) ||
+                (nodelay && option == TCP_CORK))
               {
-                nerr("ERROR: TCP_NODELAY not supported\n");
+                nerr("ERROR: %s not supported\n",
+                     option == TCP_NODELAY ? "TCP_NODELAY" : "TCP_CORK");
                 ret = -ENOSYS;
               }
           }

Reply via email to