From: Zheng Liu <gnehzuil.liu@gmail.com>
To: netdev@vger.kernel.org
Cc: Eric Dumazet <edumazet@google.com>,
"David S. Miller" <davem@davemloft.net>,
Yuchung Cheng <ycheng@google.com>, Jerry Chu <hkchu@google.com>,
Xiaochen Wang <xiaochen.wxc@alibaba-inc.com>,
Zheng Liu <wenqing.lz@taobao.com>
Subject: TCP fast open question
Date: Sat, 8 Mar 2014 19:58:23 +0800 [thread overview]
Message-ID: <20140308115823.GA3185@gmail.com> (raw)
Hi all,
Now we are trying to use TCP fast open in our nginx server, and we
encounter a problem under non-blocking socket. I appreciate if some one
can reply this question. Thanks in advance.
I describe our question here. we have two machines, one is as server and
another is as client. 'net.ipv4.tcp_fastopen' on both of them are set to
3. The server program looks like below:
...
listenfd = socket(AF_INET, SOCK_STREAM, 0);
bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
int tfo_opt = 1;
setsockopt(listenfd, SOL_TCP, TCP_LISTEN_INFO, &tfo_opt, sizeof(tfo_opt));
listen(listenfd, 5);
connfd = accept(listenfd, (struct sockaddr *)NULL, NULL);
recv(connfd, &buf, 4096)
...
The client program:
...
sockfd = socket(AF_INET, SOCK_STREAM, 0);
fcntl(sockfd, F_SETFL, fcntl(sockfd, F_GETFL, 0)|O_NONBLOCK);
sendto(sockfd, msg, strlen(msg), MSG_FASTOPEN,
(struct sockaddr *)&servaddr, sizeof(servaddr);
recv(sockfd, buf, 4096, 0);
...
We use a non-blocking socket to connect the server and send some
messages. After calling sendto(2) we always get an EINPROGRESS error.
We think it is reasonable because connect(2) could also return this
error with a non-blocking socket and the connection will be established
later. The question is *whether or not the data will be sent* after the
connection is established. If I understand correctly, sendto(2) will
return the number of bytes of data queued up in the kernel or sent in
the SYN packet. Even though the EINPROGRESS is returned. If sendto(2)
returns -1, that means that no data is queued up in kernel or sent in
the packet. Please correct me if I miss-understand something.
We run the program in our testing environment, and we use tcpdump(1) to
capture the packets. From the result we can see there is no any data
that is sent. Then we do another testing that after calling sendto(2)
the client program will sleep for 5 seconds and then call send(2) to
transfer some data.
$ ./client xx.xx.xx.xx
ret -1 errno 115
The program works well. So that means that after getting a EINPROGRESS
error, the program must call send(2) manually. Is it correct? If we
want to avoid this problem, we need to set 'net.ipv4.tcp_fastopen' to
0x707 ?
Regards,
- Zheng
next reply other threads:[~2014-03-08 11:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-08 11:58 Zheng Liu [this message]
2014-03-08 12:56 ` TCP fast open question Zhi Yong Wu
2014-03-08 14:47 ` gnehzuil.liu
2014-03-10 17:09 ` Yuchung Cheng
2014-03-16 5:57 ` Zheng Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140308115823.GA3185@gmail.com \
--to=gnehzuil.liu@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkchu@google.com \
--cc=netdev@vger.kernel.org \
--cc=wenqing.lz@taobao.com \
--cc=xiaochen.wxc@alibaba-inc.com \
--cc=ycheng@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).