You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2017/02/06 20:07:20 UTC

[7/7] mesos git commit: Introduced an `os::pipe` abstraction to stout.

Introduced an `os::pipe` abstraction to stout.

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


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

Branch: refs/heads/master
Commit: 6590b3de987a72d22ef2c654ea13464240b38af1
Parents: e0a2b0b
Author: Michael Park <mp...@apache.org>
Authored: Tue Dec 13 17:08:39 2016 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Mon Feb 6 11:54:51 2017 -0800

----------------------------------------------------------------------
 3rdparty/stout/include/Makefile.am              |  3 ++
 3rdparty/stout/include/stout/os.hpp             |  3 +-
 3rdparty/stout/include/stout/os/pipe.hpp        | 26 +++++++++
 3rdparty/stout/include/stout/os/posix/pipe.hpp  | 37 +++++++++++++
 .../stout/include/stout/os/windows/pipe.hpp     | 51 ++++++++++++++++++
 3rdparty/stout/include/stout/posix/os.hpp       | 10 ----
 3rdparty/stout/include/stout/windows/os.hpp     | 56 --------------------
 7 files changed, 119 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6590b3de/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/Makefile.am b/3rdparty/stout/include/Makefile.am
index 18f4cd1..4bde2ef 100644
--- a/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/stout/include/Makefile.am
@@ -90,6 +90,7 @@ nobase_include_HEADERS =			\
   stout/os/osx.hpp				\
   stout/os/pagesize.hpp				\
   stout/os/permissions.hpp			\
+  stout/os/pipe.hpp				\
   stout/os/process.hpp				\
   stout/os/pstree.hpp				\
   stout/os/read.hpp				\
@@ -126,6 +127,7 @@ nobase_include_HEADERS =			\
   stout/os/posix/killtree.hpp			\
   stout/os/posix/mkdtemp.hpp			\
   stout/os/posix/pagesize.hpp			\
+  stout/os/posix/pipe.hpp			\
   stout/os/posix/read.hpp			\
   stout/os/posix/rename.hpp			\
   stout/os/posix/rm.hpp				\
@@ -156,6 +158,7 @@ nobase_include_HEADERS =			\
   stout/os/windows/killtree.hpp			\
   stout/os/windows/mkdtemp.hpp			\
   stout/os/windows/pagesize.hpp			\
+  stout/os/windows/pipe.hpp				\
   stout/os/windows/read.hpp			\
   stout/os/windows/rename.hpp			\
   stout/os/windows/rm.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/6590b3de/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os.hpp b/3rdparty/stout/include/stout/os.hpp
index fd2db09..1a81db6 100644
--- a/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/stout/include/stout/os.hpp
@@ -48,9 +48,9 @@
 #include <stout/os/chroot.hpp>
 #include <stout/os/dup.hpp>
 #include <stout/os/exists.hpp>
-#include <stout/os/int_fd.hpp>
 #include <stout/os/fcntl.hpp>
 #include <stout/os/getenv.hpp>
+#include <stout/os/int_fd.hpp>
 #include <stout/os/kill.hpp>
 #include <stout/os/ls.hpp>
 #include <stout/os/lseek.hpp>
@@ -59,6 +59,7 @@
 #include <stout/os/mktemp.hpp>
 #include <stout/os/os.hpp>
 #include <stout/os/pagesize.hpp>
+#include <stout/os/pipe.hpp>
 #include <stout/os/process.hpp>
 #include <stout/os/rename.hpp>
 #include <stout/os/rm.hpp>

