summaryrefslogtreecommitdiff
path: root/src/inspector_socket_server.cc
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2019-02-08 14:34:43 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-03-04 02:19:27 +0100
commitdf67cd0fef65f8988e5189769e6e6fc3fb0aa716 (patch)
treebad64b08153f5da5cea835bb2c7c2bc2bfdfa063 /src/inspector_socket_server.cc
parent000788ec23c584c3ded71dae5cab057de0f416bd (diff)
downloadandroid-node-v8-df67cd0fef65f8988e5189769e6e6fc3fb0aa716.tar.gz
android-node-v8-df67cd0fef65f8988e5189769e6e6fc3fb0aa716.tar.bz2
android-node-v8-df67cd0fef65f8988e5189769e6e6fc3fb0aa716.zip
inspector: print all listening addresses
Some hostnames have multiple interfaces. Before this commit, the inspector only printed the first one. Now, it prints them all. No test. I can't think of a reliable way to test this on the CI matrix. PR-URL: https://github.com/nodejs/node/pull/26008 Fixes: https://github.com/nodejs/node/issues/13772 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'src/inspector_socket_server.cc')
-rw-r--r--src/inspector_socket_server.cc40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/inspector_socket_server.cc b/src/inspector_socket_server.cc
index 7ddbcd38fe..5f1bdbc1e6 100644
--- a/src/inspector_socket_server.cc
+++ b/src/inspector_socket_server.cc
@@ -93,22 +93,6 @@ const char* MatchPathSegment(const char* path, const char* expected) {
return nullptr;
}
-void PrintDebuggerReadyMessage(const std::string& host,
- int port,
- const std::vector<std::string>& ids,
- FILE* out) {
- if (out == nullptr) {
- return;
- }
- for (const std::string& id : ids) {
- fprintf(out, "Debugger listening on %s\n",
- FormatWsAddress(host, port, id, true).c_str());
- }
- fprintf(out, "For help, see: %s\n",
- "https://nodejs.org/en/docs/inspector");
- fflush(out);
-}
-
void SendHttpResponse(InspectorSocket* socket, const std::string& response) {
const char HEADERS[] = "HTTP/1.0 200 OK\r\n"
"Content-Type: application/json; charset=UTF-8\r\n"
@@ -235,6 +219,25 @@ class ServerSocket {
int port_ = -1;
};
+void PrintDebuggerReadyMessage(
+ const std::string& host,
+ const std::vector<InspectorSocketServer::ServerSocketPtr>& server_sockets,
+ const std::vector<std::string>& ids,
+ FILE* out) {
+ if (out == nullptr) {
+ return;
+ }
+ for (const auto& server_socket : server_sockets) {
+ for (const std::string& id : ids) {
+ fprintf(out, "Debugger listening on %s\n",
+ FormatWsAddress(host, server_socket->port(), id, true).c_str());
+ }
+ }
+ fprintf(out, "For help, see: %s\n",
+ "https://nodejs.org/en/docs/inspector");
+ fflush(out);
+}
+
InspectorSocketServer::InspectorSocketServer(
std::unique_ptr<SocketServerDelegate> delegate, uv_loop_t* loop,
const std::string& host, int port, FILE* out)
@@ -276,7 +279,7 @@ void InspectorSocketServer::SessionTerminated(int session_id) {
if (connected_sessions_.empty()) {
if (was_attached && state_ == ServerState::kRunning
&& !server_sockets_.empty()) {
- PrintDebuggerReadyMessage(host_, server_sockets_[0]->port(),
+ PrintDebuggerReadyMessage(host_, server_sockets_,
delegate_->GetTargetIds(), out_);
}
if (state_ == ServerState::kStopped) {
@@ -393,8 +396,7 @@ bool InspectorSocketServer::Start() {
}
delegate_.swap(delegate_holder);
state_ = ServerState::kRunning;
- // getaddrinfo sorts the addresses, so the first port is most relevant.
- PrintDebuggerReadyMessage(host_, server_sockets_[0]->port(),
+ PrintDebuggerReadyMessage(host_, server_sockets_,
delegate_->GetTargetIds(), out_);
return true;
}