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 2016/11/29 21:29:44 UTC

[11/14] mesos git commit: Added support for http::connect to take an network::Address.

Added support for http::connect to take an network::Address.

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


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

Branch: refs/heads/master
Commit: 9a4b5e62486e9b1b0ee8913f8b1ae83b165ad333
Parents: 448b860
Author: Benjamin Hindman <be...@gmail.com>
Authored: Sun Nov 27 13:58:08 2016 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Tue Nov 29 12:15:20 2016 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/http.hpp | 10 +++++-
 3rdparty/libprocess/src/http.cpp             | 37 +++++++++++++++++------
 2 files changed, 37 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/9a4b5e62/3rdparty/libprocess/include/process/http.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/http.hpp b/3rdparty/libprocess/include/process/http.hpp
index 08a8390..7894b31 100644
--- a/3rdparty/libprocess/include/process/http.hpp
+++ b/3rdparty/libprocess/include/process/http.hpp
@@ -849,7 +849,8 @@ public:
   bool operator!=(const Connection& c) const { return !(*this == c); }
 
 private:
-  Connection(const network::inet::Socket& s);
+  Connection(const network::Socket& s);
+  friend Future<Connection> connect(const network::Address& address);
   friend Future<Connection> connect(const URL&);
 
   // Forward declaration.
@@ -859,6 +860,13 @@ private:
 };
 
 
+// TODO(benh): Currently we don't support SSL for this version of
+// connect. We should support this, perhaps with an enum or a bool and
+// then update the `connect(URL)` variant to just call this function
+// instead.
+Future<Connection> connect(const network::Address& address);
+
+
 Future<Connection> connect(const URL& url);
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/9a4b5e62/3rdparty/libprocess/src/http.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/http.cpp b/3rdparty/libprocess/src/http.cpp
index 1f2de9d..03512c6 100644
--- a/3rdparty/libprocess/src/http.cpp
+++ b/3rdparty/libprocess/src/http.cpp
@@ -1024,7 +1024,7 @@ Future<Response> convert(const Response& pipeResponse)
 class ConnectionProcess : public Process<ConnectionProcess>
 {
 public:
-  ConnectionProcess(const Socket& _socket)
+  ConnectionProcess(const network::Socket& _socket)
     : ProcessBase(ID::generate("__http_connection__")),
       socket(_socket),
       sendChain(Nothing()),
@@ -1061,7 +1061,7 @@ public:
 
     // We must chain the calls to Socket::send as it
     // otherwise interleaves data across calls.
-    Socket socket_ = socket;
+    network::Socket socket_ = socket;
 
     sendChain = sendChain
       .then([socket_, request]() {
@@ -1124,7 +1124,7 @@ protected:
   }
 
 private:
-  static Future<Nothing> _send(Socket socket, Pipe::Reader reader)
+  static Future<Nothing> _send(network::Socket socket, Pipe::Reader reader)
   {
     return reader.read()
       .then([socket, reader](const string& data) mutable -> Future<Nothing> {
@@ -1233,7 +1233,7 @@ private:
     read();
   }
 
-  Socket socket;
+  network::Socket socket;
   StreamingResponseDecoder decoder;
   Future<Nothing> sendChain;
   Promise<Nothing> disconnection;
@@ -1262,7 +1262,7 @@ struct Connection::Data
   // on within a different execution context. More generally,
   // we should be passing Process ownership to libprocess to
   // ensure all interaction with a Process occurs through a PID.
-  Data(const Socket& s)
+  Data(const network::Socket& s)
     : process(spawn(new internal::ConnectionProcess(s), true)) {}
 
   ~Data()
@@ -1279,7 +1279,7 @@ struct Connection::Data
 };
 
 
-Connection::Connection(const Socket& s)
+Connection::Connection(const network::Socket& s)
   : data(std::make_shared<Connection::Data>(s)) {}
 
 
@@ -1312,6 +1312,20 @@ Future<Nothing> Connection::disconnected()
 }
 
 
+Future<Connection> connect(const network::Address& address)
+{
+  Try<network::Socket> socket = network::Socket::create(address.family());
+  if (socket.isError()) {
+    return Failure("Failed to create socket: " + socket.error());
+  }
+
+  return socket->connect(address)
+    .then([socket]() {
+      return Connection(socket.get());
+    });
+}
+
+
 Future<Connection> connect(const URL& url)
 {
   // TODO(bmahler): Move address resolution into the URL class?
@@ -1340,15 +1354,20 @@ Future<Connection> connect(const URL& url)
 
   address.port = url.port.get();
 
-  Try<Socket> socket = [&url]() -> Try<Socket> {
+  // TODO(benh): Reuse `connect(address)` once it supports SSL.
+  Try<network::Socket> socket = [&url]() -> Try<network::Socket> {
     // Default to 'http' if no scheme was specified.
     if (url.scheme.isNone() || url.scheme == string("http")) {
-      return Socket::create(SocketImpl::Kind::POLL);
+      return network::Socket::create(
+          network::Address::Family::INET,
+          SocketImpl::Kind::POLL);
     }
 
     if (url.scheme == string("https")) {
 #ifdef USE_SSL_SOCKET
-      return Socket::create(SocketImpl::Kind::SSL);
+      return network::Socket::create(
+          network::Address::Family::INET,
+          SocketImpl::Kind::SSL);
 #else
       return Error("'https' scheme requires SSL enabled");
 #endif