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:45 UTC

[10/12] mesos git commit: Windows: Moved `write` to its own file, `stout/os/write.hpp`.

Windows: Moved `write` to its own file, `stout/os/write.hpp`.

Review: https://reviews.apache.org/r/39207


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/de387d6a
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/de387d6a
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/de387d6a

Branch: refs/heads/master
Commit: de387d6a7bb3476d56f5c7879b137f0bb98f5667
Parents: eea81b2
Author: Alex Clemmer <cl...@gmail.com>
Authored: Sat Oct 17 17:45:36 2015 -0400
Committer: Joris Van Remoortere <jo...@gmail.com>
Committed: Sat Oct 17 20:11:13 2015 -0400

----------------------------------------------------------------------
 .../3rdparty/stout/include/Makefile.am          |  1 +
 .../3rdparty/stout/include/stout/os.hpp         | 25 +-----
 .../3rdparty/stout/include/stout/os/write.hpp   | 82 ++++++++++++++++++++
 .../3rdparty/stout/include/stout/posix/os.hpp   | 25 ------
 .../3rdparty/stout/include/stout/windows/os.hpp |  8 --
 5 files changed, 84 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/de387d6a/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 1d88c05..32fa58f 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
@@ -83,6 +83,7 @@ nobase_include_HEADERS =		\
   stout/os/permissions.hpp		\
   stout/os/pstree.hpp			\
   stout/os/sysctl.hpp			\
+  stout/os/write.hpp			\
   stout/os/windows/exists.hpp		\
   stout/os/windows/fcntl.hpp		\
   stout/os/windows/fork.hpp		\

http://git-wip-us.apache.org/repos/asf/mesos/blob/de387d6a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
index 5141c13..5cbb39c 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -88,6 +88,7 @@
 #ifdef __APPLE__
 #include <stout/os/sysctl.hpp>
 #endif // __APPLE__
+#include <stout/os/write.hpp>
 
 
 // For readability, we minimize the number of #ifdef blocks in the code by
@@ -185,30 +186,6 @@ inline Try<std::string> mktemp(const std::string& path = "/tmp/XXXXXX")
 }
 
 
-// Write out the string to the file at the current fd position.
-inline Try<Nothing> write(int fd, const std::string& message)
-{
-  size_t offset = 0;
-
-  while (offset < message.length()) {
-    ssize_t length =
-      ::write(fd, message.data() + offset, message.length() - offset);
-
-    if (length < 0) {
-      // TODO(benh): Handle a non-blocking fd? (EAGAIN, EWOULDBLOCK)
-      if (errno == EINTR) {
-        continue;
-      }
-      return ErrnoError();
-    }
-
-    offset += length;
-  }
-
-  return Nothing();
-}
-
-
 inline Result<std::string> realpath(const std::string& path)
 {
   char temp[PATH_MAX];

http://git-wip-us.apache.org/repos/asf/mesos/blob/de387d6a/3rdparty/libprocess/3rdparty/stout/include/stout/os/write.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/write.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/write.hpp
new file mode 100644
index 0000000..3d5976d
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/write.hpp
@@ -0,0 +1,82 @@
+/**
+ * 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_WRITE_HPP__
+#define __STOUT_OS_WRITE_HPP__
+
+
+#include <stout/error.hpp>
+#include <stout/nothing.hpp>
+#include <stout/try.hpp>
+
+#include <stout/os/close.hpp>
+#include <stout/os/open.hpp>
+
+#ifdef __WINDOWS__
+#include <stout/windows.hpp>
+#endif // __WINDOWS__
+
+
+namespace os {
+
+// Write out the string to the file at the current fd position.
+inline Try<Nothing> write(int fd, const std::string& message)
+{
+  size_t offset = 0;
+
+  while (offset < message.length()) {
+    ssize_t length =
+      ::write(fd, message.data() + offset, message.length() - offset);
+
+    if (length < 0) {
+      // TODO(benh): Handle a non-blocking fd? (EAGAIN, EWOULDBLOCK)
+      if (errno == EINTR) {
+        continue;
+      }
+      return ErrnoError();
+    }
+
+    offset += length;
+  }
+
+  return Nothing();
+}
+
+
+// A wrapper function that wraps the above write() with
+// open and closing the file.
+inline Try<Nothing> write(const std::string& path, const std::string& message)
+{
+  Try<int> fd = os::open(
+      path,
+      O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
+      S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+  if (fd.isError()) {
+    return ErrnoError("Failed to open file '" + path + "'");
+  }
+
+  Try<Nothing> result = write(fd.get(), message);
+
+  // We ignore the return value of close(). This is because users
+  // calling this function are interested in the return value of
+  // write(). Also an unsuccessful close() doesn't affect the write.
+  os::close(fd.get());
+
+  return result;
+}
+
+} // namespace os {
+
+
+#endif // __STOUT_OS_READ_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/de387d6a/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
index a042d06..2978595 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/posix/os.hpp
@@ -94,7 +94,6 @@ namespace os {
 
 // Forward declarations.
 inline Try<Nothing> utime(const std::string&);
-inline Try<Nothing> write(int, const std::string&);
 
 inline char** environ()
 {
@@ -165,30 +164,6 @@ inline Try<Nothing> touch(const std::string& path)
 }
 
 
-// A wrapper function that wraps the above write() with
-// open and closing the file.
-inline Try<Nothing> write(const std::string& path, const std::string& message)
-{
-  Try<int> fd = os::open(
-      path,
-      O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
-      S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
-
-  if (fd.isError()) {
-    return ErrnoError("Failed to open file '" + path + "'");
-  }
-
-  Try<Nothing> result = write(fd.get(), message);
-
-  // We ignore the return value of close(). This is because users
-  // calling this function are interested in the return value of
-  // write(). Also an unsuccessful close() doesn't affect the write.
-  os::close(fd.get());
-
-  return result;
-}
-
-
 inline Try<Nothing> rm(const std::string& path)
 {
   if (::remove(path.c_str()) != 0) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/de387d6a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
index 2b09668..6ed66a7 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/os.hpp
@@ -74,14 +74,6 @@ inline Try<Nothing> touch(const std::string& path)
 }
 
 
-// A wrapper function that wraps the above write() with
-// open and closing the file.
-inline Try<Nothing> write(const std::string& path, const std::string& message)
-{
-  UNIMPLEMENTED;
-}
-
-
 inline Try<Nothing> rm(const std::string& path)
 {
   UNIMPLEMENTED;