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 2015/10/18 02:11:43 UTC
[08/12] mesos git commit: Windows: Added support for
`stout/os/read.hpp`.
Windows: Added support for `stout/os/read.hpp`.
Review: https://reviews.apache.org/r/39204
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/eea81b29
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/eea81b29
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/eea81b29
Branch: refs/heads/master
Commit: eea81b29f423611091fcc7435446ea1d8668ac46
Parents: 36786db
Author: Alex Clemmer <cl...@gmail.com>
Authored: Sat Oct 17 17:41:51 2015 -0400
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Sat Oct 17 20:11:13 2015 -0400
----------------------------------------------------------------------
.../3rdparty/stout/include/Makefile.am | 2 -
.../stout/include/stout/os/posix/read.hpp | 129 -------------------
.../3rdparty/stout/include/stout/os/read.hpp | 120 ++++++++++++++++-
.../stout/include/stout/os/windows/read.hpp | 44 -------
.../3rdparty/stout/include/stout/windows.hpp | 3 +
5 files changed, 118 insertions(+), 180 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/eea81b29/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 02738b0..1d88c05 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
@@ -65,7 +65,6 @@ nobase_include_HEADERS = \
stout/os/posix/ls.hpp \
stout/os/posix/process.hpp \
stout/os/posix/pstree.hpp \
- stout/os/posix/read.hpp \
stout/os/posix/sendfile.hpp \
stout/os/posix/shell.hpp \
stout/os/posix/signals.hpp \
@@ -91,7 +90,6 @@ nobase_include_HEADERS = \
stout/os/windows/ls.hpp \
stout/os/windows/process.hpp \
stout/os/windows/pstree.hpp \
- stout/os/windows/read.hpp \
stout/os/windows/sendfile.hpp \
stout/os/windows/shell.hpp \
stout/os/windows/signals.hpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/eea81b29/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
deleted file mode 100644
index ffacce1..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/posix/read.hpp
+++ /dev/null
@@ -1,129 +0,0 @@
-/**
- * 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 <stdio.h>
-#include <unistd.h>
-
-#include <string>
-
-#ifdef __sun
-#include <fstream>
-#endif // __sun
-
-#include <stout/error.hpp>
-#include <stout/result.hpp>
-#include <stout/try.hpp>
-
-
-namespace os {
-
-// Reads 'size' bytes from a file from its current offset.
-// If EOF is encountered before reading 'size' bytes then the result
-// will contain the bytes read and a subsequent read will return None.
-inline Result<std::string> read(int fd, size_t size)
-{
- char* buffer = new char[size];
- size_t offset = 0;
-
- while (offset < size) {
- ssize_t length = ::read(fd, buffer + offset, size - offset);
-
- if (length < 0) {
- // TODO(bmahler): Handle a non-blocking fd? (EAGAIN, EWOULDBLOCK)
- if (errno == EINTR) {
- continue;
- }
- ErrnoError error; // Constructed before 'delete' to capture errno.
- delete[] buffer;
- return error;
- } else if (length == 0) {
- // Reached EOF before expected! Only return as much data as
- // available or None if we haven't read anything yet.
- if (offset > 0) {
- std::string result(buffer, offset);
- delete[] buffer;
- return result;
- }
- delete[] buffer;
- return None();
- }
-
- offset += length;
- }
-
- std::string result(buffer, size);
- delete[] buffer;
- return result;
-}
-
-
-// Returns the contents of the file.
-#ifdef __sun // getline is not available on Solaris, using STL.
-inline Try<std::string> read(const std::string& path)
-{
- std::ifstream file(path.c_str());
- if (!file.is_open()) {
- // Does ifstream actually set errno?
- return ErrnoError("Failed to open file '" + path + "'");
- }
- return std::string((std::istreambuf_iterator<char>(file)),
- (std::istreambuf_iterator<char>()));
-}
-#else
-inline Try<std::string> read(const std::string& path)
-{
- FILE* file = fopen(path.c_str(), "r");
- if (file == NULL) {
- return ErrnoError("Failed to open file '" + path + "'");
- }
-
- // Initially the 'line' is NULL and length 0, getline() allocates
- // ('malloc') a buffer for reading the line.
- // In subsequent iterations, if the buffer is not large enough to
- // hold the line, getline() resizes it with 'realloc' and updates
- // 'line' and 'length' as necessary. See:
- // - http://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html
- // - http://man7.org/linux/man-pages/man3/getline.3.html
- std::string result;
- char* line = NULL;
- size_t length = 0;
- ssize_t read;
-
- while ((read = getline(&line, &length, file)) != -1) {
- result.append(line, read);
- }
-
- // getline() requires the line buffer to be freed by the caller.
- free(line);
-
- if (ferror(file)) {
- ErrnoError error;
- // NOTE: We ignore the error from fclose(). This is because
- // users calling this function are interested in the return value
- // of read(). Also an unsuccessful fclose() does not affect the
- // read.
- fclose(file);
- return error;
- }
-
- fclose(file);
- return result;
-}
-#endif // __sun
-
-} // namespace os {
-
-#endif // __STOUT_OS_POSIX_READ_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/eea81b29/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 d5698a5..ed0dbd3 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/read.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/read.hpp
@@ -15,13 +15,123 @@
#define __STOUT_OS_READ_HPP__
-// For readability, we minimize the number of #ifdef blocks in the code by
-// splitting platform specifc system calls into separate directories.
+#include <stdio.h>
+#ifndef __WINDOWS__
+#include <unistd.h>
+#endif // __WINDOWS__
+
+#include <string>
+
+#if defined(__sun) || defined(__WINDOWS__)
+#include <fstream>
+#endif // __sun || __WINDOWS__
+
+#include <stout/error.hpp>
+#include <stout/result.hpp>
+#include <stout/try.hpp>
+
#ifdef __WINDOWS__
-#include <stout/os/windows/read.hpp>
-#else
-#include <stout/os/posix/read.hpp>
+#include <stout/windows.hpp>
#endif // __WINDOWS__
+namespace os {
+
+// Reads 'size' bytes from a file from its current offset.
+// If EOF is encountered before reading 'size' bytes then the result
+// will contain the bytes read and a subsequent read will return None.
+inline Result<std::string> read(int fd, size_t size)
+{
+ char* buffer = new char[size];
+ size_t offset = 0;
+
+ while (offset < size) {
+ ssize_t length = ::read(fd, buffer + offset, size - offset);
+
+ if (length < 0) {
+ // TODO(bmahler): Handle a non-blocking fd? (EAGAIN, EWOULDBLOCK)
+ if (errno == EINTR) {
+ continue;
+ }
+ ErrnoError error; // Constructed before 'delete' to capture errno.
+ delete[] buffer;
+ return error;
+ } else if (length == 0) {
+ // Reached EOF before expected! Only return as much data as
+ // available or None if we haven't read anything yet.
+ if (offset > 0) {
+ std::string result(buffer, offset);
+ delete[] buffer;
+ return result;
+ }
+ delete[] buffer;
+ return None();
+ }
+
+ offset += length;
+ }
+
+ std::string result(buffer, size);
+ delete[] buffer;
+ return result;
+}
+
+
+// Returns the contents of the file. NOTE: getline is not available on Solaris
+// or Windows, so we use STL.
+#if defined(__sun) || defined(__WINDOWS__)
+inline Try<std::string> read(const std::string& path)
+{
+ std::ifstream file(path.c_str());
+ if (!file.is_open()) {
+ // Does ifstream actually set errno?
+ return ErrnoError("Failed to open file '" + path + "'");
+ }
+ return std::string((std::istreambuf_iterator<char>(file)),
+ (std::istreambuf_iterator<char>()));
+}
+#else
+inline Try<std::string> read(const std::string& path)
+{
+ FILE* file = fopen(path.c_str(), "r");
+ if (file == NULL) {
+ return ErrnoError("Failed to open file '" + path + "'");
+ }
+
+ // Initially the 'line' is NULL and length 0, getline() allocates
+ // ('malloc') a buffer for reading the line.
+ // In subsequent iterations, if the buffer is not large enough to
+ // hold the line, getline() resizes it with 'realloc' and updates
+ // 'line' and 'length' as necessary. See:
+ // - http://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html
+ // - http://man7.org/linux/man-pages/man3/getline.3.html
+ std::string result;
+ char* line = NULL;
+ size_t length = 0;
+ ssize_t read;
+
+ while ((read = getline(&line, &length, file)) != -1) {
+ result.append(line, read);
+ }
+
+ // getline() requires the line buffer to be freed by the caller.
+ free(line);
+
+ if (ferror(file)) {
+ ErrnoError error;
+ // NOTE: We ignore the error from fclose(). This is because
+ // users calling this function are interested in the return value
+ // of read(). Also an unsuccessful fclose() does not affect the
+ // read.
+ fclose(file);
+ return error;
+ }
+
+ fclose(file);
+ return result;
+}
+#endif // __sun || __WINDOWS__
+
+} // namespace os {
+
#endif // __STOUT_OS_READ_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/eea81b29/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
deleted file mode 100644
index 09d6332..0000000
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/windows/read.hpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * 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 <stdio.h>
-
-#include <string>
-
-#include <stout/result.hpp>
-#include <stout/try.hpp>
-
-
-namespace os {
-
-// Reads 'size' bytes from a file from its current offset.
-// If EOF is encountered before reading 'size' bytes then the result
-// will contain the bytes read and a subsequent read will return None.
-inline Result<std::string> read(int fd, size_t size)
-{
- UNIMPLEMENTED;
-}
-
-
-// Returns the contents of the file.
-inline Try<std::string> read(const std::string& path)
-{
- UNIMPLEMENTED;
-}
-
-} // namespace os {
-
-#endif // __STOUT_OS_WINDOWS_READ_HPP__
http://git-wip-us.apache.org/repos/asf/mesos/blob/eea81b29/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 2d02d35..4a0761f 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows.hpp
@@ -19,6 +19,7 @@
#include <fcntl.h> // For file access flags like `_O_CREAT`.
#include <io.h> // For `_read`, `_write`.
+#include <BaseTsd.h> // For `SSIZE_T`.
// We include `Winsock2.h` before `Windows.h` explicitly to avoid symbold
// re-definitions. This is a known pattern in the windows community.
#include <Winsock2.h>
@@ -74,6 +75,8 @@ typedef int mode_t;
// including functions like `OpenProcess`.
typedef DWORD pid_t;
+typedef SSIZE_T ssize_t;
+
// File I/O function aliases.
//
// NOTE: The use of `auto` and the trailing return type in the following