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 2015/04/19 19:45:19 UTC

[5/8] trafficserver git commit: Checkpoint.

Checkpoint.


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

Branch: refs/heads/ts-974-multi-range-read
Commit: 45dc0c602e13a4dcf3a0681c195f3fd5f828a152
Parents: 1e43f79
Author: Alan M. Carroll <so...@yahoo-inc.com>
Authored: Thu Nov 20 15:43:58 2014 -0600
Committer: Alan M. Carroll <so...@yahoo-inc.com>
Committed: Sat Dec 6 11:56:03 2014 -0600

----------------------------------------------------------------------
 iocore/cache/CacheHttp.cc  | 29 +++++++++++++++++++++++++++++
 iocore/cache/I_CacheDefs.h | 41 ++++++++++++++++++++++++++++++++++++++++-
 lib/ts/TsBuffer.h          | 38 +++++++++++++++++++++++++++++++++++---
 3 files changed, 104 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/45dc0c60/iocore/cache/CacheHttp.cc
----------------------------------------------------------------------
diff --git a/iocore/cache/CacheHttp.cc b/iocore/cache/CacheHttp.cc
index 6bcc4fc..31531f2 100644
--- a/iocore/cache/CacheHttp.cc
+++ b/iocore/cache/CacheHttp.cc
@@ -256,6 +256,33 @@ CacheHTTPInfoVector::get_handles(const char *buf, int length, RefCountObj * bloc
   return ((caddr_t) buf - (caddr_t) start);
 }
 
+/*-------------------------------------------------------------------------
+  -------------------------------------------------------------------------*/
+bool
+RangeSpec::parse(char const* v, int len)
+{
+  char const PREFIX[] = { 'b', 'y', 't', 'e', 's', '=' };
+  ts::ConstBuffer src(v, len);
+
+  src.skip(&ParseRules::is_ws);
+
+  if (src.size() > sizeof(PREFIX) && 0 == memcmp(src.data(), PREFIX, sizeof(PREFIX))) {
+    src += sizeof(PREFIX);
+    while (src) {
+      ts::ConstBuffer max = src.splitOn(',');
+      ts::ConstBuffer min = max.splitOn('-');
+      src.skip(&ParseRules::is_ws);
+
+      if (min) {
+      } else {
+      }
+    }
+  }
+  return true;
+}
+/*-------------------------------------------------------------------------
+  -------------------------------------------------------------------------*/
+
 #else //HTTP_CACHE
 
 CacheHTTPInfoVector::CacheHTTPInfoVector()
@@ -351,5 +378,7 @@ CacheHTTPInfoVector::get_handles(const char */* buf ATS_UNUSED */, int /* length
   ink_assert(0);
   return 0;
 }
+/*-------------------------------------------------------------------------
+  -------------------------------------------------------------------------*/
 
 #endif //HTTP_CACHE

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/45dc0c60/iocore/cache/I_CacheDefs.h
----------------------------------------------------------------------
diff --git a/iocore/cache/I_CacheDefs.h b/iocore/cache/I_CacheDefs.h
index bd5bf46..84887de 100644
--- a/iocore/cache/I_CacheDefs.h
+++ b/iocore/cache/I_CacheDefs.h
@@ -21,7 +21,7 @@
   limitations under the License.
  */
 
-
+#include <vector>
 
 #ifndef _I_CACHE_DEFS_H__
 #define _I_CACHE_DEFS_H__
@@ -131,4 +131,43 @@ typedef CryptoHash CacheKey;
    word(2) - tag (lower bits), hosttable hash (upper bits)
    word(3) - ram cache hash, lookaside cache
  */
+
+
+/** A range specification.
+
+    This represents the data for an HTTP range specification.
+*/
+struct RangeSpec {
+  /** A range of bytes in an object.
+
+      If @a _min > @a _max this means the range is backwards and counts from the
+      end of the object. That is (1,0) means the last byte of content.
+  */
+  struct Descriptor {
+    uint64_t _min;
+    uint64_t _max;
+  };
+
+  enum State {
+    EMPTY, ///< No range.
+    SINGLE, ///< Single range.
+    MULTI, ///< Multiple ranges.
+  } _state;
+
+  /// The first range value.
+  /// By separating this out we can avoid allocation in the case of a single
+  /// range value, which is by far the most common ( > 99% in my experience).
+  Descriptor _singleton;
+  /// Storage for range values past the first one.
+  std::vector<Descriptor> _ranges;
+
+  RangeSpec() : _state(EMPTY)
+  {}
+
+  /** Parse a range field and update @a this with the results.
+      @return @c true if @a v was a valid range specifier, @c false otherwise.
+  */
+  bool parse(char const* v, int len);
+};
+
 #endif // __CACHE_DEFS_H__

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/45dc0c60/lib/ts/TsBuffer.h
----------------------------------------------------------------------
diff --git a/lib/ts/TsBuffer.h b/lib/ts/TsBuffer.h
index d4fac87..840c7bb 100644
--- a/lib/ts/TsBuffer.h
+++ b/lib/ts/TsBuffer.h
@@ -224,9 +224,10 @@ namespace ts {
 	@note This presumes a half open range (start, end]
     */
     self& set(
-	   char const* start, ///< First valid character.
-	   char const* end ///< First invalid character.
-	   );
+      char const* start, ///< First valid character.
+      char const* end ///< First invalid character.
+    );
+
     /// Reset to empty.
     self& reset();
 
@@ -271,17 +272,20 @@ namespace ts {
         @return A buffer containing data up to but not including @a p.
     */
     self splitOn(char c);
+
     /** Get a trailing segment of the buffer.
 
         @return A buffer that contains all data after @a p.
     */
     self after(char const* p) const;
+
     /** Get a trailing segment of the buffer.
 
         @return A buffer that contains all data after the first
         occurrence of @a c.
     */
     self after(char c) const;
+
     /** Remove trailing segment.
 
         Data at @a p and beyond is removed from the buffer.
@@ -290,6 +294,23 @@ namespace ts {
         @return @a this.
     */
     self& clip(char const* p);
+
+    /** Remove initial instances of @a c.
+
+	@return @c true if not all characters were skipped, @c false if all characters matched @a c.
+    */
+    bool skip(char c);
+
+    /** Remove leading characters that satisfy a @a predicate.
+	@return @c true if not all characters were skipped, @c false if all characters matched the @a predicate.
+
+	@internal We template this because the @c ParseRules predicates (which are the usual suspects)
+	return an integral type that is not @c bool.
+    */
+    template <
+      typename BOOL_EQUIV ///< Type that can be automatically converted to bool
+    >
+    bool skip(BOOL_EQUIV (*predicate)(char));
   };
 
   // ----------------------------------------------------------
@@ -392,6 +413,17 @@ namespace ts {
     }
     return *this;
   }
+  template < typename BOOL_EQUIV >
+  inline bool ConstBuffer::skip(BOOL_EQUIV (*predicate)(char))
+  {
+    while (*this && predicate(**this)) ++*this;
+    return *this;
+  }
+  inline bool ConstBuffer::skip(char c)
+  {
+    while (*this && c == **this) ++*this;
+    return *this;
+  }
 
 } // end namespace