From 5d5ffe9cb3a21b87a86b7f681922471241c7ef73 Mon Sep 17 00:00:00 2001 From: Gurucharan Shetty Date: Mon, 24 Feb 2014 09:58:35 -0800 Subject: [PATCH] socket-util: drain_rcvbuf() for Windows. Netlink sockets are created as blocking sockets. So, we can't afford to remove MSG_DONTWAIT for Linux. drain_rcvbuf() is currently called from netlink-socket.c and netdev-linux.c. As of now, I don't see it being used for Windows. Bug #1200865. Reported-by: Len Gao Signed-off-by: Gurucharan Shetty Acked-by: Ben Pfaff --- AUTHORS | 1 + lib/socket-util.c | 5 ++++- lib/socket-util.h | 2 ++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index dbc679b68..d8f13ba43 100644 --- a/AUTHORS +++ b/AUTHORS @@ -202,6 +202,7 @@ Koichi Yagishita yagishita.koichi@jrc.co.jp Konstantin Khorenko khorenko@openvz.org Kris zhang zhang.kris@gmail.com Krishna Miriyala krishna@nicira.com +Len Gao leng@vmware.com Logan Rosen logatronico@gmail.com Luca Falavigna dktrkranz@debian.org Luiz Henrique Ozaki luiz.ozaki@gmail.com diff --git a/lib/socket-util.c b/lib/socket-util.c index eec2713da..728c76e33 100644 --- a/lib/socket-util.c +++ b/lib/socket-util.c @@ -250,6 +250,7 @@ check_connection_completion(int fd) } } +#ifndef _WIN32 /* Drain all the data currently in the receive queue of a datagram socket (and * possibly additional data). There is no way to know how many packets are in * the receive queue, but we do know that the total number of bytes queued does @@ -275,7 +276,8 @@ drain_rcvbuf(int fd) * On other Unix-like OSes, MSG_TRUNC has no effect in the flags * argument. */ char buffer[LINUX_DATAPATH ? 1 : 2048]; - ssize_t n_bytes = recv(fd, buffer, sizeof buffer, MSG_TRUNC); + ssize_t n_bytes = recv(fd, buffer, sizeof buffer, + MSG_TRUNC | MSG_DONTWAIT); if (n_bytes <= 0 || n_bytes >= rcvbuf) { break; } @@ -283,6 +285,7 @@ drain_rcvbuf(int fd) } return 0; } +#endif /* Returns the size of socket 'sock''s receive buffer (SO_RCVBUF), or a * negative errno value if an error occurs. */ diff --git a/lib/socket-util.h b/lib/socket-util.h index 61372f8a7..92f0c6f71 100644 --- a/lib/socket-util.h +++ b/lib/socket-util.h @@ -38,7 +38,9 @@ int lookup_hostname(const char *host_name, struct in_addr *); int get_socket_rcvbuf(int sock); int check_connection_completion(int fd); +#ifndef _WIN32 int drain_rcvbuf(int fd); +#endif void drain_fd(int fd, size_t n_packets); #ifndef _WIN32 int make_unix_socket(int style, bool nonblock, -- 2.43.0