Send connect message if client is connected.

This commit is contained in:
Cheng Zhao 2014-09-05 10:52:47 +08:00
parent 3795cc58b0
commit e3b6ea62d6
2 changed files with 16 additions and 2 deletions

View file

@ -24,6 +24,8 @@ namespace {
// taken by gin, blink and node, using 2 is a safe option for now. // taken by gin, blink and node, using 2 is a safe option for now.
const int kIsolateSlot = 2; const int kIsolateSlot = 2;
const char* kContentLength = "Content-Length";
} // namespace } // namespace
NodeDebugger::NodeDebugger(v8::Isolate* isolate) NodeDebugger::NodeDebugger(v8::Isolate* isolate)
@ -105,13 +107,23 @@ void NodeDebugger::OnMessage(const std::string& message) {
void NodeDebugger::SendMessage(const std::string& message) { void NodeDebugger::SendMessage(const std::string& message) {
if (accepted_socket_) { if (accepted_socket_) {
std::string header = base::StringPrintf("Content-Length: %d\r\n\r\n", std::string header = base::StringPrintf(
static_cast<int>(message.size())); "%s: %d\r\n\r\n", kContentLength, static_cast<int>(message.size()));
accepted_socket_->Send(header); accepted_socket_->Send(header);
accepted_socket_->Send(message); 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 // static
void NodeDebugger::DebugMessageHandler(const v8::Debug::Message& message) { void NodeDebugger::DebugMessageHandler(const v8::Debug::Message& message) {
NodeDebugger* self = static_cast<NodeDebugger*>( NodeDebugger* self = static_cast<NodeDebugger*>(
@ -132,6 +144,7 @@ void NodeDebugger::DidAccept(net::StreamListenSocket* server,
} }
accepted_socket_ = socket.Pass(); accepted_socket_ = socket.Pass();
SendConnectMessage();
} }
void NodeDebugger::DidRead(net::StreamListenSocket* socket, void NodeDebugger::DidRead(net::StreamListenSocket* socket,

View file

@ -28,6 +28,7 @@ class NodeDebugger : public net::StreamListenSocket::Delegate {
void CloseSession(); void CloseSession();
void OnMessage(const std::string& message); void OnMessage(const std::string& message);
void SendMessage(const std::string& message); void SendMessage(const std::string& message);
void SendConnectMessage();
static void DebugMessageHandler(const v8::Debug::Message& message); static void DebugMessageHandler(const v8::Debug::Message& message);