Repository: mesos Updated Branches: refs/heads/master 48980012e -> 2199a599d
Added ability to check if the streaming decoder is writing to a body pipe. Review: https://reviews.apache.org/r/38606 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/9c39861f Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/9c39861f Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/9c39861f Branch: refs/heads/master Commit: 9c39861fbedfd699edd5d3854e55507a03040c70 Parents: 4898001 Author: Benjamin Mahler <[email protected]> Authored: Mon Sep 21 11:28:54 2015 -0700 Committer: Benjamin Mahler <[email protected]> Committed: Mon Oct 5 16:04:47 2015 -0700 ---------------------------------------------------------------------- 3rdparty/libprocess/src/decoder.hpp | 7 +++++++ 3rdparty/libprocess/src/tests/decoder_tests.cpp | 6 ++++++ 2 files changed, 13 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/9c39861f/3rdparty/libprocess/src/decoder.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/decoder.hpp b/3rdparty/libprocess/src/decoder.hpp index d348463..53b8079 100644 --- a/3rdparty/libprocess/src/decoder.hpp +++ b/3rdparty/libprocess/src/decoder.hpp @@ -556,6 +556,13 @@ public: return failure; } + // Returns whether the decoder is currently writing a response + // body. Helpful for knowing if the latest response is complete. + bool writingBody() const + { + return writer.isSome(); + } + private: static int on_message_begin(http_parser* p) { http://git-wip-us.apache.org/repos/asf/mesos/blob/9c39861f/3rdparty/libprocess/src/tests/decoder_tests.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/libprocess/src/tests/decoder_tests.cpp b/3rdparty/libprocess/src/tests/decoder_tests.cpp index ab33126..f1963fd 100644 --- a/3rdparty/libprocess/src/tests/decoder_tests.cpp +++ b/3rdparty/libprocess/src/tests/decoder_tests.cpp @@ -163,6 +163,7 @@ TEST(DecoderTest, StreamingResponse) deque<Response*> responses = decoder.decode(headers.data(), headers.length()); EXPECT_FALSE(decoder.failed()); + EXPECT_TRUE(decoder.writingBody()); ASSERT_EQ(1, responses.size()); Response* response = responses[0]; @@ -179,10 +180,12 @@ TEST(DecoderTest, StreamingResponse) decoder.decode(body.data(), body.length()); EXPECT_FALSE(decoder.failed()); + EXPECT_FALSE(decoder.writingBody()); // Feeding EOF to the decoder should be ok. decoder.decode("", 0); EXPECT_FALSE(decoder.failed()); + EXPECT_FALSE(decoder.writingBody()); EXPECT_TRUE(read.isReady()); EXPECT_EQ("hi", read.get()); @@ -210,6 +213,7 @@ TEST(DecoderTest, StreamingResponseFailure) deque<Response*> responses = decoder.decode(headers.data(), headers.length()); EXPECT_FALSE(decoder.failed()); + EXPECT_TRUE(decoder.writingBody()); ASSERT_EQ(1, responses.size()); Response* response = responses[0]; @@ -226,6 +230,7 @@ TEST(DecoderTest, StreamingResponseFailure) decoder.decode(body.data(), body.length()); EXPECT_FALSE(decoder.failed()); + EXPECT_TRUE(decoder.writingBody()); EXPECT_TRUE(read.isReady()); EXPECT_EQ("1", read.get()); @@ -237,6 +242,7 @@ TEST(DecoderTest, StreamingResponseFailure) // Feeding EOF to the decoder should trigger a failure! decoder.decode("", 0); EXPECT_TRUE(decoder.failed()); + EXPECT_FALSE(decoder.writingBody()); EXPECT_TRUE(read.isFailed()); EXPECT_EQ("failed to decode body", read.failure());
