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 {
struct HttpClient {
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
// for 1 resource.
std::set<std::string> path_cache;
@ -925,7 +923,6 @@ struct HttpClient {
void on_request(Request *req)
{
streams[req->stream_id] = req;
req->record_request_time();
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)
{
auto client = get_session(user_data);
auto itr = client->streams.find(stream_id);
if(itr != client->streams.end()) {
auto req = (*itr).second;
auto req =
(Request*)nghttp2_session_get_stream_user_data(session, stream_id);
if(!req) {
return 0;
}
if(req->inflater) {
while(len > 0) {
const size_t MAX_OUTLEN = 4096;
@ -1194,7 +1195,6 @@ int on_data_chunk_recv_callback
}
update_html_parser(client, req, data, len, 0);
}
}
return 0;
@ -1454,15 +1454,21 @@ int on_stream_close_callback
void *user_data)
{
auto client = get_session(user_data);
auto itr = client->streams.find(stream_id);
if(itr != client->streams.end()) {
update_html_parser(client, (*itr).second, nullptr, 0, 1);
(*itr).second->record_complete_time();
++client->complete;
auto req =
(Request*)nghttp2_session_get_stream_user_data(session, stream_id);
if(!req) {
return 0;
}
update_html_parser(client, req, nullptr, 0, 1);
req->record_complete_time();
++client->complete;
if(client->all_requests_processed()) {
nghttp2_session_terminate_session(session, NGHTTP2_NO_ERROR);
}
return 0;
}
} // namespace