diff --git a/CMakeLists.txt b/CMakeLists.txt index d3ac6b0..ce44ffd 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -263,6 +263,7 @@ ExternalProject_Add(${LIB_HTTP2} BUILD_COMMAND make INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "install" URL_MD5 5df375bbd532fcaa7cd4044b54b1188d +# URL_MD5 9521689460b4a57912acd3f88f301a3a ) endif() diff --git a/examples/HttpDemo/Http2Client/main.cpp b/examples/HttpDemo/Http2Client/main.cpp index d7198b9..2344d50 100644 --- a/examples/HttpDemo/Http2Client/main.cpp +++ b/examples/HttpDemo/Http2Client/main.cpp @@ -48,6 +48,7 @@ void syncRpc2(int c) std::map header; header[":authority"] = "domain.com"; header[":scheme"] = "http"; + // header[":method"] = "POST"; std::map rheader; //发起远程调用 diff --git a/servant/libservant/AppProtocol.cpp b/servant/libservant/AppProtocol.cpp index 608cfcd..6aa0ca1 100644 --- a/servant/libservant/AppProtocol.cpp +++ b/servant/libservant/AppProtocol.cpp @@ -128,7 +128,7 @@ vector ProxyProtocol::http2Request(RequestPacket& request, Transceiver *tr trans->getSendBuffer()->setContextData(session, [=]{delete session;}); - session->settings(); + session->settings(3000); } request.iRequestId = session->submit(request.sFuncName, request.sServantName, request.context, request.sBuffer); @@ -147,14 +147,6 @@ vector ProxyProtocol::http2Request(RequestPacket& request, Transceiver *tr TC_NetWorkBuffer::PACKET_TYPE ProxyProtocol::http2Response(TC_NetWorkBuffer &in, ResponsePacket& rsp) { TC_Http2Client* session = (TC_Http2Client*)((Transceiver*)(in.getConnection()))->getSendBuffer()->getContextData(); - if(session == NULL) - { - session = new TC_Http2Client(); - - ((Transceiver*)(in.getConnection()))->getSendBuffer()->setContextData(session, [=]{delete session;}); - - session->settings(3000); - } pair> out; TC_NetWorkBuffer::PACKET_TYPE flag = session->parseResponse(in, out); diff --git a/util/src/tc_consistent_hash_new.cpp b/util/src/tc_consistent_hash_new.cpp index 6211395..6744452 100755 --- a/util/src/tc_consistent_hash_new.cpp +++ b/util/src/tc_consistent_hash_new.cpp @@ -214,18 +214,19 @@ int TC_ConsistentHashNew::getIndex(int32_t hashcode, unsigned int & iIndex) size_t iCode = (hashcode & 0xFFFFFFFFL); int low = 0; - size_t high = _vHashList.size(); + int high = (int)_vHashList.size(); - if(iCode <= _vHashList[0].iHashCode || iCode > _vHashList[high-1].iHashCode) + if(iCode <= (size_t)_vHashList[0].iHashCode || iCode > (size_t)_vHashList[high-1].iHashCode) { iIndex = _vHashList[0].iIndex; return 0; } + while (low < high - 1) { int mid = (low + high) / 2; - if (_vHashList[mid].iHashCode > iCode) + if ((size_t)_vHashList[mid].iHashCode > iCode) { high = mid; } diff --git a/util/src/tc_file.cpp b/util/src/tc_file.cpp index 10abe0f..4f23103 100644 --- a/util/src/tc_file.cpp +++ b/util/src/tc_file.cpp @@ -414,29 +414,29 @@ string TC_File::load2str(const string &sFullFileName) { // #if TARGET_PLATFORM_LINUX || TARGET_PLATFORM_IOS -// ifstream ifs(sFullFileName.c_str()); + ifstream ifs(sFullFileName.c_str()); -// return string(istreambuf_iterator(ifs), istreambuf_iterator()); + return string(istreambuf_iterator(ifs), istreambuf_iterator()); // #elif TARGET_PLATFORM_WINDOWS - std::ifstream::pos_type iLen = TC_File::getFileSize(sFullFileName); - FILE* fp = TC_Port::fopen(sFullFileName.c_str(), "rb"); - // if (fopen_s(&fp, sFullFileName.c_str(), "rb") == 0) - if(fp != NULL) - { - char* sBuffer = new char[iLen]; - size_t l = fread(sBuffer, 1, iLen, fp); - fclose(fp); - if (l != iLen) - { - delete[] sBuffer; - return ""; - } - std::string s(sBuffer, iLen); - delete[] sBuffer; - return s; - } - return ""; + // std::ifstream::pos_type iLen = TC_File::getFileSize(sFullFileName); + // FILE* fp = TC_Port::fopen(sFullFileName.c_str(), "rb"); + // // if (fopen_s(&fp, sFullFileName.c_str(), "rb") == 0) + // if(fp != NULL) + // { + // char* sBuffer = new char[iLen]; + // size_t l = fread(sBuffer, 1, iLen, fp); + // fclose(fp); + // if (l != iLen) + // { + // delete[] sBuffer; + // return ""; + // } + // std::string s(sBuffer, iLen); + // delete[] sBuffer; + // return s; + // } + // return ""; // #endif } @@ -461,7 +461,7 @@ bool TC_File::load2str(const string &sFullFileName, vector &data) // if (fopen_s(&fp, sFullFileName.c_str(), "rb") == 0) { data.resize(iLen); - size_t l = fread(data.data(), 1, iLen, fp); + int l = fread(data.data(), 1, iLen, fp); fclose(fp); if (l != iLen) { diff --git a/util/src/tc_http2.cpp b/util/src/tc_http2.cpp index b95d473..ce21f2c 100644 --- a/util/src/tc_http2.cpp +++ b/util/src/tc_http2.cpp @@ -43,7 +43,7 @@ int TC_Http2::settings(unsigned int maxCurrentStreams) { nghttp2_settings_entry iv[2] = { {NGHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, maxCurrentStreams}, - {NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, 100 * 1024 * 1024}, + {NGHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, 1024 * 1024}, }; /* 24 bytes magic string also will be sent*/ @@ -364,19 +364,6 @@ int TC_Http2Server::encodeResponse(const shared_ptrbuffer().insert(nghttp2->buffer().end(), (const char*)data, (const char*)data + length); + nghttp2->insertBuff((const char*)data, length); return length; } @@ -397,9 +384,6 @@ static int on_begin_headers_callback(nghttp2_session* session, const nghttp2_fra { if (frame->headers.cat == NGHTTP2_HCAT_RESPONSE) { -// TC_HttpResponse rsp; -// rsp.streamId = frame->hd.stream_id; -// rsp.state = TC_Http2Client::ResponseNone; nghttp2->responses()[frame->hd.stream_id] = std::make_shared(); } } @@ -449,7 +433,6 @@ static int on_frame_recv_callback(nghttp2_session* session, const nghttp2_frame* if (frame->hd.flags & NGHTTP2_FLAG_END_HEADERS) { ; -// it->second.state = TC_Http2Client::ResponseHeadersDone; } return 0; @@ -484,8 +467,6 @@ static int on_stream_close_callback(nghttp2_session* session, int32_t stream_id, return NGHTTP2_ERR_CALLBACK_FAILURE; } -// it->second.state = TC_Http2Client::ResponseBodyDone; - nghttp2->doneResponses()[stream_id] = it->second; nghttp2->responses().erase(it); @@ -494,19 +475,7 @@ static int on_stream_close_callback(nghttp2_session* session, int32_t stream_id, } -#define MAKE_NV(NAME, VALUE, VALUELEN) \ - { \ - (uint8_t *)NAME, (uint8_t *)VALUE, sizeof(NAME) - 1, VALUELEN, \ - NGHTTP2_NV_FLAG_NONE \ - } - -#define MAKE_NV2(NAME, VALUE) \ - { \ - (uint8_t *)NAME, (uint8_t *)VALUE, sizeof(NAME) - 1, sizeof(VALUE) - 1, \ - NGHTTP2_NV_FLAG_NONE \ - } - -#define MAKE_STRING_NV(NAME, VALUE) {(uint8_t*)(NAME.data()), (uint8_t*)(VALUE.data()), NAME.size(), VALUE.size(), NGHTTP2_NV_FLAG_NONE}; +#define MAKE_STRING_NV(NAME, VALUE) {(uint8_t*)(NAME.c_str()), (uint8_t*)(VALUE.c_str()), NAME.size(), VALUE.size(), NGHTTP2_NV_FLAG_NONE}; TC_Http2Client::TC_Http2Client() { @@ -532,14 +501,14 @@ int TC_Http2Client::submit(const string &method, const string &path, const map nva; -// const std::string method(":method"); - nghttp2_nv nv1 = MAKE_STRING_NV(string(":method"), method); + const std::string smethod(":method"); + nghttp2_nv nv1 = MAKE_STRING_NV(smethod, method); if (!method.empty()) { nva.push_back(nv1); } -// const std::string path(":path"); - nghttp2_nv nv2 = MAKE_STRING_NV(string(":path"), path); + const std::string spath(":path"); + nghttp2_nv nv2 = MAKE_STRING_NV(spath, path); if (!path.empty()) nva.push_back(nv2); @@ -572,9 +541,9 @@ int TC_Http2Client::submit(const string &method, const string &path, const map