From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Fastabend Subject: [PATCH] bpf: tcp_bpf_recvmsg should return EAGAIN when nonblocking and no data Date: Mon, 29 Oct 2018 12:31:28 -0700 Message-ID: <1540841488-22023-1-git-send-email-john.fastabend@gmail.com> Cc: john.fastabend@gmail.com, netdev@vger.kernel.org To: daniel@iogearbox.net, ast@kernel.org Return-path: Received: from mail-it1-f195.google.com ([209.85.166.195]:37605 "EHLO mail-it1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725809AbeJ3EVp (ORCPT ); Tue, 30 Oct 2018 00:21:45 -0400 Received: by mail-it1-f195.google.com with SMTP id e74-v6so10911680ita.2 for ; Mon, 29 Oct 2018 12:31:41 -0700 (PDT) Sender: netdev-owner@vger.kernel.org List-ID: We return 0 in the case of a nonblocking socket that has no data available. However, this is incorrect and may confuse applications. After this patch we do the correct thing and return the error EAGAIN. Quoting return codes from recvmsg manpage, EAGAIN or EWOULDBLOCK The socket is marked nonblocking and the receive operation would block, or a receive timeout had been set and the timeout expired before data was received. Signed-off-by: John Fastabend --- net/ipv4/tcp_bpf.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c index b7918d4..3b45fe5 100644 --- a/net/ipv4/tcp_bpf.c +++ b/net/ipv4/tcp_bpf.c @@ -145,6 +145,7 @@ int tcp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, ret = err; goto out; } + copied = -EAGAIN; } ret = copied; out: -- 1.9.1