Start a new debugger thread to listen for commands.

This commit is contained in:
Cheng Zhao 2014-09-04 21:06:31 +08:00
parent ca881c5aaf
commit a584ca3678
2 changed files with 40 additions and 31 deletions

View file

@ -7,24 +7,18 @@
#include <string>
#include "atom/common/atom_version.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
#include "v8/include/v8.h"
#include "net/socket/stream_socket.h"
#include "net/socket/tcp_server_socket.h"
#include "v8/include/v8-debug.h"
#include "atom/common/node_includes.h"
namespace atom {
// static
uv_async_t NodeDebugger::dispatch_debug_messages_async_;
NodeDebugger::NodeDebugger() {
uv_async_init(uv_default_loop(),
&dispatch_debug_messages_async_,
DispatchDebugMessagesInMainThread);
uv_unref(reinterpret_cast<uv_handle_t*>(&dispatch_debug_messages_async_));
NodeDebugger::NodeDebugger()
: thread_("NodeDebugger"),
weak_factory_(this) {
bool use_debug_agent = false;
int port = 5858;
bool wait_for_connection = false;
@ -44,26 +38,32 @@ NodeDebugger::NodeDebugger() {
if (use_debug_agent) {
if (!port_str.empty())
base::StringToInt(port_str, &port);
#if 0
v8::Debug::EnableAgent("atom-shell " ATOM_VERSION, port,
wait_for_connection);
v8::Debug::SetDebugMessageDispatchHandler(DispatchDebugMessagesInMsgThread,
false);
#endif
if (!thread_.Start()) {
LOG(ERROR) << "Unable to start debugger thread";
return;
}
net::IPAddressNumber ip_number;
if (!net::ParseIPLiteralToNumber("127.0.0.1", &ip_number)) {
LOG(ERROR) << "Unable to convert ip address";
return;
}
server_socket_.reset(new net::TCPServerSocket(NULL, net::NetLog::Source()));
server_socket_->Listen(net::IPEndPoint(ip_number, port), 1);
thread_.message_loop()->PostTask(
FROM_HERE,
base::Bind(&NodeDebugger::DoAcceptLoop, weak_factory_.GetWeakPtr()));
}
}
NodeDebugger::~NodeDebugger() {
thread_.Stop();
}
// static
void NodeDebugger::DispatchDebugMessagesInMainThread(uv_async_t* handle) {
v8::Debug::ProcessDebugMessages();
}
// static
void NodeDebugger::DispatchDebugMessagesInMsgThread() {
uv_async_send(&dispatch_debug_messages_async_);
void NodeDebugger::DoAcceptLoop() {
}
} // namespace atom

View file

@ -5,8 +5,14 @@
#ifndef ATOM_BROWSER_NODE_DEBUGGER_H_
#define ATOM_BROWSER_NODE_DEBUGGER_H_
#include "base/basictypes.h"
#include "vendor/node/deps/uv/include/uv.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/thread.h"
namespace net {
class StreamSocket;
class TCPServerSocket;
}
namespace atom {
@ -17,10 +23,13 @@ class NodeDebugger {
virtual ~NodeDebugger();
private:
static void DispatchDebugMessagesInMainThread(uv_async_t* handle);
static void DispatchDebugMessagesInMsgThread();
void DoAcceptLoop();
static uv_async_t dispatch_debug_messages_async_;
base::Thread thread_;
scoped_ptr<net::TCPServerSocket> server_socket_;
scoped_ptr<net::StreamSocket> accepted_socket_;
base::WeakPtrFactory<NodeDebugger> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(NodeDebugger);
};