delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2019/07/30/23:51:33

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:reply-to:subject:to:references:from:message-id
:date:mime-version:in-reply-to:content-type
:content-transfer-encoding; q=dns; s=default; b=dkiKzhFmU716fFA1
UMJIifyo2Gmxn+vLrB3+UJPrvbdGw45GNPEHu08nfweVqBYwNPZFglgU4sRI1Iv8
Q9cAannBBABsbb3d9rlWa7obJQYxU1i+PjwmKBl8CebI4Ve+CCqwz8jaIAxQ7AOp
JUzt9g4C3N/JLp+9HrLBwLhmUkw=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:reply-to:subject:to:references:from:message-id
:date:mime-version:in-reply-to:content-type
:content-transfer-encoding; s=default; bh=oM+ttBRTgkHIZGnqIGYuXR
Djdyk=; b=E5lZON7I/OatiRaQ6Z7hPHZKj5GsDEkfkX7C+HajGECLLYbXM7Jxrn
oZ4wh80WTT07UKktwqdd7BP7A0deuV4z8fV3SrOQsusdEwDjz6SGlNCusUIqjGgg
k7q1HrMzXZ4rK1Vf9ZIHTUxrqUIHY/rBpNKlA1XD9FlOBSXaUD1CI=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00,KAM_SHORT,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=abuse, H*M:4644
X-HELO: smtp-out-no.shaw.ca
Reply-To: Brian DOT Inglis AT SystematicSw DOT ab DOT ca
Subject: Re: TCP_CORK (aka TCP_NOPUSH) does not work
To: cygwin AT cygwin DOT com
References: <BL0PR0901MB43089F348C3D31D7E07EBC20A5DC0 AT BL0PR0901MB4308 DOT namprd09 DOT prod DOT outlook DOT com>
From: Brian Inglis <Brian DOT Inglis AT SystematicSw DOT ab DOT ca>
Openpgp: preference=signencrypt
Message-ID: <77ef6d9b-c5db-0990-4644-055c9794a036@SystematicSw.ab.ca>
Date: Tue, 30 Jul 2019 21:50:35 -0600
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0
MIME-Version: 1.0
In-Reply-To: <BL0PR0901MB43089F348C3D31D7E07EBC20A5DC0@BL0PR0901MB4308.namprd09.prod.outlook.com>
X-IsSubscribed: yes

On 2019-07-30 15:30, Lavrentiev, Anton (NIH/NLM/NCBI) [C] via cygwin wrote:
> Consider the following code:
> $ cat cork.c
> #include <arpa/inet.h>
> #include <netinet/in.h>
> #include <netinet/tcp.h>
> #include <unistd.h>
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <sys/socket.h>
> #include <sys/types.h>
> #if defined(TCP_NOPUSH)  &&  !defined(TCP_CORK)
> #  define TCP_CORK  TCP_NOPUSH
> #endif

For POSIX only non-Nagle TCP_NODELAY is required:
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_tcp.h.html
and even then says:
"The implementation need not allow the value of the option to be set via
setsockopt() or retrieved via getsockopt()."

TCP_CORK is Linux only; TCP_NOPUSH is BSD only; Windows does its own thing:
https://baus.net/on-tcp_cork/
https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-tcp-socket-options

Regular SO options on Windows:
https://docs.microsoft.com/en-us/windows/win32/winsock/sol-socket-socket-options

You can abuse Nagle to get similar behaviour cross-platform:
https://stackoverflow.com/a/22118709

> int main(int argc, const char* argv[])
> {
>     union {
>         struct sockaddr_in in;
>         struct sockaddr    sa;
>     } addr;
>     int sock, cork = 1;
> 
>     memset(&addr, 0, sizeof(addr));
>     if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
>         perror("socket");
>     addr.in.sin_family = AF_INET;
>     addr.in.sin_addr.s_addr = inet_addr(argv[1]);
>     addr.in.sin_port = htons((unsigned short) atoi(argv[2]));
>     if (connect(sock, &addr.sa, sizeof(addr.in)) < 0)
>         perror("connect");
>     if (setsockopt(sock, IPPROTO_TCP, TCP_CORK, (char*) &cork, sizeof(cork)) != 0)
>         perror("cork");
>     return 0;
> }
> When compiled and run under Cygwin, the last syscall, setsockopt(), returns
> an error, Protocol not available:
> gcc cork.c
> ./a.exe 8.8.8.8 443
> cork: Protocol not available

This is error ENOPROTOOPT, where the message is misleading, but as suggested by
the name, means that the socket option is not supported for that protocol;
getsockopt(3p/3posix) says: "The option is not supported by the protocol."
getsockopt(2) for Linux and FreeBSD say: "The option is unknown at the level
indicated." and given the POSIX statement above, that error should be treated as
a warning to do something different.

> The same code works under Linux just fine.  I straced both.
> gcc cork.c
> ./a.out 8.8.8.8 443
> Any ideas?  Is TCP_NOPUSH (which is a BSDism, BTW) not actually usable on
Cygwin?  If not, why is it in the header file <netinet/tcp.h>?

If a socket option is defined, perhaps for compatibility, it should either be
used or ignored, rather than giving an error.
If you are not going to support a socket option, and generate an error, it would
be better to not define the option and generate the error at compile time,
instead of failing at run time.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

This email may be disturbing to some readers as it contains
too much technical detail. Reader discretion is advised.

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019