You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2015/02/08 16:51:29 UTC

[02/20] mesos git commit: Moved network::* functions into network.hpp.

Moved network::* functions into network.hpp.

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


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

Branch: refs/heads/master
Commit: 544411a11b39799037e2c87858d426ac70a71794
Parents: 8b48850
Author: Benjamin Hindman <be...@gmail.com>
Authored: Thu Dec 25 17:10:57 2014 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Sat Feb 7 14:42:45 2015 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/include/Makefile.am         |   1 +
 3rdparty/libprocess/include/process/network.hpp | 102 +++++++++++++++++++
 3rdparty/libprocess/include/process/socket.hpp  |  87 ----------------
 3rdparty/libprocess/src/http.cpp                |   1 +
 3rdparty/libprocess/src/poll_socket.cpp         |   1 +
 3rdparty/libprocess/src/socket.cpp              |   1 +
 3rdparty/libprocess/src/tests/process_tests.cpp |   1 +
 7 files changed, 107 insertions(+), 87 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/544411a1/3rdparty/libprocess/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/Makefile.am b/3rdparty/libprocess/include/Makefile.am
index 542ae1c..988c8d5 100644
--- a/3rdparty/libprocess/include/Makefile.am
+++ b/3rdparty/libprocess/include/Makefile.am
@@ -31,6 +31,7 @@ nobase_include_HEADERS =		\
   process/metrics/timer.hpp		\
   process/mime.hpp			\
   process/mutex.hpp			\
+  process/network.hpp			\
   process/node.hpp			\
   process/once.hpp			\
   process/owned.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/544411a1/3rdparty/libprocess/include/process/network.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/network.hpp b/3rdparty/libprocess/include/process/network.hpp
new file mode 100644
index 0000000..2ceea8c
--- /dev/null
+++ b/3rdparty/libprocess/include/process/network.hpp
@@ -0,0 +1,102 @@
+#ifndef __PROCESS_NETWORK_HPP__
+#define __PROCESS_NETWORK_HPP__
+
+#include <process/node.hpp>
+
+#include <stout/net.hpp>
+#include <stout/try.hpp>
+
+namespace process {
+namespace network {
+
+// Returns a socket file descriptor for the specified options. Note
+// that on OS X, the returned socket will have the SO_NOSIGPIPE option
+// set.
+inline Try<int> socket(int family, int type, int protocol)
+{
+  int s;
+  if ((s = ::socket(family, type, protocol)) == -1) {
+    return ErrnoError();
+  }
+
+#ifdef __APPLE__
+  // Disable SIGPIPE via setsockopt because OS X does not support
+  // the MSG_NOSIGNAL flag on send(2).
+  const int enable = 1;
+  if (setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, &enable, sizeof(int)) == -1) {
+    return ErrnoError();
+  }
+#endif // __APPLE__
+
+  return s;
+}
+
+// accept, bind, connect, getsockname wrappers for different protocol families
+inline Try<int> accept(int s, sa_family_t family)
+{
+  switch (family) {
+    case AF_INET: {
+      sockaddr_in addr = net::createSockaddrIn(0, 0);
+      socklen_t addrlen = sizeof(addr);
+
+      int accepted = ::accept(s, (sockaddr*) &addr, &addrlen);
+      if (accepted < 0) {
+        return ErrnoError("Failed to accept");
+      }
+
+      return accepted;
+    }
+    default:
+      return Error("Unsupported family type: " + stringify(family));
+  }
+}
+
+
+inline Try<int> bind(int s, const Node& node)
+{
+  sockaddr_in addr = net::createSockaddrIn(node.ip, node.port);
+
+  int error = ::bind(s, (sockaddr*) &addr, sizeof(addr));
+  if (error < 0) {
+    return ErrnoError("Failed to bind on " + stringify(node));
+  }
+
+  return error;
+}
+
+
+inline Try<int> connect(int s, const Node& node)
+{
+  sockaddr_in addr = net::createSockaddrIn(node.ip, node.port);
+
+  int error = ::connect(s, (sockaddr*) &addr, sizeof(addr));
+  if (error < 0) {
+    return ErrnoError("Failed to connect to " + stringify(node));
+  }
+
+  return error;
+}
+
+
+inline Try<Node> getsockname(int s, sa_family_t family)
+{
+  switch (family) {
+    case AF_INET: {
+      sockaddr_in addr = net::createSockaddrIn(0, 0);
+      socklen_t addrlen = sizeof(addr);
+
+      if(::getsockname(s, (sockaddr*) &addr, &addrlen) < 0) {
+        return ErrnoError("Failed to getsockname");
+      }
+
+      return Node(addr.sin_addr.s_addr, ntohs(addr.sin_port));
+    }
+    default:
+      return Error("Unsupported family type: " + stringify(family));
+  }
+}
+
+} // namespace network {
+} // namespace process {
+
+#endif // __PROCESS_NETWORK_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/544411a1/3rdparty/libprocess/include/process/socket.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/socket.hpp b/3rdparty/libprocess/include/process/socket.hpp
index ddb9e36..7e92cc8 100644
--- a/3rdparty/libprocess/include/process/socket.hpp
+++ b/3rdparty/libprocess/include/process/socket.hpp
@@ -1,8 +1,6 @@
 #ifndef __PROCESS_SOCKET_HPP__
 #define __PROCESS_SOCKET_HPP__
 
