You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2016/03/24 10:27:08 UTC
[10/11] mesos git commit: Stout: Added implementation of `read` that
works on Windows.
Stout: Added implementation of `read` that works on Windows.
Review: https://reviews.apache.org/r/44748/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/8fd56e77
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/8fd56e77
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/8fd56e77
Branch: refs/heads/master
Commit: 8fd56e77924c109d42bbad7600901f9756f18467
Parents: 98b4f82
Author: Alex Clemmer <cl...@gmail.com>
Authored: Thu Mar 24 09:33:24 2016 +0100
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Thu Mar 24 10:26:50 2016 +0100
----------------------------------------------------------------------
.../3rdparty/stout/include/Makefile.am | 2 ++
.../stout/include/stout/os/posix/read.hpp | 29 ++++++++++++++++
.../3rdparty/stout/include/stout/os/read.hpp | 19 ++++++++---
.../stout/include/stout/os/windows/read.hpp | 36 ++++++++++++++++++++
4 files changed, 82 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/8fd56e77/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
index 96ecdd6..5c9ec52 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
@@ -109,6 +109,7 @@ nobase_include_HEADERS = \
stout/os/posix/killtree.hpp \
stout/os/posix/mkdtemp.hpp \
stout/os/posix/pstree.hpp \
+ stout/os/posix/read.hpp \
stout/os/posix/rmdir.hpp \
stout/os/posix/sendfile.hpp \
stout/os/posix/shell.hpp \
@@ -127,6 +128,7 @@ nobase_include_HEADERS = \
stout/os/windows/killtree.hpp \
stout/os/windows/mkdtemp.hpp \
stout/os/windows/pstree.hpp \
+ stout/os/windows/read.hpp \
stout/os/windows/rmdir.hpp \
stout/os/windows/sendfile.hpp \
stout/os/windows/shell.hpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/8fd56e77/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/read.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/read.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/read.hpp
new file mode 100644
index 0000000..b6185de
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/read.hpp
@@ -0,0 +1,29 @@
+// 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_READ_HPP__
+#define __STOUT_OS_POSIX_READ_HPP__
+
+#include <errno.h>
+#include <unistd.h>
+
+
+namespace os {
+
+// Compatibility function. On POSIX, this function is trivial, but on Windows,
+// we have to check whether the file descriptor is a socket or a file to read
+// from it.
+using ::read;
+
+} // namespace os {
+
+#endif // __STOUT_OS_POSIX_READ_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/8fd56e77/3rdparty/libprocess/3rdparty/stout/include/stout/os/read.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/read.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/read.hpp
index d494cbf..e1e97c1 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/read.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/read.hpp
@@ -13,7 +13,6 @@
#ifndef __STOUT_OS_READ_HPP__
#define __STOUT_OS_READ_HPP__
-
#include <stdio.h>
#ifndef __WINDOWS__
#include <unistd.h>
@@ -28,11 +27,17 @@
#include <stout/error.hpp>
#include <stout/result.hpp>
#include <stout/try.hpp>
-
#ifdef __WINDOWS__
#include <stout/windows.hpp>
#endif // __WINDOWS__
+#include <stout/os/socket.hpp>
+#ifdef __WINDOWS__
+#include <stout/os/windows/read.hpp>
+#else
+#include <stout/os/posix/read.hpp>
+#endif // __WINDOWS__
+
namespace os {
@@ -45,11 +50,17 @@ inline Result<std::string> read(int fd, size_t size)
size_t offset = 0;
while (offset < size) {
- ssize_t length = ::read(fd, buffer + offset, size - offset);
+ ssize_t length = os::read(fd, buffer + offset, size - offset);
+
+#ifdef __WINDOWS__
+ int error = WSAGetLastError();
+#else
+ int error = errno;
+#endif // __WINDOWS__
if (length < 0) {
// TODO(bmahler): Handle a non-blocking fd? (EAGAIN, EWOULDBLOCK)
- if (errno == EINTR) {
+ if (net::is_restartable_error(error)) {
continue;
}
ErrnoError error; // Constructed before 'delete' to capture errno.
http://git-wip-us.apache.org/repos/asf/mesos/blob/8fd56e77/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/read.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/read.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/read.hpp
new file mode 100644
index 0000000..a10df73
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/read.hpp
@@ -0,0 +1,36 @@
+// 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_READ_HPP__
+#define __STOUT_OS_WINDOWS_READ_HPP__
+
+#include <io.h>
+
+#include <stout/windows.hpp> // For order-dependent networking headers.
+
+#include <stout/os/socket.hpp>
+
+
+namespace os {
+
+inline ssize_t read(int fd, void* data, size_t size)
+{
+ if (net::is_socket(fd)) {
+ return ::recv(fd, (char*) data, size, 0);
+ }
+
+ return ::_read(fd, data, size);
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_WINDOWS_READ_HPP__