Index: src/debug-agent.cc |
diff --git a/src/debug-agent.cc b/src/debug-agent.cc |
index b390cc5931d3d229f343e911585e8e30d9d8380f..51bd4b15db7136c263481bef7b2f3c19f8f78a4e 100644 |
--- a/src/debug-agent.cc |
+++ b/src/debug-agent.cc |
@@ -46,8 +46,6 @@ void DebuggerAgentMessageHandler(const v8::Debug::Message& message) { |
// Debugger agent main thread. |
void DebuggerAgent::Run() { |
- const int kOneSecondInMicros = 1000000; |
- |
// Allow this socket to reuse port even if still in TIME_WAIT. |
server_->SetReuseAddress(true); |
@@ -60,16 +58,20 @@ void DebuggerAgent::Run() { |
// would be that the port is already in use so this avoids a busy loop and |
// make the agent take over the port when it becomes free. |
if (!bound) { |
+ const TimeDelta kTimeout = TimeDelta::FromSeconds(1); |
PrintF("Failed to open socket on port %d, " |
- "waiting %d ms before retrying\n", port_, kOneSecondInMicros / 1000); |
- terminate_now_->Wait(kOneSecondInMicros); |
+ "waiting %d ms before retrying\n", port_, |
+ static_cast<int>(kTimeout.InMilliseconds())); |
+ if (!terminate_now_.WaitFor(kTimeout)) { |
+ if (terminate_) return; |
+ } |
} |
} |
// Accept connections on the bound port. |
while (!terminate_) { |
bool ok = server_->Listen(1); |
- listening_->Signal(); |
+ listening_.Signal(); |
if (ok) { |
// Accept the new connection. |
Socket* client = server_->Accept(); |
@@ -89,7 +91,7 @@ void DebuggerAgent::Shutdown() { |
// Signal termination and make the server exit either its listen call or its |
// binding loop. This makes sure that no new sessions can be established. |
- terminate_now_->Signal(); |
+ terminate_now_.Signal(); |
server_->Shutdown(); |
Join(); |
@@ -99,7 +101,7 @@ void DebuggerAgent::Shutdown() { |
void DebuggerAgent::WaitUntilListening() { |
- listening_->Wait(); |
+ listening_.Wait(); |
} |
static const char* kCreateSessionMessage = |