Windows: Replaced `WindowsFD` with `int_fd` typedef. The latter should be used everywhere but in the implementation for consistency with the POSIX side of the code.
Also meant fixing the included header (and spacing). Review: https://reviews.apache.org/r/66425 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/ef511376 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/ef511376 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/ef511376 Branch: refs/heads/master Commit: ef5113760bf262a425b71744129a863f19576292 Parents: 86bb964 Author: Andrew Schwartzmeyer <[email protected]> Authored: Fri Mar 16 16:17:57 2018 -0700 Committer: Andrew Schwartzmeyer <[email protected]> Committed: Tue May 1 18:36:04 2018 -0700 ---------------------------------------------------------------------- .../include/stout/internal/windows/inherit.hpp | 5 ++-- .../stout/include/stout/os/windows/close.hpp | 5 ++-- 3rdparty/stout/include/stout/os/windows/dup.hpp | 4 +-- .../stout/include/stout/os/windows/fcntl.hpp | 12 ++++----- .../stout/include/stout/os/windows/fsync.hpp | 7 +++-- .../include/stout/os/windows/ftruncate.hpp | 5 ++-- .../stout/include/stout/os/windows/pipe.hpp | 8 +++--- .../stout/include/stout/os/windows/read.hpp | 5 ++-- .../stout/include/stout/os/windows/sendfile.hpp | 28 ++++++++------------ .../stout/include/stout/os/windows/shell.hpp | 8 +++--- .../stout/include/stout/os/windows/socket.hpp | 15 +++++------ .../stout/include/stout/os/windows/write.hpp | 5 ++-- 3rdparty/stout/include/stout/windows/os.hpp | 1 - 13 files changed, 48 insertions(+), 60 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/ef511376/3rdparty/stout/include/stout/internal/windows/inherit.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/internal/windows/inherit.hpp b/3rdparty/stout/include/stout/internal/windows/inherit.hpp index 6da6f8e..7dbde82 100644 --- a/3rdparty/stout/include/stout/internal/windows/inherit.hpp +++ b/3rdparty/stout/include/stout/internal/windows/inherit.hpp @@ -16,10 +16,9 @@ #include <stout/error.hpp> #include <stout/nothing.hpp> #include <stout/try.hpp> - -#include <stout/os/windows/fd.hpp> #include <stout/windows.hpp> +#include <stout/os/int_fd.hpp> namespace internal { namespace windows { @@ -29,7 +28,7 @@ namespace windows { // NOTE: By default, handles on Windows are not inheritable, so this is // primarily used to enable inheritance when passing handles to child processes, // and subsequently disable inheritance. -inline Try<Nothing> set_inherit(const os::WindowsFD& fd, const bool inherit) +inline Try<Nothing> set_inherit(const int_fd& fd, const bool inherit) { const BOOL result = ::SetHandleInformation( fd, HANDLE_FLAG_INHERIT, inherit ? HANDLE_FLAG_INHERIT : 0); http://git-wip-us.apache.org/repos/asf/mesos/blob/ef511376/3rdparty/stout/include/stout/os/windows/close.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/close.hpp b/3rdparty/stout/include/stout/os/windows/close.hpp index ff635e4..fc3a676 100644 --- a/3rdparty/stout/include/stout/os/windows/close.hpp +++ b/3rdparty/stout/include/stout/os/windows/close.hpp @@ -19,12 +19,13 @@ #include <stout/try.hpp> #include <stout/windows/error.hpp> -#include <stout/os/windows/fd.hpp> +#include <stout/os/int_fd.hpp> + #include <stout/os/windows/socket.hpp> namespace os { -inline Try<Nothing> close(const WindowsFD& fd) +inline Try<Nothing> close(const int_fd& fd) { switch (fd.type()) { case WindowsFD::FD_CRT: http://git-wip-us.apache.org/repos/asf/mesos/blob/ef511376/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 265046c..75ef9d8 100644 --- a/3rdparty/stout/include/stout/os/windows/dup.hpp +++ b/3rdparty/stout/include/stout/os/windows/dup.hpp @@ -18,11 +18,11 @@ #include <stout/unreachable.hpp> #include <stout/windows.hpp> // For `WinSock2.h`. -#include <stout/os/windows/fd.hpp> +#include <stout/os/int_fd.hpp> namespace os { -inline Try<WindowsFD> dup(const WindowsFD& fd) +inline Try<int_fd> dup(const int_fd& fd) { switch (fd.type()) { case WindowsFD::FD_CRT: http://git-wip-us.apache.org/repos/asf/mesos/blob/ef511376/3rdparty/stout/include/stout/os/windows/fcntl.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/fcntl.hpp b/3rdparty/stout/include/stout/os/windows/fcntl.hpp index 0e8fa8d..bb82676 100644 --- a/3rdparty/stout/include/stout/os/windows/fcntl.hpp +++ b/3rdparty/stout/include/stout/os/windows/fcntl.hpp @@ -19,30 +19,30 @@ #include <stout/try.hpp> #include <stout/windows.hpp> +#include <stout/os/int_fd.hpp> #include <stout/os/socket.hpp> -#include <stout/os/windows/fd.hpp> namespace os { -inline Try<Nothing> cloexec(const WindowsFD& fd) +inline Try<Nothing> cloexec(const int_fd& fd) { return Nothing(); } -inline Try<Nothing> unsetCloexec(const WindowsFD& fd) +inline Try<Nothing> unsetCloexec(const int_fd& fd) { return Nothing(); } -inline Try<bool> isCloexec(const WindowsFD& fd) +inline Try<bool> isCloexec(const int_fd& fd) { return true; } -inline Try<Nothing> nonblock(const WindowsFD& fd) +inline Try<Nothing> nonblock(const int_fd& fd) { switch (fd.type()) { case WindowsFD::FD_CRT: @@ -66,7 +66,7 @@ inline Try<Nothing> nonblock(const WindowsFD& fd) // NOTE: This is not supported on Windows. -inline Try<bool> isNonblock(const WindowsFD& fd) +inline Try<bool> isNonblock(const int_fd& fd) { VLOG(2) << "`os::isNonblock` has been called, but is a stub on Windows"; return true; http://git-wip-us.apache.org/repos/asf/mesos/blob/ef511376/3rdparty/stout/include/stout/os/windows/fsync.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/fsync.hpp b/3rdparty/stout/include/stout/os/windows/fsync.hpp index 8405247..b0e0b98 100644 --- a/3rdparty/stout/include/stout/os/windows/fsync.hpp +++ b/3rdparty/stout/include/stout/os/windows/fsync.hpp @@ -20,14 +20,13 @@ #include <stout/try.hpp> #include <stout/windows.hpp> -#include <stout/os/windows/fd.hpp> - +#include <stout/os/int_fd.hpp> namespace os { -inline Try<Nothing> fsync(const WindowsFD& fd) +inline Try<Nothing> fsync(const int_fd& fd) { - if (!FlushFileBuffers(fd)) { + if (!::FlushFileBuffers(fd)) { return WindowsError( "os::fsync: Could not flush file buffers for given file descriptor"); } http://git-wip-us.apache.org/repos/asf/mesos/blob/ef511376/3rdparty/stout/include/stout/os/windows/ftruncate.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/ftruncate.hpp b/3rdparty/stout/include/stout/os/windows/ftruncate.hpp index fc4a8b5..1d90d2b 100644 --- a/3rdparty/stout/include/stout/os/windows/ftruncate.hpp +++ b/3rdparty/stout/include/stout/os/windows/ftruncate.hpp @@ -20,13 +20,12 @@ #include <stout/stringify.hpp> #include <stout/try.hpp> -#include <stout/os/windows/fd.hpp> - +#include <stout/os/int_fd.hpp> namespace os { // Identical in functionality to POSIX standard `ftruncate`. -inline Try<Nothing> ftruncate(const WindowsFD& fd, __int64 length) +inline Try<Nothing> ftruncate(const int_fd& fd, __int64 length) { if (::_chsize_s(fd.crt(), length) != 0) { return ErrnoError( http://git-wip-us.apache.org/repos/asf/mesos/blob/ef511376/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 index 365db94..8ea89b9 100644 --- a/3rdparty/stout/include/stout/os/windows/pipe.hpp +++ b/3rdparty/stout/include/stout/os/windows/pipe.hpp @@ -18,12 +18,14 @@ #include <stout/error.hpp> #include <stout/try.hpp> +#include <stout/os/int_fd.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() +inline Try<std::array<int_fd, 2>> pipe() { // Create inheritable pipe, as described in MSDN[1]. // @@ -39,11 +41,11 @@ inline Try<std::array<WindowsFD, 2>> pipe() const BOOL result = ::CreatePipe(&read_handle, &write_handle, &securityAttr, 0); - if (!result) { + if (result == FALSE) { return WindowsError(); } - return std::array<WindowsFD, 2>{read_handle, write_handle}; + return std::array<int_fd, 2>{read_handle, write_handle}; } } // namespace os { http://git-wip-us.apache.org/repos/asf/mesos/blob/ef511376/3rdparty/stout/include/stout/os/windows/read.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/read.hpp b/3rdparty/stout/include/stout/os/windows/read.hpp index 8047ad5..b5b70ad 100644 --- a/3rdparty/stout/include/stout/os/windows/read.hpp +++ b/3rdparty/stout/include/stout/os/windows/read.hpp @@ -19,13 +19,12 @@ #include <stout/unreachable.hpp> #include <stout/windows.hpp> // For order-dependent networking headers. +#include <stout/os/int_fd.hpp> #include <stout/os/socket.hpp> -#include <stout/os/windows/fd.hpp> - namespace os { -inline ssize_t read(const WindowsFD& fd, void* data, size_t size) +inline ssize_t read(const int_fd& fd, void* data, size_t size) { CHECK_LE(size, UINT_MAX); http://git-wip-us.apache.org/repos/asf/mesos/blob/ef511376/3rdparty/stout/include/stout/os/windows/sendfile.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/sendfile.hpp b/3rdparty/stout/include/stout/os/windows/sendfile.hpp index fff5872..08afb7f 100644 --- a/3rdparty/stout/include/stout/os/windows/sendfile.hpp +++ b/3rdparty/stout/include/stout/os/windows/sendfile.hpp @@ -19,7 +19,7 @@ #include <stout/try.hpp> #include <stout/windows.hpp> // For `winioctl.h`. -#include <stout/os/windows/fd.hpp> +#include <stout/os/int_fd.hpp> namespace os { @@ -27,33 +27,27 @@ namespace os { // descriptor to the output socket. // On error, `Try<ssize_t, SocketError>` contains the error. inline Try<ssize_t, SocketError> sendfile( - const WindowsFD& s, const WindowsFD& fd, off_t offset, size_t length) + const int_fd& s, const int_fd& fd, off_t offset, size_t length) { // NOTE: We convert the `offset` here to avoid potential data loss // in the type casting and bitshifting below. uint64_t offset_ = offset; OVERLAPPED from = { - 0, - 0, - {static_cast<DWORD>(offset_), static_cast<DWORD>(offset_ >> 32)}, - nullptr}; + 0, + 0, + {static_cast<DWORD>(offset_), static_cast<DWORD>(offset_ >> 32)}, + nullptr}; CHECK_LE(length, MAXDWORD); - if (TransmitFile( - s, - fd, - static_cast<DWORD>(length), - 0, - &from, - nullptr, - 0) == FALSE && - (WSAGetLastError() == WSA_IO_PENDING || - WSAGetLastError() == ERROR_IO_PENDING)) { + if (::TransmitFile(s, fd, static_cast<DWORD>(length), 0, &from, nullptr, 0) == + FALSE && + (::WSAGetLastError() == WSA_IO_PENDING || + ::WSAGetLastError() == ERROR_IO_PENDING)) { DWORD sent = 0; DWORD flags = 0; - if (WSAGetOverlappedResult(s, &from, &sent, TRUE, &flags) == TRUE) { + if (::WSAGetOverlappedResult(s, &from, &sent, TRUE, &flags) == TRUE) { return sent; } } http://git-wip-us.apache.org/repos/asf/mesos/blob/ef511376/3rdparty/stout/include/stout/os/windows/shell.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/shell.hpp b/3rdparty/stout/include/stout/os/windows/shell.hpp index aacd746..8da612a 100644 --- a/3rdparty/stout/include/stout/os/windows/shell.hpp +++ b/3rdparty/stout/include/stout/os/windows/shell.hpp @@ -30,7 +30,7 @@ #include <stout/try.hpp> #include <stout/windows.hpp> -#include <stout/os/windows/fd.hpp> +#include <stout/os/int_fd.hpp> #include <stout/internal/windows/inherit.hpp> @@ -241,7 +241,7 @@ inline Try<ProcessData> create_process( const std::vector<std::string>& argv, const Option<std::map<std::string, std::string>>& environment, const bool create_suspended = false, - const Option<std::array<os::WindowsFD, 3>> pipes = None()) + const Option<std::array<int_fd, 3>>& pipes = None()) { // TODO(andschwa): Assert that `command` and `argv[0]` are the same. const std::wstring arg_string = stringify_args(argv); @@ -277,7 +277,7 @@ inline Try<ProcessData> create_process( // [2] https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx if (pipes.isSome()) { // Each of these handles must be inheritable. - foreach (const os::WindowsFD& fd, pipes.get()) { + foreach (const int_fd& fd, pipes.get()) { const Try<Nothing> inherit = set_inherit(fd, true); if (inherit.isError()) { return Error(inherit.error()); @@ -319,7 +319,7 @@ inline Try<ProcessData> create_process( // NOTE: This is explicit, and does not take into account the // previous inheritance semantics of each `HANDLE`. It is assumed // that users of this function send non-inheritable handles. - foreach (const os::WindowsFD& fd, pipes.get()) { + foreach (const int_fd& fd, pipes.get()) { const Try<Nothing> inherit = set_inherit(fd, false); if (inherit.isError()) { return Error(inherit.error()); http://git-wip-us.apache.org/repos/asf/mesos/blob/ef511376/3rdparty/stout/include/stout/os/windows/socket.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/socket.hpp b/3rdparty/stout/include/stout/os/windows/socket.hpp index 259b05b..a05b0e2 100644 --- a/3rdparty/stout/include/stout/os/windows/socket.hpp +++ b/3rdparty/stout/include/stout/os/windows/socket.hpp @@ -22,9 +22,6 @@ #include <stout/os/int_fd.hpp> -#include <stout/os/windows/fd.hpp> - - namespace net { // Initialize Windows socket stack. @@ -132,8 +129,8 @@ inline Try<int_fd> socket( // NOTE: The below wrappers are used to silence some implicit // type-casting warnings. -inline os::WindowsFD accept( - const os::WindowsFD& fd, sockaddr* addr, socklen_t* addrlen) +inline int_fd accept( + const int_fd& fd, sockaddr* addr, socklen_t* addrlen) { return ::accept(fd, addr, reinterpret_cast<int*>(addrlen)); } @@ -144,7 +141,7 @@ inline os::WindowsFD accept( // on POSIX will also work on Windows. inline int bind( - const os::WindowsFD& fd, const sockaddr* addr, socklen_t addrlen) + const int_fd& fd, const sockaddr* addr, socklen_t addrlen) { CHECK_LE(addrlen, INT32_MAX); return ::bind(fd, addr, static_cast<int>(addrlen)); @@ -152,7 +149,7 @@ inline int bind( inline int connect( - const os::WindowsFD& fd, const sockaddr* address, socklen_t addrlen) + const int_fd& fd, const sockaddr* address, socklen_t addrlen) { CHECK_LE(addrlen, INT32_MAX); return ::connect(fd, address, static_cast<int>(addrlen)); @@ -160,7 +157,7 @@ inline int connect( inline ssize_t send( - const os::WindowsFD& fd, const void* buf, size_t len, int flags) + const int_fd& fd, const void* buf, size_t len, int flags) { CHECK_LE(len, INT32_MAX); return ::send( @@ -168,7 +165,7 @@ inline ssize_t send( } -inline ssize_t recv(const os::WindowsFD& fd, void* buf, size_t len, int flags) +inline ssize_t recv(const int_fd& fd, void* buf, size_t len, int flags) { CHECK_LE(len, INT32_MAX); return ::recv(fd, static_cast<char*>(buf), static_cast<int>(len), flags); http://git-wip-us.apache.org/repos/asf/mesos/blob/ef511376/3rdparty/stout/include/stout/os/windows/write.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/os/windows/write.hpp b/3rdparty/stout/include/stout/os/windows/write.hpp index 7100648..57660a3 100644 --- a/3rdparty/stout/include/stout/os/windows/write.hpp +++ b/3rdparty/stout/include/stout/os/windows/write.hpp @@ -20,13 +20,12 @@ #include <stout/unreachable.hpp> #include <stout/windows.hpp> // For order-dependent networking headers. +#include <stout/os/int_fd.hpp> #include <stout/os/socket.hpp> -#include <stout/os/windows/fd.hpp> - namespace os { -inline ssize_t write(const WindowsFD& fd, const void* data, size_t size) +inline ssize_t write(const int_fd& fd, const void* data, size_t size) { CHECK_LE(size, INT_MAX); http://git-wip-us.apache.org/repos/asf/mesos/blob/ef511376/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 900baf9..af5cb81 100644 --- a/3rdparty/stout/include/stout/windows/os.hpp +++ b/3rdparty/stout/include/stout/windows/os.hpp @@ -42,7 +42,6 @@ #include <stout/os/read.hpp> #include <stout/os/raw/environment.hpp> -#include <stout/os/windows/fd.hpp> // NOTE: These system headers must be included after `stout/windows.hpp` // as they may include `Windows.h`. See comments in `stout/windows.hpp`