http://git-wip-us.apache.org/repos/asf/mesos/blob/6590b3de/3rdparty/stout/include/stout/os/pipe.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/pipe.hpp b/3rdparty/stout/include/stout/os/pipe.hpp
new file mode 100644
index 0000000..246dde0
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/pipe.hpp
@@ -0,0 +1,26 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_PIPE_HPP__
+#define __STOUT_OS_PIPE_HPP__
+
+
+// For readability, we minimize the number of #ifdef blocks in the code by
+// splitting platform specific system calls into separate directories.
+#ifdef __WINDOWS__
+#include <stout/os/windows/pipe.hpp>
+#else
+#include <stout/os/posix/pipe.hpp>
+#endif // __WINDOWS__
+
+
+#endif // __STOUT_OS_PIPE_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/6590b3de/3rdparty/stout/include/stout/os/posix/pipe.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/pipe.hpp b/3rdparty/stout/include/stout/os/posix/pipe.hpp
new file mode 100644
index 0000000..ac76224
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/posix/pipe.hpp
@@ -0,0 +1,37 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_POSIX_PIPE_HPP__
+#define __STOUT_OS_POSIX_PIPE_HPP__
+
+#include <unistd.h>
+
+#include <array>
+
+#include <stout/error.hpp>
+#include <stout/try.hpp>
+
+namespace os {
+
+// Create pipes for interprocess communication.
+inline Try<std::array<int, 2>> pipe()
+{
+  std::array<int, 2> result;
+  if (::pipe(result.data()) < 0) {
+    return ErrnoError();
+  }
+  return result;
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_POSIX_PIPE_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/6590b3de/3rdparty/stout/include/stout/os/windows/pipe.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/pipe.hpp b/3rdparty/stout/include/stout/os/windows/pipe.hpp
new file mode 100644
index 0000000..365db94
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/windows/pipe.hpp
@@ -0,0 +1,51 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_WINDOWS_PIPE_HPP__
+#define __STOUT_OS_WINDOWS_PIPE_HPP__
+
+#include <array>
+
+#include <stout/error.hpp>
+#include <stout/try.hpp>
+
+namespace os {
+
+// Create pipes for interprocess communication. Since the pipes cannot
+// be used directly by Posix `read/write' functions they are wrapped
+// in file descriptors, a process-local concept.
+inline Try<std::array<WindowsFD, 2>> pipe()
+{
+  // Create inheritable pipe, as described in MSDN[1].
+  //
+  // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa365782(v=vs.85).aspx
+  SECURITY_ATTRIBUTES securityAttr;
+  securityAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
+  securityAttr.bInheritHandle = TRUE;
+  securityAttr.lpSecurityDescriptor = nullptr;
+
+  HANDLE read_handle;
+  HANDLE write_handle;
+
+  const BOOL result =
+    ::CreatePipe(&read_handle, &write_handle, &securityAttr, 0);
+
+  if (!result) {
+    return WindowsError();
+  }
+
+  return std::array<WindowsFD, 2>{read_handle, write_handle};
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_WINDOWS_PIPE_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/6590b3de/3rdparty/stout/include/stout/posix/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/posix/os.hpp b/3rdparty/stout/include/stout/posix/os.hpp
index 68df2ef..8511dfd 100644
--- a/3rdparty/stout/include/stout/posix/os.hpp
+++ b/3rdparty/stout/include/stout/posix/os.hpp
@@ -451,16 +451,6 @@ inline Try<std::string> var()
 }
 
 
-// Create pipes for interprocess communication.
-inline Try<Nothing> pipe(int pipe_fd[2])
-{
-  if (::pipe(pipe_fd) == -1) {
-    return ErrnoError();
-  }
-  return Nothing();
-}
-
-
 inline Try<Nothing> dup2(int oldFd, int newFd)
 {
   while (::dup2(oldFd, newFd) == -1) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/6590b3de/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/stout/include/stout/windows/os.hpp
index c123772..b0fd0f2 100644
--- a/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/stout/include/stout/windows/os.hpp
@@ -749,62 +749,6 @@ inline Try<std::string> var()
 }
 
 
-// Create pipes for interprocess communication. Since the pipes cannot
-// be used directly by Posix `read/write' functions they are wrapped
-// in file descriptors, a process-local concept.
-inline Try<Nothing> pipe(int pipe[2])
-{
-  // Create inheritable pipe, as described in MSDN[1].
-  //
-  // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa365782(v=vs.85).aspx
-  SECURITY_ATTRIBUTES securityAttr;
-  securityAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
-  securityAttr.bInheritHandle = TRUE;
-  securityAttr.lpSecurityDescriptor = nullptr;
-
-  HANDLE read_handle;
-  HANDLE write_handle;
-
-  const BOOL result = ::CreatePipe(
-      &read_handle,
-      &write_handle,
-      &securityAttr,
-      0);
-
-  pipe[0] = _open_osfhandle(
-      reinterpret_cast<intptr_t>(read_handle),
-      _O_RDONLY | _O_TEXT);
-
-  if (pipe[0] == -1) {
-    return ErrnoError();
-  }
-
-  pipe[1] = _open_osfhandle(reinterpret_cast<intptr_t>(write_handle), _O_TEXT);
-  if (pipe[1] == -1) {
-    return ErrnoError();
-  }
-
-  return Nothing();
-}
-
-
-// Prepare the file descriptors to be shared with a different process.
-// Under Windows we have to obtain the underlying handles to be shared
-// with a different processs.
-inline intptr_t fd_to_handle(int in)
-{
-  return ::_get_osfhandle(in);
-}
-
-
-// Convert the global file handle into a file descriptor, which on
-// Windows is only valid within the current process.
-inline int handle_to_fd(intptr_t in, int flags)
-{
-  return ::_open_osfhandle(in, flags);
-}
-
-
 // Returns a host-specific default for the `PATH` environment variable, based
 // on the configuration of the host.
 inline std::string host_default_path()