You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2018/01/22 19:03:26 UTC

[trafficserver] branch master updated: Multiplexer plugin: Fix bug with chunk decoding, add some comments.

This is an automated email from the ASF dual-hosted git repository.

amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 6d506bb  Multiplexer plugin: Fix bug with chunk decoding, add some comments.
6d506bb is described below

commit 6d506bbbb5310bddb75f1790104dbd606dce7979
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Tue Nov 7 08:09:04 2017 -0600

    Multiplexer plugin: Fix bug with chunk decoding, add some comments.
---
 plugins/experimental/multiplexer/chunk-decoder.cc |  6 ++--
 plugins/experimental/multiplexer/chunk-decoder.h  | 35 ++++++++++++-----------
 2 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/plugins/experimental/multiplexer/chunk-decoder.cc b/plugins/experimental/multiplexer/chunk-decoder.cc
index ce47156..26c5f77 100644
--- a/plugins/experimental/multiplexer/chunk-decoder.cc
+++ b/plugins/experimental/multiplexer/chunk-decoder.cc
@@ -1,6 +1,6 @@
 /** @file
 
-  Multiplexes request to other origins.
+  Chunk decoding.
 
   @section license License
 
@@ -51,7 +51,6 @@ ChunkDecoder::parseSize(const char *p, const int64_t s)
   while (state_ != State::kData && *p != '\0' && length < s) {
     assert(state_ < State::kUpperBound); // VALID RANGE
     switch (state_) {
-    case State::kUnknown:
     case State::kData:
     case State::kInvalid:
     case State::kEnd:
@@ -117,6 +116,7 @@ ChunkDecoder::decode(const TSIOBufferReader &r)
   int64_t size;
   TSIOBufferBlock block = TSIOBufferReaderStart(r);
 
+  // Trying to parse a size.
   if (isSizeState()) {
     while (block != nullptr && size_ == 0) {
       const char *p = TSIOBufferBlockReadStart(block, r, &size);
@@ -141,7 +141,7 @@ ChunkDecoder::decode(const TSIOBufferReader &r)
     assert(size_ > 0);
     const char *p = TSIOBufferBlockReadStart(block, r, &size);
     if (p != nullptr) {
-      if (size > size_) {
+      if (size >= size_) {
         length += size_;
         size_  = 0;
         state_ = State::kSizeR;
diff --git a/plugins/experimental/multiplexer/chunk-decoder.h b/plugins/experimental/multiplexer/chunk-decoder.h
index d81a5fe..9a5e9d0 100644
--- a/plugins/experimental/multiplexer/chunk-decoder.h
+++ b/plugins/experimental/multiplexer/chunk-decoder.h
@@ -26,31 +26,32 @@
 #include <ts/ts.h>
 #include <inttypes.h>
 
+/** Class to handle state for decoding chunked data.
+ */
 class ChunkDecoder
 {
-  struct State {
-    enum STATES {
-      kUnknown,
-
-      kInvalid,
+  /// Parse states.
+  enum State {
+    kInvalid, ///< Invalid state.
 
-      kData,
-      kDataN,
-      kEnd,
-      kEndN,
-      kSize,
-      kSizeN,
-      kSizeR,
+    kData,  ///< Expecting data.
+    kDataN, ///< Expecting LF after size.
+    kEnd,
+    kEndN,
+    kSize,  ///< Expecting chunk size.
+    kSizeN, ///< Expecting LF after data.
+    kSizeR, ///< Expecting CR after data.
 
-      kUpperBound,
-    };
+    kUpperBound,
   };
 
-  State::STATES state_;
-  int64_t size_;
+  State state_  = kSize;
+  int64_t size_ = 0;
 
 public:
-  ChunkDecoder(void) : state_(State::kSize), size_(0) {}
+  /// Default Constructor. Construct to empty state of expected size 0.
+  ChunkDecoder() {}
+
   void parseSizeCharacter(const char);
   int parseSize(const char *, const int64_t);
   int decode(const TSIOBufferReader &);

-- 
To stop receiving notification emails like this one, please contact
amc@apache.org.