You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2018/06/28 18:22:18 UTC

[04/16] mesos git commit: Windows: Made socket `int_fd` castable to `HANDLE` type.

Windows: Made socket `int_fd` castable to `HANDLE` type.

Many Win32 functions that take in `HANDLE` also work on `SOCKET`, such
as `ReadFile` or `CreateIoCompletionPort`. IOCP on Windows uses the
`HANDLE` type uniformly, so we need to be able to convert socket
`int_fd` to `HANDLE`.

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


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

Branch: refs/heads/master
Commit: f7f1c45739443109b9451472578746d21f7cef99
Parents: f6f35a8
Author: Akash Gupta <ak...@hotmail.com>
Authored: Wed Jun 27 14:30:11 2018 -0700
Committer: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Committed: Wed Jun 27 15:06:10 2018 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/windows/fd.hpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f7f1c457/3rdparty/stout/include/stout/os/windows/fd.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/fd.hpp b/3rdparty/stout/include/stout/os/windows/fd.hpp
index 89a037a..b472658 100644
--- a/3rdparty/stout/include/stout/os/windows/fd.hpp
+++ b/3rdparty/stout/include/stout/os/windows/fd.hpp
@@ -153,7 +153,15 @@ public:
 
   operator HANDLE() const
   {
-    CHECK_EQ(Type::HANDLE, type());
+    // A `SOCKET` can be treated as a regular file `HANDLE` [1]. There are
+    // many Win32 functions that work on a `SOCKET` but have the `HANDLE`
+    // type as a function parameter like `CreateIoCompletionPort`, so we need
+    // to be able to cast a `SOCKET` based `int_fd` to a `HANDLE`.
+    //
+    // [1]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740522(v=vs.85).aspx // NOLINT(whitespace/line_length)
+    if (type() == Type::SOCKET) {
+      return reinterpret_cast<HANDLE>(socket_);
+    }
     return handle_;
   }