nghttp: Remove streams from HttpClient

This commit is contained in:
Tatsuhiro Tsujikawa 2014-05-08 00:29:46 +09:00
parent 48fc0c04bc
commit 1bd43e094a
1 changed files with 71 additions and 65 deletions

View File

@ -414,8 +414,6 @@ enum client_state {
namespace { namespace {
struct HttpClient { struct HttpClient {
std::vector<std::unique_ptr<Request>> reqvec; std::vector<std::unique_ptr<Request>> reqvec;
// Map from stream ID to Request object.
std::map<int32_t, Request*> streams;
// Insert path already added in reqvec to prevent multiple request // Insert path already added in reqvec to prevent multiple request
// for 1 resource. // for 1 resource.
std::set<std::string> path_cache; std::set<std::string> path_cache;
@ -925,7 +923,6 @@ struct HttpClient {
void on_request(Request *req) void on_request(Request *req)
{ {
streams[req->stream_id] = req;
req->record_request_time(); req->record_request_time();
if(req->pri == 0 && req->dep) { if(req->pri == 0 && req->dep) {
@ -1127,9 +1124,13 @@ int on_data_chunk_recv_callback
const uint8_t *data, size_t len, void *user_data) const uint8_t *data, size_t len, void *user_data)
{ {
auto client = get_session(user_data); auto client = get_session(user_data);
auto itr = client->streams.find(stream_id); auto req =
if(itr != client->streams.end()) { (Request*)nghttp2_session_get_stream_user_data(session, stream_id);
auto req = (*itr).second;
if(!req) {
return 0;
}
if(req->inflater) { if(req->inflater) {
while(len > 0) { while(len > 0) {
const size_t MAX_OUTLEN = 4096; const size_t MAX_OUTLEN = 4096;
@ -1194,7 +1195,6 @@ int on_data_chunk_recv_callback
} }
update_html_parser(client, req, data, len, 0); update_html_parser(client, req, data, len, 0);
} }
}
return 0; return 0;
@ -1454,15 +1454,21 @@ int on_stream_close_callback
void *user_data) void *user_data)
{ {
auto client = get_session(user_data); auto client = get_session(user_data);
auto itr = client->streams.find(stream_id); auto req =
if(itr != client->streams.end()) { (Request*)nghttp2_session_get_stream_user_data(session, stream_id);
update_html_parser(client, (*itr).second, nullptr, 0, 1);
(*itr).second->record_complete_time(); if(!req) {
++client->complete; return 0;
} }
update_html_parser(client, req, nullptr, 0, 1);
req->record_complete_time();
++client->complete;
if(client->all_requests_processed()) { if(client->all_requests_processed()) {
nghttp2_session_terminate_session(session, NGHTTP2_NO_ERROR); nghttp2_session_terminate_session(session, NGHTTP2_NO_ERROR);
} }
return 0; return 0;
} }
} // namespace } // namespace