Skip to content

Commit

Permalink
campaignd: Use find() to locate a request handler
Browse files Browse the repository at this point in the history
Makes it so for each request received we use
request_handlers_table::find() instead of a plain linear search to find
the handler, using the tag name of the first WML child node we can find,
instead of trying to locate one with a known handler id.

In theory this allows taking advantage of the request_handlers_table
type's (currently a std::map) own lookup mechanism.
  • Loading branch information
irydacea committed Jun 25, 2014
1 parent 6b8e42d commit df54918
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/campaign_server/campaign_server.cpp
Expand Up @@ -278,13 +278,18 @@ void server::run()

while((sock = network::receive_data(data, 0)) != network::null_connection)
{
typedef std::pair<std::string, request_handler> rh_table_entry;
BOOST_FOREACH(const rh_table_entry& rh, handlers_)
{
const config& req_body = data.child(rh.first);
config::all_children_iterator i = data.ordered_begin();

if(req_body) {
rh.second(request(rh.first, req_body, sock));
if(i != data.ordered_end()) {
// We only handle the first child.
const config::any_child& c = *i;

request_handlers_table::const_iterator j
= handlers_.find(c.key);

if(j != handlers_.end()) {
// Call the handler.
j->second(request(c.key, c.cfg, sock));
}
}
}
Expand Down

0 comments on commit df54918

Please sign in to comment.