From 642c9228d7d170605394035777b9593bd5c1005f Mon Sep 17 00:00:00 2001 From: jarodruan Date: Mon, 10 Feb 2020 09:39:49 +0800 Subject: [PATCH] nghttp2 succ --- examples/HttpDemo/HttpServer/Http2Imp.h | 2 +- examples/HttpDemo/HttpServer/HttpServer.cpp | 2 +- servant/libservant/AppProtocol.cpp | 6 ++---- servant/protocol | 2 +- util/src/tc_http2session.cpp | 14 +++++++------- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/examples/HttpDemo/HttpServer/Http2Imp.h b/examples/HttpDemo/HttpServer/Http2Imp.h index e5867b3..6c69d6c 100644 --- a/examples/HttpDemo/HttpServer/Http2Imp.h +++ b/examples/HttpDemo/HttpServer/Http2Imp.h @@ -15,7 +15,7 @@ */ #ifndef _Http2Imp_H_ -#define _HttpImp_H_ +#define _Http2Imp_H_ #include "servant/Application.h" #include "util/tc_spin_lock.h" diff --git a/examples/HttpDemo/HttpServer/HttpServer.cpp b/examples/HttpDemo/HttpServer/HttpServer.cpp index e8f55d8..d6279a2 100644 --- a/examples/HttpDemo/HttpServer/HttpServer.cpp +++ b/examples/HttpDemo/HttpServer/HttpServer.cpp @@ -36,7 +36,7 @@ TC_NetWorkBuffer::PACKET_TYPE parseHttp2(TC_NetWorkBuffer&in, vector &out) Http2Imp::addHttp2Session(connection->getId(), session); } - cout << "parseHttp2:" << in.getBufferLength() << endl; + cout << "parseHttp2:" << in.getBufferLength() << ", " << session << endl; return session->parse(in, out); } diff --git a/servant/libservant/AppProtocol.cpp b/servant/libservant/AppProtocol.cpp index 8bedcf6..9b135f8 100644 --- a/servant/libservant/AppProtocol.cpp +++ b/servant/libservant/AppProtocol.cpp @@ -251,10 +251,7 @@ vector ProxyProtocol::http2Request(RequestPacket& request, Transceiver *tr if (!request.sServantName.empty()) nva.push_back(nv2); - for (std::map::const_iterator - it(request.context.begin()); - it != request.context.end(); - ++ it) + for (std::map::const_iterator it(request.context.begin()); it != request.context.end(); ++ it) { nghttp2_nv nv = MAKE_STRING_NV(it->first, it->second); nva.push_back(nv); @@ -292,6 +289,7 @@ vector ProxyProtocol::http2Request(RequestPacket& request, Transceiver *tr vector out; out.assign(session->sendBuffer().begin(), session->sendBuffer().end()); + session->sendBuffer().clear(); cout << "iRequestId:" << request.iRequestId << ", size:" << out.size() << endl; diff --git a/servant/protocol b/servant/protocol index 2e3c1ab..7c22d46 160000 --- a/servant/protocol +++ b/servant/protocol @@ -1 +1 @@ -Subproject commit 2e3c1abd10ad801f74f7673f54f7d45b7962318f +Subproject commit 7c22d46777d76c8c08c2161f7cb4d9f0f45991d7 diff --git a/util/src/tc_http2session.cpp b/util/src/tc_http2session.cpp index 33270c6..a87cc83 100644 --- a/util/src/tc_http2session.cpp +++ b/util/src/tc_http2session.cpp @@ -58,7 +58,7 @@ static int on_header_callback(nghttp2_session *session, size_t namelen, const uint8_t *value, size_t valuelen, uint8_t flags, void *user_data) { - //TLOGDEBUG("[on_header_callback] streamid:" << frame->hd.stream_id << " name:" << name << " value:" << value << " flags:" << flags << endl); + cout << "[on_header_callback] streamid:" << frame->hd.stream_id << " name:" << name << " value:" << value << " flags:" << flags << endl; TC_Http2Session *ptr = (TC_Http2Session*)user_data; { @@ -100,11 +100,10 @@ static int on_begin_headers_callback(nghttp2_session *session, const nghttp2_frame *frame, void *user_data) { - //TLOGDEBUG("[on_begin_headers_callback] streamid:" << frame->hd.stream_id << endl); + cout << "[on_begin_headers_callback] streamid:" << frame->hd.stream_id << endl; TC_Http2Session *ptr = (TC_Http2Session*)user_data; - if (frame->hd.type != NGHTTP2_HEADERS || - frame->headers.cat != NGHTTP2_HCAT_REQUEST) { + if (frame->hd.type != NGHTTP2_HEADERS || frame->headers.cat != NGHTTP2_HCAT_REQUEST) { return 0; } @@ -130,7 +129,7 @@ static int on_frame_recv_callback(nghttp2_session *session, const nghttp2_frame /* Check that the client request has finished */ if (frame->hd.flags & NGHTTP2_FLAG_END_STREAM) { - //TLOGDEBUG("[on_frame_recv_callback] NGHTTP2_FLAG_END_STREAM" << endl); + cout << "[on_frame_recv_callback] NGHTTP2_FLAG_END_STREAM" << endl; { TC_LockT lock(ptr->reqLock_); @@ -162,7 +161,8 @@ static int on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags, int32_t stream_id, const uint8_t *data, size_t len, void *user_data) { - //TLOGDEBUG("[on_data_chunk_recv_callback] stream_id:" << stream_id << endl); + cout << "[on_data_chunk_recv_callback] stream_id:" << stream_id << endl; + TC_Http2Session *ptr = (TC_Http2Session*)user_data; { TC_LockT lock(ptr->reqLock_); @@ -177,7 +177,7 @@ static int on_data_chunk_recv_callback(nghttp2_session *session, uint8_t flags, static int on_stream_close_callback(nghttp2_session *session, int32_t stream_id, uint32_t error_code, void *user_data) { - //TLOGDEBUG("[on_stream_close_callback] streamid:" << stream_id << endl); + cout << "[on_stream_close_callback] streamid:" << stream_id << endl; TC_Http2Session *ptr = (TC_Http2Session*)user_data;