| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 63f4302 commit 9a111e7
5 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -556,9 +556,10 @@ void AgentImpl::WorkerRunIO() { | |||
| 556 | 556 | } | |
| 557 | 557 | InspectorAgentDelegate delegate(this, script_path, script_name_, wait_); | |
| 558 | 558 | delegate_ = &delegate; | |
| 559 | - InspectorSocketServer server(&delegate, options_.port()); | ||
| 559 | + InspectorSocketServer server(&delegate, | ||
| 560 | + options_.host_name(), | ||
| 561 | + options_.port()); | ||
| 560 | 562 | if (!server.Start(&child_loop_)) { | |
| 561 | - fprintf(stderr, "Unable to open devtools socket: %s\n", uv_strerror(err)); | ||
| 562 | 563 | state_ = State::kError; // Safe, main thread is waiting on semaphore | |
| 563 | 564 | uv_close(reinterpret_cast<uv_handle_t*>(&io_thread_req_), nullptr); | |
| 564 | 565 | uv_loop_close(&child_loop_); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,9 +24,9 @@ void Escape(std::string* string) { | |||
| 24 | 24 | } | |
| 25 | 25 | } | |
| 26 | 26 | ||
| 27 | - std::string GetWsUrl(int port, const std::string& id) { | ||
| 27 | + std::string GetWsUrl(const std::string& host, int port, const std::string& id) { | ||
| 28 | 28 | char buf[1024]; | |
| 29 | - snprintf(buf, sizeof(buf), "127.0.0.1:%d/%s", port, id.c_str()); | ||
| 29 | + snprintf(buf, sizeof(buf), "%s:%d/%s", host.c_str(), port, id.c_str()); | ||
| 30 | 30 | return buf; | |
| 31 | 31 | } | |
| 32 | 32 | ||
@@ -74,7 +74,8 @@ void OnBufferAlloc(uv_handle_t* handle, size_t len, uv_buf_t* buf) { | |||
| 74 | 74 | buf->len = len; | |
| 75 | 75 | } | |
| 76 | 76 | ||
| 77 | - void PrintDebuggerReadyMessage(int port, | ||
| 77 | + void PrintDebuggerReadyMessage(const std::string& host, | ||
| 78 | + int port, | ||
| 78 | 79 | const std::vector<std::string>& ids, | |
| 79 | 80 | FILE* out) { | |
| 80 | 81 | if (out == NULL) { | |
@@ -92,7 +93,8 @@ void PrintDebuggerReadyMessage(int port, | |||
| 92 | 93 | for (const std::string& id : ids) { | |
| 93 | 94 | fprintf(out, | |
| 94 | 95 | " chrome-devtools://devtools/bundled/inspector.html?" | |
| 95 | - "experiments=true&v8only=true&ws=%s\n", GetWsUrl(port, id).c_str()); | ||
| 96 | + "experiments=true&v8only=true&ws=%s\n", | ||
| 97 | + GetWsUrl(host, port, id).c_str()); | ||
| 96 | 98 | } | |
| 97 | 99 | fflush(out); | |
| 98 | 100 | } | |
@@ -229,9 +231,11 @@ class SocketSession { | |||
| 229 | 231 | }; | |
| 230 | 232 | ||
| 231 | 233 | InspectorSocketServer::InspectorSocketServer(SocketServerDelegate* delegate, | |
| 234 | + const std::string& host, | ||
| 232 | 235 | int port, | |
| 233 | 236 | FILE* out) : loop_(nullptr), | |
| 234 | 237 | delegate_(delegate), | |
| 238 | + host_(host), | ||
| 235 | 239 | port_(port), | |
| 236 | 240 | server_(uv_tcp_t()), | |
| 237 | 241 | closer_(nullptr), | |
@@ -284,7 +288,7 @@ void InspectorSocketServer::SessionTerminated(int session_id) { | |||
| 284 | 288 | delegate_->EndSession(session_id); | |
| 285 | 289 | if (connected_sessions_.empty() && | |
| 286 | 290 | uv_is_active(reinterpret_cast<uv_handle_t*>(&server_))) { | |
| 287 | - PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds(), out_); | ||
| 291 | + PrintDebuggerReadyMessage(host_, port_, delegate_->GetTargetIds(), out_); | ||
| 288 | 292 | } | |
| 289 | 293 | } | |
| 290 | 294 | ||
@@ -337,7 +341,7 @@ void InspectorSocketServer::SendListResponse(InspectorSocket* socket) { | |||
| 337 | 341 | } | |
| 338 | 342 | } | |
| 339 | 343 | if (!connected) { | |
| 340 | - std::string address = GetWsUrl(port_, id); | ||
| 344 | + std::string address = GetWsUrl(host_, port_, id); | ||
| 341 | 345 | std::ostringstream frontend_url; | |
| 342 | 346 | frontend_url << "chrome-devtools://devtools/bundled"; | |
| 343 | 347 | frontend_url << "/inspector.html?experiments=true&v8only=true&ws="; | |
@@ -353,7 +357,7 @@ bool InspectorSocketServer::Start(uv_loop_t* loop) { | |||
| 353 | 357 | loop_ = loop; | |
| 354 | 358 | sockaddr_in addr; | |
| 355 | 359 | uv_tcp_init(loop_, &server_); | |
| 356 | - uv_ip4_addr("0.0.0.0", port_, &addr); | ||
| 360 | + uv_ip4_addr(host_.c_str(), port_, &addr); | ||
| 357 | 361 | int err = uv_tcp_bind(&server_, | |
| 358 | 362 | reinterpret_cast<const struct sockaddr*>(&addr), 0); | |
| 359 | 363 | if (err == 0) | |
@@ -363,11 +367,13 @@ bool InspectorSocketServer::Start(uv_loop_t* loop) { | |||
| 363 | 367 | SocketConnectedCallback); | |
| 364 | 368 | } | |
| 365 | 369 | if (err == 0 && connected_sessions_.empty()) { | |
| 366 | - PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds(), out_); | ||
| 370 | + PrintDebuggerReadyMessage(host_, port_, delegate_->GetTargetIds(), out_); | ||
| 367 | 371 | } | |
| 368 | 372 | if (err != 0 && connected_sessions_.empty()) { | |
| 369 | 373 | if (out_ != NULL) { | |
| 370 | - fprintf(out_, "Unable to open devtools socket: %s\n", uv_strerror(err)); | ||
| 374 | + fprintf(out_, "Starting inspector on %s:%d failed: %s\n", | ||
| 375 | + host_.c_str(), port_, uv_strerror(err)); | ||
| 376 | + fflush(out_); | ||
| 371 | 377 | } | |
| 372 | 378 | uv_close(reinterpret_cast<uv_handle_t*>(&server_), nullptr); | |
| 373 | 379 | return false; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ class InspectorSocketServer { | |||
| 33 | 33 | public: | |
| 34 | 34 | using ServerCallback = void (*)(InspectorSocketServer*); | |
| 35 | 35 | InspectorSocketServer(SocketServerDelegate* delegate, | |
| 36 | + const std::string& host, | ||
| 36 | 37 | int port, | |
| 37 | 38 | FILE* out = stderr); | |
| 38 | 39 | bool Start(uv_loop_t* loop); | |
@@ -65,6 +66,7 @@ class InspectorSocketServer { | |||
| 65 | 66 | ||
| 66 | 67 | uv_loop_t* loop_; | |
| 67 | 68 | SocketServerDelegate* const delegate_; | |
| 69 | + const std::string host_; | ||
| 68 | 70 | int port_; | |
| 69 | 71 | std::string path_; | |
| 70 | 72 | uv_tcp_t server_; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4331,7 +4331,7 @@ inline int Start(Isolate* isolate, IsolateData* isolate_data, | |||
| 4331 | 4331 | if (debug_enabled) { | |
| 4332 | 4332 | const char* path = argc > 1 ? argv[1] : nullptr; | |
| 4333 | 4333 | StartDebug(&env, path, debug_options); | |
| 4334 | - if (debug_options.debugger_enabled() && !debugger_running) | ||
| 4334 | + if (!debugger_running) | ||
| 4335 | 4335 | return 12; // Signal internal error. | |
| 4336 | 4336 | } | |
| 4337 | 4337 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,8 @@ | |||
| 8 | 8 | ||
| 9 | 9 | static uv_loop_t loop; | |
| 10 | 10 | ||
| 11 | + static const char HOST[] = "127.0.0.1"; | ||
| 12 | + | ||
| 11 | 13 | static const char CLIENT_CLOSE_FRAME[] = "\x88\x80\x2D\x0E\x1E\xFA"; | |
| 12 | 14 | static const char SERVER_CLOSE_FRAME[] = "\x88\x00"; | |
| 13 | 15 | ||
@@ -249,7 +251,7 @@ class SocketWrapper { | |||
| 249 | 251 | } | |
| 250 | 252 | ||
| 251 | 253 | static void Connected_(uv_connect_t* connect, int status) { | |
| 252 | - EXPECT_EQ(0, status); | ||
| 254 | + EXPECT_EQ(0, status) << "Unable to connect: " << uv_strerror(status); | ||
| 253 | 255 | SocketWrapper* wrapper = | |
| 254 | 256 | node::ContainerOf(&SocketWrapper::connect_, connect); | |
| 255 | 257 | wrapper->connected_ = true; | |
@@ -301,7 +303,7 @@ class ServerHolder { | |||
| 301 | 303 | template <typename Delegate> | |
| 302 | 304 | ServerHolder(Delegate* delegate, int port, FILE* out = NULL) | |
| 303 | 305 | : closed(false), paused(false), sessions_terminated(false), | |
| 304 | - server_(delegate, port, out) { | ||
| 306 | + server_(delegate, HOST, port, out) { | ||
| 305 | 307 | delegate->Connect(&server_); | |
| 306 | 308 | } | |
| 307 | 309 | ||
@@ -362,7 +364,7 @@ class ServerDelegateNoTargets : public SocketServerDelegate { | |||
| 362 | 364 | static void TestHttpRequest(int port, const std::string& path, | |
| 363 | 365 | const std::string& expected_body) { | |
| 364 | 366 | SocketWrapper socket(&loop); | |
| 365 | - socket.Connect("0.0.0.0", port); | ||
| 367 | + socket.Connect(HOST, port); | ||
| 366 | 368 | socket.TestHttpRequest(path, expected_body); | |
| 367 | 369 | socket.Close(); | |
| 368 | 370 | } | |
@@ -385,7 +387,7 @@ TEST_F(InspectorSocketServerTest, InspectorSessions) { | |||
| 385 | 387 | ||
| 386 | 388 | SocketWrapper well_behaved_socket(&loop); | |
| 387 | 389 | // Regular connection | |
| 388 | - well_behaved_socket.Connect("0.0.0.0", server.port()); | ||
| 390 | + well_behaved_socket.Connect(HOST, server.port()); | ||
| 389 | 391 | well_behaved_socket.Write(WsHandshakeRequest(MAIN_TARGET_ID)); | |
| 390 | 392 | well_behaved_socket.Expect(WS_HANDSHAKE_RESPONSE); | |
| 391 | 393 | ||
@@ -408,7 +410,7 @@ TEST_F(InspectorSocketServerTest, InspectorSessions) { | |||
| 408 | 410 | ||
| 409 | 411 | // Declined connection | |
| 410 | 412 | SocketWrapper declined_target_socket(&loop); | |
| 411 | - declined_target_socket.Connect("127.0.0.1", server.port()); | ||
| 413 | + declined_target_socket.Connect(HOST, server.port()); | ||
| 412 | 414 | declined_target_socket.Write(WsHandshakeRequest(UNCONNECTABLE_TARGET_ID)); | |
| 413 | 415 | declined_target_socket.Expect("HTTP/1.0 400 Bad Request"); | |
| 414 | 416 | declined_target_socket.ExpectEOF(); | |
@@ -417,7 +419,7 @@ TEST_F(InspectorSocketServerTest, InspectorSessions) { | |||
| 417 | 419 | ||
| 418 | 420 | // Bogus target - start session callback should not even be invoked | |
| 419 | 421 | SocketWrapper bogus_target_socket(&loop); | |
| 420 | - bogus_target_socket.Connect("127.0.0.1", server.port()); | ||
| 422 | + bogus_target_socket.Connect(HOST, server.port()); | ||
| 421 | 423 | bogus_target_socket.Write(WsHandshakeRequest("bogus_target")); | |
| 422 | 424 | bogus_target_socket.Expect("HTTP/1.0 400 Bad Request"); | |
| 423 | 425 | bogus_target_socket.ExpectEOF(); | |
@@ -426,7 +428,7 @@ TEST_F(InspectorSocketServerTest, InspectorSessions) { | |||
| 426 | 428 | ||
| 427 | 429 | // Drop connection (no proper close frames) | |
| 428 | 430 | SocketWrapper dropped_connection_socket(&loop); | |
| 429 | - dropped_connection_socket.Connect("127.0.0.1", server.port()); | ||
| 431 | + dropped_connection_socket.Connect(HOST, server.port()); | ||
| 430 | 432 | dropped_connection_socket.Write(WsHandshakeRequest(MAIN_TARGET_ID)); | |
| 431 | 433 | dropped_connection_socket.Expect(WS_HANDSHAKE_RESPONSE); | |
| 432 | 434 | ||
@@ -440,7 +442,7 @@ TEST_F(InspectorSocketServerTest, InspectorSessions) { | |||
| 440 | 442 | ||
| 441 | 443 | // Reconnect regular connection | |
| 442 | 444 | SocketWrapper stays_till_termination_socket(&loop); | |
| 443 | - stays_till_termination_socket.Connect("127.0.0.1", server.port()); | ||
| 445 | + stays_till_termination_socket.Connect(HOST, server.port()); | ||
| 444 | 446 | stays_till_termination_socket.Write(WsHandshakeRequest(MAIN_TARGET_ID)); | |
| 445 | 447 | stays_till_termination_socket.Expect(WS_HANDSHAKE_RESPONSE); | |
| 446 | 448 | ||
@@ -484,7 +486,7 @@ TEST_F(InspectorSocketServerTest, ServerWithoutTargets) { | |||
| 484 | 486 | ||
| 485 | 487 | // Declined connection | |
| 486 | 488 | SocketWrapper socket(&loop); | |
| 487 | - socket.Connect("0.0.0.0", server.port()); | ||
| 489 | + socket.Connect(HOST, server.port()); | ||
| 488 | 490 | socket.Write(WsHandshakeRequest(UNCONNECTABLE_TARGET_ID)); | |
| 489 | 491 | socket.Expect("HTTP/1.0 400 Bad Request"); | |
| 490 | 492 | socket.ExpectEOF(); | |
@@ -512,7 +514,7 @@ TEST_F(InspectorSocketServerTest, StoppingServerDoesNotKillConnections) { | |||
| 512 | 514 | ServerHolder server(&delegate, 0); | |
| 513 | 515 | ASSERT_TRUE(server->Start(&loop)); | |
| 514 | 516 | SocketWrapper socket1(&loop); | |
| 515 | - socket1.Connect("0.0.0.0", server.port()); | ||
| 517 | + socket1.Connect(HOST, server.port()); | ||
| 516 | 518 | socket1.TestHttpRequest("/json/list", "[ ]"); | |
| 517 | 519 | server->Stop(ServerHolder::CloseCallback); | |
| 518 | 520 | SPIN_WHILE(!server.closed); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments