[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mesos-commits
Subject:    svn commit: r1367755 - in /incubator/mesos/trunk: src/tests/stout_tests.cpp third_party/libprocess/i
From:       benh () apache ! org
Date:       2012-07-31 20:27:12
Message-ID: 20120731202712.63C9223889DA () eris ! apache ! org
[Download RAW message or body]

Author: benh
Date: Tue Jul 31 20:27:11 2012
New Revision: 1367755

URL: http://svn.apache.org/viewvc?rev=1367755&view=rev
Log:
Add os::nonblock utility functions to set/check O_NONBLOCK flag for
file descriptors (contributed by Jie Yu,
https://reviews.apache.org/r/6217).

Modified:
    incubator/mesos/trunk/src/tests/stout_tests.cpp
    incubator/mesos/trunk/third_party/libprocess/include/stout/os.hpp

Modified: incubator/mesos/trunk/src/tests/stout_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/stout_tests.cpp?rev=1367755&r1=1367754&r2=1367755&view=diff
 ==============================================================================
--- incubator/mesos/trunk/src/tests/stout_tests.cpp (original)
+++ incubator/mesos/trunk/src/tests/stout_tests.cpp Tue Jul 31 20:27:11 2012
@@ -239,6 +239,36 @@ TEST_F(StoutUtilsTest, rmdir)
 }
 
 
+TEST_F(StoutUtilsTest, nonblock)
+{
+  int pipes[2];
+  ASSERT_NE(-1, pipe(pipes));
+
+  Try<bool> result = false;
+
+  result = os::isNonblock(pipes[0]);
+  ASSERT_TRUE(result.isSome());
+  EXPECT_FALSE(result.get());
+
+  result = os::nonblock(pipes[0]);
+  ASSERT_TRUE(result.isSome());
+  EXPECT_TRUE(result.get());
+
+  result = os::isNonblock(pipes[0]);
+  ASSERT_TRUE(result.isSome());
+  EXPECT_TRUE(result.get());
+
+  close(pipes[0]);
+  close(pipes[1]);
+
+  result = os::nonblock(pipes[0]);
+  EXPECT_TRUE(result.isError());
+
+  result = os::isNonblock(pipes[0]);
+  EXPECT_TRUE(result.isError());
+}
+
+
 TEST_F(StoutUtilsTest, touch)
 {
   const std::string& testfile  = tmpdir + "/" + UUID::random().toString();

Modified: incubator/mesos/trunk/third_party/libprocess/include/stout/os.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/third_party/libprocess/include/stout/os.hpp?rev=1367755&r1=1367754&r2=1367755&view=diff
 ==============================================================================
--- incubator/mesos/trunk/third_party/libprocess/include/stout/os.hpp (original)
+++ incubator/mesos/trunk/third_party/libprocess/include/stout/os.hpp Tue Jul 31 \
20:27:11 2012 @@ -119,6 +119,34 @@ inline Try<bool> cloexec(int fd)
 }
 
 
+inline Try<bool> nonblock(int fd)
+{
+  int flags = ::fcntl(fd, F_GETFL);
+
+  if (flags == -1) {
+    return Try<bool>::error(strerror(errno));
+  }
+
+  if (::fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
+    return Try<bool>::error(strerror(errno));
+  }
+
+  return true;
+}
+
+
+inline Try<bool> isNonblock(int fd)
+{
+  int flags = ::fcntl(fd, F_GETFL);
+
+  if (flags == -1) {
+    return Try<bool>::error(strerror(errno));
+  }
+
+  return (flags & O_NONBLOCK) != 0;
+}
+
+
 inline Try<bool> touch(const std::string& path)
 {
   Try<int> fd = open(path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IRWXO);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic