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 2014/02/19 22:31:32 UTC

git commit: Move process::http namespace into http.cpp.

Repository: mesos
Updated Branches:
  refs/heads/master 9968b66f5 -> c21f96334


Move process::http namespace into http.cpp.

This moves the code declared in the process::http namespace to be in
it's own file (http.cpp). It already had it's own header.

Bug: https://issues.apache.org/jira/browse/MESOS-936

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


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

Branch: refs/heads/master
Commit: c21f9633436372f9920003a491eeafde7839e429
Parents: 9968b66
Author: Charlie Carson <ch...@gmail.com>
Authored: Wed Feb 19 13:29:55 2014 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Wed Feb 19 13:31:18 2014 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/Makefile.am     |   1 +
 3rdparty/libprocess/src/http.cpp    | 167 +++++++++++++++++++++++++++++++
 3rdparty/libprocess/src/process.cpp | 144 --------------------------
 3 files changed, 168 insertions(+), 144 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c21f9633/3rdparty/libprocess/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/Makefile.am b/3rdparty/libprocess/Makefile.am
index bcb78a4..a7d199f 100644
--- a/3rdparty/libprocess/Makefile.am
+++ b/3rdparty/libprocess/Makefile.am
@@ -31,6 +31,7 @@ libprocess_la_SOURCES =		\
   src/decoder.hpp		\
   src/encoder.hpp		\
   src/gate.hpp			\
+  src/http.cpp			\
   src/latch.cpp			\
   src/pid.cpp			\
   src/process.cpp		\

http://git-wip-us.apache.org/repos/asf/mesos/blob/c21f9633/3rdparty/libprocess/src/http.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/http.cpp b/3rdparty/libprocess/src/http.cpp
new file mode 100644
index 0000000..804fe80
--- /dev/null
+++ b/3rdparty/libprocess/src/http.cpp
@@ -0,0 +1,167 @@
+#include <arpa/inet.h>
+
+#include <cstring>
+#include <deque>
+#include <iostream>
+#include <string>
+
+#include <process/future.hpp>
+#include <process/http.hpp>
+#include <process/io.hpp>
+
+#include <stout/lambda.hpp>
+#include <stout/nothing.hpp>
+#include <stout/option.hpp>
+#include <stout/os.hpp>
+#include <stout/try.hpp>
+
+#include "decoder.hpp"
+
+using std::deque;
+using std::string;
+
+using process::http::Request;
+using process::http::Response;
+
+namespace process {
+
+namespace http {
+
+hashmap<uint16_t, string> statuses;
+
+namespace internal {
+
+Future<Response> decode(const string& buffer)
+{
+  ResponseDecoder decoder;
+  deque<Response*> responses = decoder.decode(buffer.c_str(), buffer.length());
+
+  if (decoder.failed() || responses.empty()) {
+    for (size_t i = 0; i < responses.size(); ++i) {
+      delete responses[i];
+    }
+    return Failure("Failed to decode HTTP response:\n" + buffer + "\n");
+  } else if (responses.size() > 1) {
+    PLOG(ERROR) << "Received more than 1 HTTP Response";
+  }
+
+  Response response = *responses[0];
+  for (size_t i = 0; i < responses.size(); ++i) {
+    delete responses[i];
+  }
+
+  return response;
+}
+
+
+Future<Response> request(
+    const UPID& upid,
+    const string& method,
+    const Option<string>& path,
+    const Option<string>& query,
+    const Option<string>& body,
+    const Option<string>& contentType)
+{
+  Try<int> socket = process::socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
+
+  if (socket.isError()) {
+    return Failure("Failed to create socket: " + socket.error());
+  }
+
+  int s = socket.get();
+
+  Try<Nothing> cloexec = os::cloexec(s);
+  if (!cloexec.isSome()) {
+    os::close(s);
+    return Failure("Failed to cloexec: " + cloexec.error());
+  }
+
+  sockaddr_in addr;
+  memset(&addr, 0, sizeof(addr));
+  addr.sin_family = AF_INET;
+  addr.sin_port = htons(upid.port);
+  addr.sin_addr.s_addr = upid.ip;
+
+  if (connect(s, (sockaddr*) &addr, sizeof(addr)) < 0) {
+    os::close(s);
+    return Failure(string("Failed to connect: ") + strerror(errno));
+  }
+
+  std::ostringstream out;
+
+  out << method << " /" << upid.id;
+
+  if (path.isSome()) {
+    out << "/" << path.get();
+  }
+
+  if (query.isSome()) {
+    out << "?" << query.get();
+  }
+
+  out << " HTTP/1.1\r\n";
+
+  // Call inet_ntop since inet_ntoa is not thread-safe!
+  char ip[INET_ADDRSTRLEN];
+  PCHECK(inet_ntop(AF_INET, (in_addr *) &upid.ip, ip, INET_ADDRSTRLEN) != NULL);
+
+  out << "Host: " << ip << ":" << upid.port << "\r\n"
+      << "Connection: close\r\n";
+
+  if (body.isNone() && contentType.isSome()) {
+    os::close(s);
+    return Failure("Attempted to do a POST with a Content-Type but no body");
+  }
+
+  if (contentType.isSome()) {
+    out << "Content-Type: " << contentType.get() << "\r\n";
+  }
+
+  if (body.isNone()) {
+    out << "\r\n";
+  } else {
+    out << "Content-Length: " << body.get().length() << "\r\n"
+        << "\r\n"
+        << body.get();
+  }
+
+  Try<Nothing> nonblock = os::nonblock(s);
+  if (!nonblock.isSome()) {
+    os::close(s);
+    return Failure("Failed to set nonblock: " + nonblock.error());
+  }
+
+  // Need to disambiguate the io::read we want when binding below.
+  Future<string> (*read)(int) = io::read;
+
+  return io::write(s, out.str())
+    .then(lambda::bind(read, s))
+    .then(lambda::bind(&internal::decode, lambda::_1))
+    .onAny(lambda::bind(&os::close, s));
+}
+
+
+} // namespace internal {
+
+
+Future<Response> get(
+    const UPID& upid,
+    const Option<string>& path,
+    const Option<string>& query)
+{
+  return internal::request(upid, "GET", path, query, None(), None());
+}
+
+
+Future<Response> post(
+    const UPID& upid,
+    const Option<string>& path,
+    const Option<string>& body,
+    const Option<string>& contentType)
+{
+  return internal::request(upid, "POST", path, None(), body, contentType);
+}
+
+
+} // namespace http {
+} // namespace process {

