Windows: Used Unicode API to duplicate sockets.

This code was still using the macro `::WSADuplicateSocket` instead of
the explicit Unicode version `::WSADuplicateSocketW`. Because `UNICODE`
has been defined, the code logically has not changed, but the comment
was out-of-date, and the warning no longer needs to be disabled.

We've left file handle duplication alone for a subsequent patch to fix,
as there are side effects from the implicit inheritance semantics of
`::_dup` that we currently rely on.

Review: https://reviews.apache.org/r/65402


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9bde2aeb
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9bde2aeb
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9bde2aeb

Branch: refs/heads/master
Commit: 9bde2aeb15045b3e255bc60afa535201fbb8c3ea
Parents: bdfee0c
Author: Andrew Schwartzmeyer <and...@schwartzmeyer.com>
Authored: Mon Jan 22 16:00:04 2018 -0800
Committer: Andrew Schwartzmeyer <and...@schwartzmeyer.com>
Committed: Fri Feb 9 11:57:27 2018 -0800

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/windows/dup.hpp | 24 ++++++++++----------
 1 file changed, 12 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/9bde2aeb/3rdparty/stout/include/stout/os/windows/dup.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/dup.hpp 
b/3rdparty/stout/include/stout/os/windows/dup.hpp
index b37aaa6..265046c 100644
--- a/3rdparty/stout/include/stout/os/windows/dup.hpp
+++ b/3rdparty/stout/include/stout/os/windows/dup.hpp
@@ -27,25 +27,25 @@ inline Try<WindowsFD> dup(const WindowsFD& fd)
   switch (fd.type()) {
     case WindowsFD::FD_CRT:
     case WindowsFD::FD_HANDLE: {
+      // TODO(andschwa): Replace this with `::DuplicateHandle` after figuring
+      // out how to make it compatible with handles to stdin/stdout/stderr, as
+      // well as defining sane inheritance semantics.
       int result = ::_dup(fd.crt());
       if (result == -1) {
         return ErrnoError();
       }
+
       return result;
     }
     case WindowsFD::FD_SOCKET: {
-#pragma warning(push)
-#pragma warning(disable : 4996)
-      // Disable compiler warning asking us to use the Unicode version of
-      // `WSASocket` and `WSADuplicateSocket`, because Mesos currently does not
-      // support Unicode. See MESOS-6817.
-      WSAPROTOCOL_INFO protInfo;
-      if (::WSADuplicateSocket(fd, GetCurrentProcessId(), &protInfo) !=
-          INVALID_SOCKET) {
-        return WSASocket(0, 0, 0, &protInfo, 0, 0);
-      };
-#pragma warning(pop)
-      return SocketError();
+      WSAPROTOCOL_INFOW info;
+      const int result =
+        ::WSADuplicateSocketW(fd, ::GetCurrentProcessId(), &info);
+      if (result != 0) {
+        return SocketError();
+      }
+
+      return ::WSASocketW(0, 0, 0, &info, 0, 0);
     }
   }
   UNREACHABLE();

Reply via email to