You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by jp...@apache.org on 2014/04/10 22:09:53 UTC
[2/2] git commit: TS-2699: Add TSClientProtoStackCreate API
TS-2699: Add TSClientProtoStackCreate API
Currently, plugin authors are expected to construct TSClientProtoStack
values by bitshifting them into their correct locations. This is
tedious likely to be error-prone. TSClientProtoStackCreate() accepts
a sequence of TSProtoType values, terminated by a TS_PROTO_NULL.
It combines the values and returns a TSClientProtoStack value that
describes the protocol layering of a client request.
Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/d80ab011
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/d80ab011
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/d80ab011
Branch: refs/heads/master
Commit: d80ab011a852733fe33a7d7e212153c98e9560ee
Parents: afd37d2
Author: James Peach <jp...@apache.org>
Authored: Fri Apr 4 20:45:18 2014 -0700
Committer: James Peach <jp...@apache.org>
Committed: Thu Apr 10 13:00:27 2014 -0700
----------------------------------------------------------------------
CHANGES | 2 ++
iocore/net/P_ProtocolAcceptCont.h | 4 ++--
lib/ts/apidefs.h.in | 4 ++--
plugins/experimental/spdy/stream.cc | 2 +-
proxy/InkAPI.cc | 36 ++++++++++++++++++++++++++++++++
proxy/InkAPITest.cc | 30 +++++++++++++++++++++++++-
proxy/api/ts/ts.h | 3 +++
proxy/logging/Log.cc | 2 +-
8 files changed, 76 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/d80ab011/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 4efb31c..6076a4f 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
-*- coding: utf-8 -*-
Changes with Apache Traffic Server 5.0.0
+ *) [TS-2699] Add TSClientProtoStackCreate API.
+
*) [TS-2678] Some sites (e.g. craigslist) fails to load due to
incorrect truncated response detection.
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/d80ab011/iocore/net/P_ProtocolAcceptCont.h
----------------------------------------------------------------------
diff --git a/iocore/net/P_ProtocolAcceptCont.h b/iocore/net/P_ProtocolAcceptCont.h
index 7631e5c..8b25cd8 100644
--- a/iocore/net/P_ProtocolAcceptCont.h
+++ b/iocore/net/P_ProtocolAcceptCont.h
@@ -31,7 +31,7 @@ class ProtocolAcceptCont: public AcceptCont
public:
ProtocolAcceptCont(): AcceptCont(NULL)
{
- memset(endpoint, 0, TS_PROTO_MAX * sizeof(AcceptCont *));
+ memset(endpoint, 0, sizeof(endpoint));
SET_HANDLER(&ProtocolAcceptCont::mainEvent);
}
~ProtocolAcceptCont() {}
@@ -44,7 +44,7 @@ private:
ProtocolAcceptCont(const ProtocolAcceptCont &); // disabled
ProtocolAcceptCont& operator =(const ProtocolAcceptCont&); // disabled
- Continuation *endpoint[TS_PROTO_MAX];
+ Continuation *endpoint[sizeof(TSClientProtoStack) * CHAR_BIT];
};
#endif /* P_ProtocolAcceptCont_H_ */
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/d80ab011/lib/ts/apidefs.h.in
----------------------------------------------------------------------
diff --git a/lib/ts/apidefs.h.in b/lib/ts/apidefs.h.in
index ffd8cbb..e909821 100644
--- a/lib/ts/apidefs.h.in
+++ b/lib/ts/apidefs.h.in
@@ -116,10 +116,10 @@ extern "C"
TS_PROTO_HTTP = 12,
TS_PROTO_SPDY = 13,
TS_PROTO_RTMP = 14,
- TS_PROTO_WBSK = 15, /* WebSocket */
+ TS_PROTO_WS = 15, /* WebSocket */
/* MAX value of TSProtoType */
- TS_PROTO_MAX
+ TS_PROTO_NULL = 32
} TSProtoType;
typedef uint32_t TSClientProtoStack;
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/d80ab011/plugins/experimental/spdy/stream.cc
----------------------------------------------------------------------
diff --git a/plugins/experimental/spdy/stream.cc b/plugins/experimental/spdy/stream.cc
index b5a7474..1d6fda9 100644
--- a/plugins/experimental/spdy/stream.cc
+++ b/plugins/experimental/spdy/stream.cc
@@ -71,7 +71,7 @@ initiate_client_request(
{
TSReleaseAssert(stream->vconn == nullptr);
- stream->vconn = TSHttpConnect(addr);
+ stream->vconn = TSHttpConnectWithProtoStack(addr, TSClientProtoStackCreate(TS_PROTO_TLS, TS_PROTO_SPDY, TS_PROTO_NULL));
if (stream->vconn) {
TSVConnRead(stream->vconn, contp, stream->input.buffer, std::numeric_limits<int64_t>::max());
TSVConnWrite(stream->vconn, contp, stream->output.reader, std::numeric_limits<int64_t>::max());
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/d80ab011/proxy/InkAPI.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPI.cc b/proxy/InkAPI.cc
index 2aa4cb5..c9eaf89 100644
--- a/proxy/InkAPI.cc
+++ b/proxy/InkAPI.cc
@@ -6048,6 +6048,42 @@ TSHttpAltInfoQualitySet(TSHttpAltInfo infop, float quality)
info->m_qvalue = quality;
}
+TSClientProtoStack
+TSClientProtoStackCreate(TSProtoType ptype, ...)
+{
+ unsigned pstack = 0;
+ va_list args;
+ const int pmax = (sizeof(TSClientProtoStack) * CHAR_BIT) - 1;
+
+ if (ptype == TS_PROTO_NULL || ptype > pmax) {
+ return 0;
+ }
+
+ pstack |= (1u << ptype);
+
+ va_start(args, ptype);
+ for (;;) {
+ ptype = (TSProtoType)va_arg(args, int);
+
+ // TS_PROTO_NULL ends the list.
+ if (ptype == TS_PROTO_NULL) {
+ va_end(args);
+ return pstack;
+ }
+
+ // Protocol stack value is out of range.
+ if (ptype > pmax) {
+ va_end(args);
+ return 0;
+ }
+
+ pstack |= (1u << ptype);
+ }
+
+ // We can't get here.
+ ink_release_assert(0);
+}
+
extern HttpAcceptCont *plugin_http_accept;
extern HttpAcceptCont *plugin_http_transparent_accept;
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/d80ab011/proxy/InkAPITest.cc
----------------------------------------------------------------------
diff --git a/proxy/InkAPITest.cc b/proxy/InkAPITest.cc
index f380eb5..5541323 100644
--- a/proxy/InkAPITest.cc
+++ b/proxy/InkAPITest.cc
@@ -42,10 +42,11 @@
#include "api/ts/ts.h"
#include "api/ts/experimental.h"
#include "I_RecCore.h"
-#include "I_Layout.h"
+#include <sys/types.h>
#include "InkAPITestTool.cc"
#include "http/HttpSM.h"
+#include "ts/TestBox.h"
#define TC_PASS 1
#define TC_FAIL 0
@@ -7664,3 +7665,30 @@ REGRESSION_TEST(SDK_API_DEBUG_NAME_LOOKUPS) (RegressionTest * test, int /* atype
return;
}
+
+////////////////////////////////////////////////
+// SDK_API_PROTO_STACK_CREATE
+//
+// Unit Test for API: TSClientProtoStackCreate
+////////////////////////////////////////////////
+
+REGRESSION_TEST(SDK_API_TSClientProtoStackCreate)(RegressionTest * t, int /* atype ATS_UNUSED */, int * pstatus)
+{
+ TestBox box(t, pstatus);
+
+ box = REGRESSION_TEST_PASSED;
+
+#define CHECK(expr, expected) do { \
+ TSClientProtoStack ps = (expr); \
+ box.check(ps == expected, "%s: received %u, expected %u", #expr, (unsigned)ps, (unsigned)expected); \
+} while(0)
+
+ CHECK(TSClientProtoStackCreate(TS_PROTO_NULL), 0);
+ CHECK(TSClientProtoStackCreate((TSProtoType)99, TS_PROTO_NULL), 0);
+ CHECK(TSClientProtoStackCreate(TS_PROTO_SPDY, (TSProtoType)99, TS_PROTO_NULL), 0);
+ CHECK(TSClientProtoStackCreate(TS_PROTO_UDP, TS_PROTO_NULL), 1);
+ CHECK(TSClientProtoStackCreate(TS_PROTO_UDP, TS_PROTO_TCP, TS_PROTO_NULL), 3);
+
+}
+
+
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/d80ab011/proxy/api/ts/ts.h
----------------------------------------------------------------------
diff --git a/proxy/api/ts/ts.h b/proxy/api/ts/ts.h
index 8279155..8c787b1 100644
--- a/proxy/api/ts/ts.h
+++ b/proxy/api/ts/ts.h
@@ -1576,6 +1576,9 @@ extern "C"
/* --------------------------------------------------------------------------
Initiate Http Connection */
+
+ tsapi TSClientProtoStack TSClientProtoStackCreate(TSProtoType, ...);
+
/**
Allows the plugin to initiate an http connection. The TSVConn the
plugin receives as the result of successful operates identically to
http://git-wip-us.apache.org/repos/asf/trafficserver/blob/d80ab011/proxy/logging/Log.cc
----------------------------------------------------------------------
diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc
index 8a7d0d5..aeac203 100644
--- a/proxy/logging/Log.cc
+++ b/proxy/logging/Log.cc
@@ -375,7 +375,7 @@ Log::init_fields()
TS_PROTO_HTTP, "HTTP",
TS_PROTO_SPDY, "SPDY",
TS_PROTO_RTMP, "RTMP",
- TS_PROTO_WBSK, "WBSK");
+ TS_PROTO_WS, "WS");
field = NEW(new LogField("client_protocol_stack", "cps",
LogField::sINT,