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; } }