You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2013/05/15 23:13:44 UTC

[2/2] git commit: Fixed libprocess to pipe all close()s through os::close().

Fixed libprocess to pipe all close()s through os::close().

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


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

Branch: refs/heads/master
Commit: dcdc88b272589ab51e82e1a285059d1302325c05
Parents: 8ecb6ed
Author: Vinod Kone <vi...@twitter.com>
Authored: Wed May 15 11:51:45 2013 -0700
Committer: Vinod Kone <vi...@twitter.com>
Committed: Wed May 15 14:13:26 2013 -0700

----------------------------------------------------------------------
 third_party/libprocess/include/process/socket.hpp |   11 +++++++++--
 third_party/libprocess/src/encoder.hpp            |    4 ++--
 third_party/libprocess/src/httpd.cpp              |    6 ++++--
 third_party/libprocess/src/net.hpp                |    4 +++-
 third_party/libprocess/src/process.cpp            |   12 ++++++------
 5 files changed, 24 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/dcdc88b2/third_party/libprocess/include/process/socket.hpp
----------------------------------------------------------------------
diff --git a/third_party/libprocess/include/process/socket.hpp b/third_party/libprocess/include/process/socket.hpp
index f466963..669a333 100644
--- a/third_party/libprocess/include/process/socket.hpp
+++ b/third_party/libprocess/include/process/socket.hpp
@@ -4,6 +4,12 @@
 #include <assert.h>
 #include <unistd.h> // For close.
 
+#include <iostream>
+
+#include <stout/nothing.hpp>
+#include <stout/os.hpp>
+#include <stout/try.hpp>
+
 // An abstraction around a socket (file descriptor) that provides
 // reference counting such that the socket is only closed (and thus,
 // has the possiblity of being reused) after there are no more
@@ -62,8 +68,9 @@ private:
     if (__sync_sub_and_fetch(refs, 1) == 0) {
       delete refs;
       if (s >= 0) {
-        if (close(s) != 0) {
-          perror("Failed to close socket");
+        Try<Nothing> close = os::close(s);
+        if (close.isError()) {
+          std::cerr << "Failed to close socket: " << close.error() << std::endl;
           abort();
         }
       }

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/dcdc88b2/third_party/libprocess/src/encoder.hpp
----------------------------------------------------------------------
diff --git a/third_party/libprocess/src/encoder.hpp b/third_party/libprocess/src/encoder.hpp
index 12b3ffa..ec5e271 100644
--- a/third_party/libprocess/src/encoder.hpp
+++ b/third_party/libprocess/src/encoder.hpp
@@ -13,7 +13,7 @@
 #include <stout/gzip.hpp>
 #include <stout/hashmap.hpp>
 #include <stout/numify.hpp>
-
+#include <stout/os.hpp>
 
 namespace process {
 
@@ -218,7 +218,7 @@ public:
 
   virtual ~FileEncoder()
   {
-    close(fd);
+    os::close(fd);
   }
 
   virtual Sender sender()

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/dcdc88b2/third_party/libprocess/src/httpd.cpp
----------------------------------------------------------------------
diff --git a/third_party/libprocess/src/httpd.cpp b/third_party/libprocess/src/httpd.cpp
index 49bcece..793a5b0 100644
--- a/third_party/libprocess/src/httpd.cpp
+++ b/third_party/libprocess/src/httpd.cpp
@@ -14,6 +14,8 @@
 
 #include <arpa/inet.h>
 
+#include <stout/os.hpp>
+
 #include "net.hpp"
 
 #include "http-parser/http_parser.h"
@@ -145,7 +147,7 @@ protected:
 
       if (fstat(fd, &fd_stat) < 0) {
 	send(HTTP_500, strlen(HTTP_500));
-	close(fd);
+	os::close(fd);
 	return;
       }
 
@@ -184,7 +186,7 @@ protected:
 
       //cout << ht_id() << ": running " << this << " connection (4)" << endl;
 
-      close(fd);
+      os::close(fd);
 
       break;
     }

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/dcdc88b2/third_party/libprocess/src/net.hpp
----------------------------------------------------------------------
diff --git a/third_party/libprocess/src/net.hpp b/third_party/libprocess/src/net.hpp
index 8359526..2fdc62a 100644
--- a/third_party/libprocess/src/net.hpp
+++ b/third_party/libprocess/src/net.hpp
@@ -20,6 +20,8 @@
 #include <stdexcept>
 #include <iostream>
 
+#include <stout/os.hpp>
+
 typedef enum Protocol { TCP = SOCK_STREAM, UDP = SOCK_DGRAM } Protocol;
 
 using std::runtime_error;
@@ -155,7 +157,7 @@ public:
 	 fcntl(s, F_SETFL, flags | O_NONBLOCK) < 0))
 	throw runtime_error(string("ioctl/fcntl: ") += strerror(errno));
   }
-  ~SocketProcess() { ::close(s); }
+  ~SocketProcess() { os::close(s); }
 };
 
 

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/dcdc88b2/third_party/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/third_party/libprocess/src/process.cpp b/third_party/libprocess/src/process.cpp
index 197611f..edcb684 100644
--- a/third_party/libprocess/src/process.cpp
+++ b/third_party/libprocess/src/process.cpp
@@ -1097,7 +1097,7 @@ void accept(struct ev_loop* loop, ev_io* watcher, int revents)
   if (nonblock.isError()) {
     LOG_IF(INFO, VLOG_IS_ON(1)) << "Failed to accept, nonblock: "
                                 << nonblock.error();
-    close(s);
+    os::close(s);
     return;
   }
 
@@ -1105,7 +1105,7 @@ void accept(struct ev_loop* loop, ev_io* watcher, int revents)
   if (cloexec.isError()) {
     LOG_IF(INFO, VLOG_IS_ON(1)) << "Failed to accept, cloexec: "
                                 << cloexec.error();
-    close(s);
+    os::close(s);
     return;
   }
 
@@ -1114,7 +1114,7 @@ void accept(struct ev_loop* loop, ev_io* watcher, int revents)
   if (setsockopt(s, SOL_TCP, TCP_NODELAY, &on, sizeof(on)) < 0) {
     const char* error = strerror(errno);
     VLOG(1) << "Failed to turn off the Nagle algorithm: " << error;
-    close(s);
+    os::close(s);
   } else {
     // Inform the socket manager for proper bookkeeping.
     const Socket& socket = socket_manager->accepted(s);
@@ -1437,7 +1437,7 @@ HttpProxy::~HttpProxy()
   // Need to make sure response producers know not to continue to
   // create a response (streaming or otherwise).
   if (pipe.isSome()) {
-    close(pipe.get());
+    os::close(pipe.get());
   }
   pipe = None();
 
@@ -1451,7 +1451,7 @@ HttpProxy::~HttpProxy()
     if (item->future->isReady()) {
       const Response& response = item->future->get();
       if (response.type == Response::PIPE) {
-        close(response.pipe);
+        os::close(response.pipe);
       }
     }
 
@@ -1667,7 +1667,7 @@ void HttpProxy::stream(const Future<short>& poll, const Request& request)
   }
 
   if (finished) {
-    close(pipe.get());
+    os::close(pipe.get());
     pipe = None();
     next();
   }