-#include <assert.h>
-
 #include <memory>
 
 #include <process/future.hpp>
@@ -14,98 +12,13 @@
 #include <stout/os.hpp>
 #include <stout/try.hpp>
 
-
 namespace process {
 namespace network {
 
-// Returns a socket fd for the specified options. Note that on OS X,
-// the returned socket will have the SO_NOSIGPIPE option set.
-inline Try<int> socket(int family, int type, int protocol)
-{
-  int s;
-  if ((s = ::socket(family, type, protocol)) == -1) {
-    return ErrnoError();
-  }
-
-#ifdef __APPLE__
-  // Disable SIGPIPE via setsockopt because OS X does not support
-  // the MSG_NOSIGNAL flag on send(2).
-  const int enable = 1;
-  if (setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, &enable, sizeof(int)) == -1) {
-    return ErrnoError();
-  }
-#endif // __APPLE__
-
-  return s;
-}
-
-// accept, bind, connect, getsockname wrappers for different protocol families
-inline Try<int> accept(int s, sa_family_t family)
-{
-  switch (family) {
-    case AF_INET: {
-      sockaddr_in addr = net::createSockaddrIn(0, 0);
-      socklen_t addrlen = sizeof(addr);
-
-      int accepted = ::accept(s, (sockaddr*) &addr, &addrlen);
-      if (accepted < 0) {
-        return ErrnoError("Failed to accept");
-      }
-
-      return accepted;
-    }
-    default:
-      return Error("Unsupported family type: " + stringify(family));
-  }
-}
-
-inline Try<int> bind(int s, const Node& node)
-{
-  sockaddr_in addr = net::createSockaddrIn(node.ip, node.port);
-
-  int error  = ::bind(s, (sockaddr*) &addr, sizeof(addr));
-  if (error < 0) {
-    return ErrnoError("Failed to bind on " + stringify(node));
-  }
-
-  return error;
-}
-
-inline Try<int> connect(int s, const Node& node)
-{
-  sockaddr_in addr = net::createSockaddrIn(node.ip, node.port);
-
-  int error = ::connect(s, (sockaddr*) &addr, sizeof(addr));
-  if (error < 0) {
-    return ErrnoError("Failed to connect to " + stringify(node));
-  }
-
-  return error;
-}
-
-inline Try<Node> getsockname(int s, sa_family_t family)
-{
-  switch (family) {
-    case AF_INET: {
-      sockaddr_in addr = net::createSockaddrIn(0, 0);
-      socklen_t addrlen = sizeof(addr);
-
-      if(::getsockname(s, (sockaddr*) &addr, &addrlen) < 0) {
-        return ErrnoError("Failed to getsockname");
-      }
-
-      return Node(addr.sin_addr.s_addr, ntohs(addr.sin_port));
-    }
-    default:
-      return Error("Unsupported family type: " + stringify(family));
-  }
-}
-
 // 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
 // references.
-
 class Socket
 {
 public:

http://git-wip-us.apache.org/repos/asf/mesos/blob/544411a1/3rdparty/libprocess/src/http.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/http.cpp b/3rdparty/libprocess/src/http.cpp
index ec9823e..5063014 100644
--- a/3rdparty/libprocess/src/http.cpp
+++ b/3rdparty/libprocess/src/http.cpp
@@ -10,6 +10,7 @@
 #include <process/future.hpp>
 #include <process/http.hpp>
 #include <process/io.hpp>
+#include <process/network.hpp>
 #include <process/socket.hpp>
 
 #include <stout/lambda.hpp>

http://git-wip-us.apache.org/repos/asf/mesos/blob/544411a1/3rdparty/libprocess/src/poll_socket.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/poll_socket.cpp b/3rdparty/libprocess/src/poll_socket.cpp
index 2e70c6c..eaeabd7 100644
--- a/3rdparty/libprocess/src/poll_socket.cpp
+++ b/3rdparty/libprocess/src/poll_socket.cpp
@@ -1,6 +1,7 @@
 #include <netinet/tcp.h>
 
 #include <process/io.hpp>
+#include <process/network.hpp>
 #include <process/socket.hpp>
 
 #include "config.hpp"

http://git-wip-us.apache.org/repos/asf/mesos/blob/544411a1/3rdparty/libprocess/src/socket.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/socket.cpp b/3rdparty/libprocess/src/socket.cpp
index 4b0f6be..df68077 100644
--- a/3rdparty/libprocess/src/socket.cpp
+++ b/3rdparty/libprocess/src/socket.cpp
@@ -1,3 +1,4 @@
+#include <process/network.hpp>
 #include <process/socket.hpp>
 
 #include "poll_socket.hpp"

http://git-wip-us.apache.org/repos/asf/mesos/blob/544411a1/3rdparty/libprocess/src/tests/process_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/process_tests.cpp b/3rdparty/libprocess/src/tests/process_tests.cpp
index a4bf28c..5580546 100644
--- a/3rdparty/libprocess/src/tests/process_tests.cpp
+++ b/3rdparty/libprocess/src/tests/process_tests.cpp
@@ -20,6 +20,7 @@
 #include <process/gc.hpp>
 #include <process/gmock.hpp>
 #include <process/gtest.hpp>
+#include <process/network.hpp>
 #include <process/process.hpp>
 #include <process/run.hpp>
 #include <process/socket.hpp>