From 1bada7ab1212c9fb3def0fb5c6af3b78de5ae85c Mon Sep 17 00:00:00 2001 From: Gurucharan Shetty Date: Tue, 18 Feb 2014 12:52:01 -0800 Subject: [PATCH] socket-util: poll() for Windows. Also, Windows does not have a MSG_DONTWAIT. Get rid of it as we always use non-blocking sockets. Co-authored-by: Linda Sun Signed-off-by: Linda Sun Signed-off-by: Gurucharan Shetty Acked-by: Ben Pfaff --- lib/socket-util.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/socket-util.c b/lib/socket-util.c index b0ff7cfc1..a13a59cfd 100644 --- a/lib/socket-util.c +++ b/lib/socket-util.c @@ -224,14 +224,19 @@ check_connection_completion(int fd) pfd.fd = fd; pfd.events = POLLOUT; + +#ifndef _WIN32 do { retval = poll(&pfd, 1, 0); } while (retval < 0 && errno == EINTR); +#else + retval = WSAPoll(&pfd, 1, 0); +#endif if (retval == 1) { if (pfd.revents & POLLERR) { - ssize_t n = send(fd, "", 1, MSG_DONTWAIT); + ssize_t n = send(fd, "", 1, 0); if (n < 0) { - return errno; + return sock_errno(); } else { VLOG_ERR_RL(&rl, "poll return POLLERR but send succeeded"); return EPROTO; @@ -239,7 +244,7 @@ check_connection_completion(int fd) } return 0; } else if (retval < 0) { - VLOG_ERR_RL(&rl, "poll: %s", ovs_strerror(errno)); + VLOG_ERR_RL(&rl, "poll: %s", sock_strerror(sock_errno())); return errno; } else { return EAGAIN; @@ -271,8 +276,7 @@ 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 | MSG_DONTWAIT); + ssize_t n_bytes = recv(fd, buffer, sizeof buffer, MSG_TRUNC); if (n_bytes <= 0 || n_bytes >= rcvbuf) { break; } -- 2.43.0