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 2017/02/04 07:46:50 UTC

[6/6] mesos git commit: Replaced (another) recursive implementation with process::loop.

Replaced (another) recursive implementation with process::loop.

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


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

Branch: refs/heads/master
Commit: d611162c7d4a2bd0734e808b7e1ac8d6b0daa1a2
Parents: ca3fe98
Author: Benjamin Hindman <be...@gmail.com>
Authored: Sat Jan 14 13:49:38 2017 -0800
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Fri Feb 3 23:44:26 2017 -0800

----------------------------------------------------------------------
 3rdparty/libprocess/src/http.cpp | 59 +++++++++++++++++------------------
 1 file changed, 28 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d611162c/3rdparty/libprocess/src/http.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/http.cpp b/3rdparty/libprocess/src/http.cpp
index 544c26f..f12a8a5 100644
--- a/3rdparty/libprocess/src/http.cpp
+++ b/3rdparty/libprocess/src/http.cpp
@@ -1000,9 +1000,6 @@ ostream& operator<<(ostream& stream, const URL& url)
 
 namespace internal {
 
-void _encode(Pipe::Reader reader, Pipe::Writer writer); // Forward declaration.
-
-
 // Encodes the request by writing into a pipe, the caller can
 // read the encoded data from the returned read end of the pipe.
 // A pipe is used since the request body can be a pipe and must
@@ -1098,7 +1095,34 @@ Pipe::Reader encode(const Request& request)
     case Request::PIPE:
       CHECK_SOME(request.reader);
       CHECK(request.body.empty());
-      _encode(request.reader.get(), writer);
+      Pipe::Reader requestReader = request.reader.get();
+      loop(None(),
+           [=]() mutable {
+             return requestReader.read();
+           },
+           [=](const string& chunk) mutable -> ControlFlow<Nothing> {
+             if (chunk.empty()) {
+               // EOF case.
+               writer.write("0\r\n\r\n");
+               writer.close();
+               return Break();
+             }
+
+             std::ostringstream out;
+             out << std::hex << chunk.size() << "\r\n";
+             out << chunk;
+             out << "\r\n";
+
+             writer.write(out.str());
+
+             return Continue();
+           })
+        .onDiscarded([=]() mutable {
+          writer.fail("discarded");
+        })
+        .onFailed([=](const string& failure) mutable {
+          writer.fail(failure);
+        });
       break;
   }
 
@@ -1106,33 +1130,6 @@ Pipe::Reader encode(const Request& request)
 }
 
 
-void _encode(Pipe::Reader reader, Pipe::Writer writer)
-{
-  reader.read()
-    .onAny([reader, writer](const Future<string>& chunk) mutable {
-      if (!chunk.isReady()) {
-        writer.fail(chunk.isFailed() ? chunk.failure() : "discarded");
-        return;
-      }
-
-      if (chunk->empty()) {
-        // EOF case.
-        writer.write("0\r\n\r\n");
-        writer.close();
-        return;
-      }
-
-      std::ostringstream out;
-      out << std::hex << chunk->size() << "\r\n";
-      out << chunk.get();
-      out << "\r\n";
-
-      writer.write(out.str());
-      _encode(reader, writer);
-    });
-}
-
-
 // Returns a 'BODY' response once the body of the provided
 // 'PIPE' response can be read completely.
 Future<Response> convert(const Response& pipeResponse)