http://git-wip-us.apache.org/repos/asf/mesos/blob/c21f9633/3rdparty/libprocess/src/process.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/process.cpp b/3rdparty/libprocess/src/process.cpp
index 6cf4bfb..cd7d5ec 100644
--- a/3rdparty/libprocess/src/process.cpp
+++ b/3rdparty/libprocess/src/process.cpp
@@ -151,13 +151,6 @@ string generate(const string& prefix)
 } // namespace ID {
 
 
-namespace http {
-
-hashmap<uint16_t, string> statuses;
-
-} // namespace http {
-
-
 namespace mime {
 
 map<string, string> types;
@@ -3903,143 +3896,6 @@ Future<Nothing> splice(int from, int to, size_t chunk)
 
 } // namespace io {
 
-
-namespace http {
-
-namespace internal {
-
-Future<Response> decode(const string& buffer)
-{
-  ResponseDecoder decoder;
-  deque<Response*> responses = decoder.decode(buffer.c_str(), buffer.length());
-
-  if (decoder.failed() || responses.empty()) {
-    for (size_t i = 0; i < responses.size(); ++i) {
-      delete responses[i];
-    }
-    return Failure("Failed to decode HTTP response:\n" + buffer + "\n");
-  } else if (responses.size() > 1) {
-    PLOG(ERROR) << "Received more than 1 HTTP Response";
-  }
-
-  Response response = *responses[0];
-  for (size_t i = 0; i < responses.size(); ++i) {
-    delete responses[i];
-  }
-
-  return response;
-}
-
-
-Future<Response> request(
-    const UPID& upid,
-    const string& method,
-    const Option<string>& path,
-    const Option<string>& query,
-    const Option<string>& body,
-    const Option<string>& contentType)
-{
-  Try<int> socket = process::socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
-
-  if (socket.isError()) {
-    return Failure("Failed to create socket: " + socket.error());
-  }
-
-  int s = socket.get();
-
-  Try<Nothing> cloexec = os::cloexec(s);
-  if (!cloexec.isSome()) {
-    os::close(s);
-    return Failure("Failed to cloexec: " + cloexec.error());
-  }
-
-  sockaddr_in addr;
-  memset(&addr, 0, sizeof(addr));
-  addr.sin_family = AF_INET;
-  addr.sin_port = htons(upid.port);
-  addr.sin_addr.s_addr = upid.ip;
-
-  if (connect(s, (sockaddr*) &addr, sizeof(addr)) < 0) {
-    os::close(s);
-    return Failure(string("Failed to connect: ") + strerror(errno));
-  }
-
-  std::ostringstream out;
-
-  out << method << " /" << upid.id;
-
-  if (path.isSome()) {
-    out << "/" << path.get();
-  }
-
-  if (query.isSome()) {
-    out << "?" << query.get();
-  }
-
-  out << " HTTP/1.1\r\n";
-
-  // Call inet_ntop since inet_ntoa is not thread-safe!
-  char ip[INET_ADDRSTRLEN];
-  PCHECK(inet_ntop(AF_INET, (in_addr *) &upid.ip, ip, INET_ADDRSTRLEN) != NULL);
-
-  out << "Host: " << ip << ":" << upid.port << "\r\n"
-      << "Connection: close\r\n";
-
-  if (body.isNone() && contentType.isSome()) {
-    os::close(s);
-    return Failure("Attempted to do a POST with a Content-Type but no body");
-  }
-
-  if (contentType.isSome()) {
-    out << "Content-Type: " << contentType.get() << "\r\n";
-  }
-
-  if (body.isNone()) {
-    out << "\r\n";
-  } else {
-    out << "Content-Length: " << body.get().length() << "\r\n"
-        << "\r\n"
-        << body.get();
-  }
-
-  Try<Nothing> nonblock = os::nonblock(s);
-  if (!nonblock.isSome()) {
-    os::close(s);
-    return Failure("Failed to set nonblock: " + nonblock.error());
-  }
-
-  // Need to disambiguate the io::read we want when binding below.
-  Future<string> (*read)(int) = io::read;
-
-  return io::write(s, out.str())
-    .then(lambda::bind(read, s))
-    .then(lambda::bind(&internal::decode, lambda::_1))
-    .onAny(lambda::bind(&os::close, s));
-}
-
-} // namespace internal {
-
-
-Future<Response> get(
-    const UPID& upid,
-    const Option<string>& path,
-    const Option<string>& query)
-{
-  return internal::request(upid, "GET", path, query, None(), None());
-}
-
-
-Future<Response> post(
-    const UPID& upid,
-    const Option<string>& path,
-    const Option<string>& body,
-    const Option<string>& contentType)
-{
-  return internal::request(upid, "POST", path, None(), body, contentType);
-}
-
-}  // namespace http {
-
 namespace internal {
 
 void dispatch(