// Accept connections on the bound port.
while (!terminate_) {
bool ok = server_->Listen(1);
+ listening_->Signal();
if (ok) {
// Accept the new connection.
Socket* client = server_->Accept();
}
+void DebuggerAgent::WaitUntilListening() {
+ listening_->Wait();
+}
+
void DebuggerAgent::CreateSession(Socket* client) {
ScopedLock with(session_access_);
: name_(StrDup(name)), port_(port),
server_(OS::CreateSocket()), terminate_(false),
session_access_(OS::CreateMutex()), session_(NULL),
- terminate_now_(OS::CreateSemaphore(0)) {
+ terminate_now_(OS::CreateSemaphore(0)),
+ listening_(OS::CreateSemaphore(0)) {
ASSERT(instance_ == NULL);
instance_ = this;
}
}
void Shutdown();
+ void WaitUntilListening();
private:
void Run();
Mutex* session_access_; // Mutex guarging access to session_.
DebuggerAgentSession* session_; // Current active session if any.
Semaphore* terminate_now_; // Semaphore to signal termination.
+ Semaphore* listening_;
static DebuggerAgent* instance_;
}
+void Debugger::WaitForAgent() {
+ if (agent_ != NULL)
+ agent_->WaitUntilListening();
+}
+
MessageImpl MessageImpl::NewEvent(DebugEvent event,
bool running,
Handle<JSObject> exec_state,
// Stop the debugger agent.
static void StopAgent();
+ // Blocks until the agent has started listening for connections
+ static void WaitForAgent();
+
// Unload the debugger if possible. Only called when no debugger is currently
// active.
static void UnloadDebugger();
// with the client connected.
ok = i::Debugger::StartAgent("test", kPort2);
CHECK(ok);
+ i::Debugger::WaitForAgent();
i::Socket* client = i::OS::CreateSocket();
ok = client->Connect("localhost", port2_str);
CHECK(ok);
// Create the server socket and bind it to the requested port.
server_ = OS::CreateSocket();
+ server_->SetReuseAddress(true);
CHECK(server_ != NULL);
ok = server_->Bind(port_);
CHECK(ok);