You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ic...@apache.org on 2015/12/14 12:09:31 UTC
svn commit: r1719881 - in /httpd/httpd/trunk/modules/http2: h2_alt_svc.c
h2_config.c h2_ctx.c h2_ctx.h h2_h2.c h2_switch.c h2_task.c
Author: icing
Date: Mon Dec 14 11:09:31 2015
New Revision: 1719881
URL: http://svn.apache.org/viewvc?rev=1719881&view=rev
Log:
saving some bytes and cycles by not create h2_ctx for every connection and checking for c->master in the hooks
Modified:
httpd/httpd/trunk/modules/http2/h2_alt_svc.c
httpd/httpd/trunk/modules/http2/h2_config.c
httpd/httpd/trunk/modules/http2/h2_ctx.c
httpd/httpd/trunk/modules/http2/h2_ctx.h
httpd/httpd/trunk/modules/http2/h2_h2.c
httpd/httpd/trunk/modules/http2/h2_switch.c
httpd/httpd/trunk/modules/http2/h2_task.c
Modified: httpd/httpd/trunk/modules/http2/h2_alt_svc.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_alt_svc.c?rev=1719881&r1=1719880&r2=1719881&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/http2/h2_alt_svc.c (original)
+++ httpd/httpd/trunk/modules/http2/h2_alt_svc.c Mon Dec 14 11:09:31 2015
@@ -73,7 +73,6 @@ h2_alt_svc *h2_alt_svc_parse(const char
static int h2_alt_svc_handler(request_rec *r)
{
- h2_ctx *ctx;
const h2_config *cfg;
int i;
@@ -82,8 +81,7 @@ static int h2_alt_svc_handler(request_re
return DECLINED;
}
- ctx = h2_ctx_rget(r);
- if (h2_ctx_is_active(ctx) || h2_ctx_is_task(ctx)) {
+ if (h2_ctx_rget(r)) {
return DECLINED;
}
Modified: httpd/httpd/trunk/modules/http2/h2_config.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_config.c?rev=1719881&r1=1719880&r2=1719881&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/http2/h2_config.c (original)
+++ httpd/httpd/trunk/modules/http2/h2_config.c Mon Dec 14 11:09:31 2015
@@ -561,14 +561,16 @@ const h2_config *h2_config_rget(request_
const h2_config *h2_config_get(conn_rec *c)
{
- h2_ctx *ctx = h2_ctx_get(c);
+ h2_ctx *ctx = h2_ctx_get(c, 0);
- if (ctx->config) {
- return ctx->config;
- }
- else if (ctx->server) {
- ctx->config = h2_config_sget(ctx->server);
- return ctx->config;
+ if (ctx) {
+ if (ctx->config) {
+ return ctx->config;
+ }
+ else if (ctx->server) {
+ ctx->config = h2_config_sget(ctx->server);
+ return ctx->config;
+ }
}
return h2_config_sget(c->base_server);
Modified: httpd/httpd/trunk/modules/http2/h2_ctx.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_ctx.c?rev=1719881&r1=1719880&r2=1719881&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/http2/h2_ctx.c (original)
+++ httpd/httpd/trunk/modules/http2/h2_ctx.c Mon Dec 14 11:09:31 2015
@@ -20,6 +20,7 @@
#include <http_config.h>
#include "h2_private.h"
+#include "h2_session.h"
#include "h2_task.h"
#include "h2_ctx.h"
#include "h2_private.h"
@@ -41,10 +42,10 @@ h2_ctx *h2_ctx_create_for(const conn_rec
return ctx;
}
-h2_ctx *h2_ctx_get(const conn_rec *c)
+h2_ctx *h2_ctx_get(const conn_rec *c, int create)
{
h2_ctx *ctx = (h2_ctx*)ap_get_module_config(c->conn_config, &http2_module);
- if (ctx == NULL) {
+ if (ctx == NULL && create) {
ctx = h2_ctx_create(c);
}
return ctx;
@@ -52,7 +53,7 @@ h2_ctx *h2_ctx_get(const conn_rec *c)
h2_ctx *h2_ctx_rget(const request_rec *r)
{
- return h2_ctx_get(r->connection);
+ return h2_ctx_get(r->connection, 0);
}
const char *h2_ctx_protocol_get(const conn_rec *c)
@@ -64,10 +65,19 @@ const char *h2_ctx_protocol_get(const co
h2_ctx *h2_ctx_protocol_set(h2_ctx *ctx, const char *proto)
{
ctx->protocol = proto;
- ctx->is_h2 = (proto != NULL);
return ctx;
}
+h2_session *h2_ctx_session_get(h2_ctx *ctx)
+{
+ return ctx? ctx->session : NULL;
+}
+
+void h2_ctx_session_set(h2_ctx *ctx, struct h2_session *session)
+{
+ ctx->session = session;
+}
+
h2_ctx *h2_ctx_server_set(h2_ctx *ctx, server_rec *s)
{
ctx->server = s;
@@ -79,12 +89,7 @@ int h2_ctx_is_task(h2_ctx *ctx)
return ctx && !!ctx->task;
}
-int h2_ctx_is_active(h2_ctx *ctx)
-{
- return ctx && ctx->is_h2;
-}
-
struct h2_task *h2_ctx_get_task(h2_ctx *ctx)
{
- return ctx->task;
+ return ctx? ctx->task : NULL;
}
Modified: httpd/httpd/trunk/modules/http2/h2_ctx.h
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_ctx.h?rev=1719881&r1=1719880&r2=1719881&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/http2/h2_ctx.h (original)
+++ httpd/httpd/trunk/modules/http2/h2_ctx.h Mon Dec 14 11:09:31 2015
@@ -16,6 +16,7 @@
#ifndef __mod_h2__h2_ctx__
#define __mod_h2__h2_ctx__
+struct h2_session;
struct h2_task;
struct h2_config;
@@ -28,15 +29,22 @@ struct h2_config;
* - those created by ourself to perform work on HTTP/2 streams
*/
typedef struct h2_ctx {
- int is_h2; /* h2 engine is used */
const char *protocol; /* the protocol negotiated */
+ struct h2_session *session; /* the session established */
struct h2_task *task; /* the h2_task executing or NULL */
const char *hostname; /* hostname negotiated via SNI, optional */
server_rec *server; /* httpd server config selected. */
const struct h2_config *config; /* effective config in this context */
} h2_ctx;
-h2_ctx *h2_ctx_get(const conn_rec *c);
+/**
+ * Get (or create) a h2 context record for this connection.
+ * @param c the connection to look at
+ * @param create != 0 iff missing context shall be created
+ * @return h2 context of this connection
+ */
+h2_ctx *h2_ctx_get(const conn_rec *c, int create);
+
h2_ctx *h2_ctx_rget(const request_rec *r);
h2_ctx *h2_ctx_create_for(const conn_rec *c, struct h2_task *task);
@@ -50,13 +58,15 @@ h2_ctx *h2_ctx_protocol_set(h2_ctx *ctx,
*/
h2_ctx *h2_ctx_server_set(h2_ctx *ctx, server_rec *s);
+struct h2_session *h2_ctx_session_get(h2_ctx *ctx);
+void h2_ctx_session_set(h2_ctx *ctx, struct h2_session *session);
+
/**
* Get the h2 protocol negotiated for this connection, or NULL.
*/
const char *h2_ctx_protocol_get(const conn_rec *c);
int h2_ctx_is_task(h2_ctx *ctx);
-int h2_ctx_is_active(h2_ctx *ctx);
struct h2_task *h2_ctx_get_task(h2_ctx *ctx);
Modified: httpd/httpd/trunk/modules/http2/h2_h2.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_h2.c?rev=1719881&r1=1719880&r2=1719881&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/http2/h2_h2.c (original)
+++ httpd/httpd/trunk/modules/http2/h2_h2.c Mon Dec 14 11:09:31 2015
@@ -574,8 +574,13 @@ void h2_h2_register_hooks(void)
int h2_h2_process_conn(conn_rec* c)
{
- h2_ctx *ctx = h2_ctx_get(c);
+ h2_ctx *ctx;
+ if (c->master) {
+ return DECLINED;
+ }
+
+ ctx = h2_ctx_get(c, 0);
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, c, "h2_h2, process_conn");
if (h2_ctx_is_task(ctx)) {
/* our stream pseudo connection */
@@ -612,6 +617,9 @@ int h2_h2_process_conn(conn_rec* c)
if ((slen >= 24) && !memcmp(H2_MAGIC_TOKEN, s, 24)) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, c,
"h2_h2, direct mode detected");
+ if (!ctx) {
+ ctx = h2_ctx_get(c, 1);
+ }
h2_ctx_protocol_set(ctx, h2_h2_is_tls(c)? "h2" : "h2c");
}
else {
@@ -630,7 +638,7 @@ int h2_h2_process_conn(conn_rec* c)
/* If "h2" was selected as protocol (by whatever mechanism), take over
* the connection.
*/
- if (h2_ctx_is_active(ctx)) {
+ if (ctx) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, c,
"h2_h2, connection, h2 active");
Modified: httpd/httpd/trunk/modules/http2/h2_switch.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_switch.c?rev=1719881&r1=1719880&r2=1719881&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/http2/h2_switch.c (original)
+++ httpd/httpd/trunk/modules/http2/h2_switch.c Mon Dec 14 11:09:31 2015
@@ -136,7 +136,7 @@ static int h2_protocol_switch(conn_rec *
}
if (found) {
- h2_ctx *ctx = h2_ctx_get(c);
+ h2_ctx *ctx = h2_ctx_get(c, 1);
ap_log_cerror(APLOG_MARK, APLOG_TRACE1, 0, c,
"switching protocol to '%s'", protocol);
Modified: httpd/httpd/trunk/modules/http2/h2_task.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/http2/h2_task.c?rev=1719881&r1=1719880&r2=1719881&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/http2/h2_task.c (original)
+++ httpd/httpd/trunk/modules/http2/h2_task.c Mon Dec 14 11:09:31 2015
@@ -118,8 +118,13 @@ void h2_task_register_hooks(void)
static int h2_task_pre_conn(conn_rec* c, void *arg)
{
- h2_ctx *ctx = h2_ctx_get(c);
+ h2_ctx *ctx;
+ if (!c->master) {
+ return OK;
+ }
+
+ ctx = h2_ctx_get(c, 0);
(void)arg;
if (h2_ctx_is_task(ctx)) {
h2_task *task = h2_ctx_get_task(ctx);
@@ -246,8 +251,13 @@ static apr_status_t h2_task_process_requ
static int h2_task_process_conn(conn_rec* c)
{
- h2_ctx *ctx = h2_ctx_get(c);
+ h2_ctx *ctx;
+
+ if (!c->master) {
+ return DECLINED;
+ }
+ ctx = h2_ctx_get(c, 0);
if (h2_ctx_is_task(ctx)) {
if (!ctx->task->serialize_headers) {
ap_log_cerror(APLOG_MARK, APLOG_TRACE2, 0, c,