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 2016/04/26 00:18:34 UTC
[4/4] mesos git commit: Windows: Implemented `sendfile` in stout.
Windows: Implemented `sendfile` in stout.
Review: https://reviews.apache.org/r/43985/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/add43d3c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/add43d3c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/add43d3c
Branch: refs/heads/master
Commit: add43d3c7df0acbbb262de35a1eadb3febf855ca
Parents: a5c81d4
Author: Daniel Pravat <dp...@outlook.com>
Authored: Thu Apr 21 22:55:09 2016 -0700
Committer: Michael Park <mp...@apache.org>
Committed: Mon Apr 25 14:34:16 2016 -0700
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/error.hpp | 7 ++++
.../stout/include/stout/os/posix/sendfile.hpp | 21 +++++++----
.../stout/include/stout/os/windows/sendfile.hpp | 37 +++++++++++++++-----
.../3rdparty/stout/include/stout/windows.hpp | 1 +
4 files changed, 52 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/add43d3c/3rdparty/libprocess/3rdparty/stout/include/stout/error.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/error.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/error.hpp
index cd1bad1..3f4e4b1 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/error.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/error.hpp
@@ -26,4 +26,11 @@
#include <stout/windows/error.hpp>
#endif // __WINDOWS__
+using SocketError =
+#ifdef __WINDOWS_
+ WindowsSocketError;
+#else
+ ErrnoError;
+#endif // __WINDOWS__
+
#endif // __STOUT_ERROR_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/add43d3c/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/sendfile.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/sendfile.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/sendfile.hpp
index 293f82f..c2806fa 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/sendfile.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/sendfile.hpp
@@ -27,21 +27,30 @@
#include <stout/os/signals.hpp>
#include <stout/unreachable.hpp>
+#include <stout/error.hpp>
+#include <stout/try.hpp>
+
namespace os {
// Returns the amount of bytes written from the input file
-// descriptor to the output socket. On error, returns -1 and
-// errno indicates the error.
+// descriptor to the output socket. On error,
+// `Try<ssize_t, SocketError>` contains the error.
// NOTE: The following limitations exist because of the OS X
// implementation of sendfile:
// 1. s must be a stream oriented socket descriptor.
// 2. fd must be a regular file descriptor.
-inline ssize_t sendfile(int s, int fd, off_t offset, size_t length)
+inline Try<ssize_t, SocketError> sendfile(
+ int s, int fd, off_t offset, size_t length)
{
#if defined(__linux__) || defined(__sun)
SUPPRESS (SIGPIPE) {
// This will set errno to EPIPE if a SIGPIPE occurs.
- return ::sendfile(s, fd, &offset, length);
+ ssize_t sent = ::sendfile(s, fd, &offset, length);
+ if (sent < 0) {
+ return SocketError();
+ }
+
+ return sent;
}
UNREACHABLE();
#elif defined __APPLE__
@@ -52,7 +61,7 @@ inline ssize_t sendfile(int s, int fd, off_t offset, size_t length)
if (errno == EAGAIN && _length > 0) {
return _length;
}
- return -1;
+ return SocketError();
}
return _length;
@@ -64,7 +73,7 @@ inline ssize_t sendfile(int s, int fd, off_t offset, size_t length)
if (errno == EAGAIN && length > 0) {
return _length;
}
- return -1;
+ return SocketError();
}
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/add43d3c/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/sendfile.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/sendfile.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/sendfile.hpp
index 750ca67..7b2a724 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/sendfile.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/sendfile.hpp
@@ -15,19 +15,40 @@
#include <errno.h>
+#include <stout/error.hpp>
+#include <stout/try.hpp>
+#include <stout/windows.hpp>
namespace os {
// Returns the amount of bytes written from the input file
-// descriptor to the output socket. On error, returns -1 and
-// errno indicates the error.
-// NOTE: The following limitations exist because of the OS X
-// implementation of sendfile:
-// 1. s must be a stream oriented socket descriptor.
-// 2. fd must be a regular file descriptor.
-inline ssize_t sendfile(int s, int fd, off_t offset, size_t length)
+// descriptor to the output socket.
+// On error, `Try<ssize_t, SocketError>` contains the error.
+inline Try<ssize_t, SocketError> sendfile(
+ int s, int fd, off_t offset, size_t length)
{
- UNIMPLEMENTED;
+ // NOTE: It is not necessary to close the `HANDLE`; when we call `_close` on
+ // `fd` it will close the underlying `HANDLE` as well.
+ HANDLE file = reinterpret_cast<HANDLE>(_get_osfhandle(fd));
+
+ OVERLAPPED from = {
+ 0,
+ 0,
+ {static_cast<DWORD>(offset), static_cast<DWORD>(offset >> 32)},
+ NULL};
+
+ if (TransmitFile(s, file, length, 0, &from, NULL, 0) == FALSE &&
+ (WSAGetLastError() == WSA_IO_PENDING ||
+ WSAGetLastError() == ERROR_IO_PENDING)) {
+ DWORD sent = 0;
+ DWORD flags = 0;
+
+ if (WSAGetOverlappedResult(s, &from, &sent, TRUE, &flags) == TRUE) {
+ return sent;
+ }
+ }
+
+ return SocketError();
}
} // namespace os {
http://git-wip-us.apache.org/repos/asf/mesos/blob/add43d3c/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
index c2d1dc1..a7a59e7 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
@@ -26,6 +26,7 @@
// re-definitions. This is a known pattern in the windows community.
#include <WS2tcpip.h>
#include <Winsock2.h>
+#include <mswsock.h>
#include <Windows.h>
#include <memory>