From e3b6ea62d65389fd7c719efdc8da98debdcbb247 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 5 Sep 2014 10:52:47 +0800 Subject: [PATCH] Send connect message if client is connected. --- atom/browser/node_debugger.cc | 17 +++++++++++++++-- atom/browser/node_debugger.h | 1 + 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/atom/browser/node_debugger.cc b/atom/browser/node_debugger.cc index 68ab20bb924a..55cc3e68f24f 100644 --- a/atom/browser/node_debugger.cc +++ b/atom/browser/node_debugger.cc @@ -24,6 +24,8 @@ namespace { // taken by gin, blink and node, using 2 is a safe option for now. const int kIsolateSlot = 2; +const char* kContentLength = "Content-Length"; + } // namespace NodeDebugger::NodeDebugger(v8::Isolate* isolate) @@ -105,13 +107,23 @@ void NodeDebugger::OnMessage(const std::string& message) { void NodeDebugger::SendMessage(const std::string& message) { if (accepted_socket_) { - std::string header = base::StringPrintf("Content-Length: %d\r\n\r\n", - static_cast(message.size())); + std::string header = base::StringPrintf( + "%s: %d\r\n\r\n", kContentLength, static_cast(message.size())); accepted_socket_->Send(header); accepted_socket_->Send(message); } } +void NodeDebugger::SendConnectMessage() { + accepted_socket_->Send(base::StringPrintf( + "Type: connect\r\n" + "V8-Version: %s\r\n" + "Protocol-Version: 1\r\n" + "Embedding-Host: %s\r\n" + "%s: 0\r\n", + v8::V8::GetVersion(), "Atom-Shell", kContentLength), true); +} + // static void NodeDebugger::DebugMessageHandler(const v8::Debug::Message& message) { NodeDebugger* self = static_cast( @@ -132,6 +144,7 @@ void NodeDebugger::DidAccept(net::StreamListenSocket* server, } accepted_socket_ = socket.Pass(); + SendConnectMessage(); } void NodeDebugger::DidRead(net::StreamListenSocket* socket, diff --git a/atom/browser/node_debugger.h b/atom/browser/node_debugger.h index bc2c392051d1..39273fa2dc2e 100644 --- a/atom/browser/node_debugger.h +++ b/atom/browser/node_debugger.h @@ -28,6 +28,7 @@ class NodeDebugger : public net::StreamListenSocket::Delegate { void CloseSession(); void OnMessage(const std::string& message); void SendMessage(const std::string& message); + void SendConnectMessage(); static void DebugMessageHandler(const v8::Debug::Message& message);