Repository: mesos Updated Branches: refs/heads/master e80834526 -> 394141075
Windows: Added pipe support functions. Review: https://reviews.apache.org/r/47942/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2bbd1b2c Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2bbd1b2c Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2bbd1b2c Branch: refs/heads/master Commit: 2bbd1b2c177879a48745daf45ae13631c1ef53ac Parents: e808345 Author: Alex Clemmer <[email protected]> Authored: Mon May 30 20:16:21 2016 -0700 Committer: Joris Van Remoortere <[email protected]> Committed: Mon May 30 20:29:13 2016 -0700 ---------------------------------------------------------------------- 3rdparty/stout/include/stout/posix/os.hpp | 10 +++++ 3rdparty/stout/include/stout/windows/os.hpp | 56 ++++++++++++++++++++++++ 2 files changed, 66 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/2bbd1b2c/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 f08604c..715ae34 100644 --- a/3rdparty/stout/include/stout/posix/os.hpp +++ b/3rdparty/stout/include/stout/posix/os.hpp @@ -446,6 +446,16 @@ inline Option<std::string> which(const std::string& command) return None(); } + +// Create pipes for interprocess communication. +inline Try<Nothing> pipe(int pipe_fd[2]) +{ + if (::pipe(pipe_fd) == -1) { + return ErrnoError(); + } + return Nothing(); +} + } // namespace os { #endif // __STOUT_POSIX_OS_HPP__ http://git-wip-us.apache.org/repos/asf/mesos/blob/2bbd1b2c/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 275c17d..f7043f6 100644 --- a/3rdparty/stout/include/stout/windows/os.hpp +++ b/3rdparty/stout/include/stout/windows/os.hpp @@ -746,6 +746,62 @@ inline Try<Nothing> kill_job(pid_t pid) return Nothing(); } + +// 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 = NULL; + + 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); +} + } // namespace os { #endif // __STOUT_WINDOWS_OS_HPP__
