Skip to content

Commit

Permalink
Start accepting http connections in next run loop.
Browse files Browse the repository at this point in the history
Devtools is not ready to get callbacks if accept returns connections
synchronously.

BUG=428389

Review URL: https://codereview.chromium.org/683733006

Cr-Commit-Position: refs/heads/master@{#302309}
  • Loading branch information
byungchul authored and Commit bot committed Oct 31, 2014
1 parent cbdaf76 commit baa7546
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion net/server/http_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

#include "net/server/http_server.h"

#include "base/bind.h"
#include "base/compiler_specific.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/message_loop/message_loop_proxy.h"
#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
Expand All @@ -30,7 +33,11 @@ HttpServer::HttpServer(scoped_ptr<ServerSocket> server_socket,
last_id_(0),
weak_ptr_factory_(this) {
DCHECK(server_socket_);
DoAcceptLoop();
// Start accepting connections in next run loop in case when delegate is not
// ready to get callbacks.
base::MessageLoopProxy::current()->PostTask(
FROM_HERE,
base::Bind(&HttpServer::DoAcceptLoop, weak_ptr_factory_.GetWeakPtr()));
}

HttpServer::~HttpServer() {
Expand Down
4 changes: 4 additions & 0 deletions net/server/http_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class HttpServer {
virtual void OnClose(int connection_id) = 0;
};

// Instantiates a http server with |server_socket| which already started
// listening, but not accepting. This constructor schedules accepting
// connections asynchronously in case when |delegate| is not ready to get
// callbacks yet.
HttpServer(scoped_ptr<ServerSocket> server_socket,
HttpServer::Delegate* delegate);
~HttpServer();
Expand Down

0 comments on commit baa7546

Please sign in to comment.