From: Mikko Rasa Date: Wed, 10 Aug 2011 18:42:48 +0000 (+0300) Subject: Store pending responses in a map X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=b884825f8415c3bd300c433e1e155d98dbc56550;p=libs%2Fnet.git Store pending responses in a map --- diff --git a/source/http/server.cpp b/source/http/server.cpp index 9205cc1..47de7dd 100644 --- a/source/http/server.cpp +++ b/source/http/server.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -124,11 +125,13 @@ void Server::client_data_available(Client &cl) try { cl.response = response.get(); + responses[cl.response] = &cl; signal_request.emit(*cl.request, *response); if(cl.async) response.release(); else { + responses.erase(cl.response); cl.response = 0; if(response->get_status()==NONE) { @@ -139,6 +142,7 @@ void Server::client_data_available(Client &cl) } catch(const exception &e) { + responses.erase(cl.response); cl.response = 0; response = new Response(INTERNAL_ERROR); response->add_content(e.what()); @@ -159,12 +163,7 @@ void Server::client_end_of_file(Client &cl) Server::Client &Server::get_client_by_response(Response &resp) { - for(list::iterator i=clients.begin(); i!=clients.end(); ++i) - if(i->response==&resp) - return *i; - - // XXX Do this differently - throw invalid_argument("Response does not belong to any client"); + return *get_item(responses, &resp); } diff --git a/source/http/server.h b/source/http/server.h index 41894db..e07ee55 100644 --- a/source/http/server.h +++ b/source/http/server.h @@ -32,6 +32,7 @@ private: Net::StreamServerSocket sock; std::list clients; + std::map responses; IO::EventDispatcher *event_disp; public: