Skip to content

Commit 66ca795

Browse files
bnoordhuisBethGriggs
authored andcommitted
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: #26008Fixes: #13772 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Eugene Ostroukhov <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent dcf1310 commit 66ca795

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

‎src/inspector_socket_server.cc‎

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,6 @@ const char* MatchPathSegment(const char* path, const char* expected){
9393
returnnullptr;
9494
}
9595

96-
voidPrintDebuggerReadyMessage(const std::string& host,
97-
int port,
98-
const std::vector<std::string>& ids,
99-
FILE* out){
100-
if (out == nullptr){
101-
return;
102-
}
103-
for (const std::string& id : ids){
104-
fprintf(out, "Debugger listening on %s\n",
105-
FormatWsAddress(host, port, id, true).c_str());
106-
}
107-
fprintf(out, "For help, see: %s\n",
108-
"https://nodejs.org/en/docs/inspector");
109-
fflush(out);
110-
}
111-
11296
voidSendHttpResponse(InspectorSocket* socket, const std::string& response){
11397
constchar HEADERS[] = "HTTP/1.0 200 OK\r\n"
11498
"Content-Type: application/json; charset=UTF-8\r\n"
@@ -235,6 +219,25 @@ class ServerSocket{
235219
int port_ = -1;
236220
};
237221

222+
voidPrintDebuggerReadyMessage(
223+
const std::string& host,
224+
const std::vector<InspectorSocketServer::ServerSocketPtr>& server_sockets,
225+
const std::vector<std::string>& ids,
226+
FILE* out){
227+
if (out == nullptr){
228+
return;
229+
}
230+
for (constauto& server_socket : server_sockets){
231+
for (const std::string& id : ids){
232+
fprintf(out, "Debugger listening on %s\n",
233+
FormatWsAddress(host, server_socket->port(), id, true).c_str());
234+
}
235+
}
236+
fprintf(out, "For help, see: %s\n",
237+
"https://nodejs.org/en/docs/inspector");
238+
fflush(out);
239+
}
240+
238241
InspectorSocketServer::InspectorSocketServer(
239242
std::unique_ptr<SocketServerDelegate> delegate, uv_loop_t* loop,
240243
const std::string& host, int port, FILE* out)
@@ -276,7 +279,7 @@ void InspectorSocketServer::SessionTerminated(int session_id){
276279
if (connected_sessions_.empty()){
277280
if (was_attached && state_ == ServerState::kRunning
278281
&& !server_sockets_.empty()){
279-
PrintDebuggerReadyMessage(host_, server_sockets_[0]->port(),
282+
PrintDebuggerReadyMessage(host_, server_sockets_,
280283
delegate_->GetTargetIds(), out_);
281284
}
282285
if (state_ == ServerState::kStopped){
@@ -393,8 +396,7 @@ bool InspectorSocketServer::Start(){
393396
}
394397
delegate_.swap(delegate_holder);
395398
state_ = ServerState::kRunning;
396-
// getaddrinfo sorts the addresses, so the first port is most relevant.
397-
PrintDebuggerReadyMessage(host_, server_sockets_[0]->port(),
399+
PrintDebuggerReadyMessage(host_, server_sockets_,
398400
delegate_->GetTargetIds(), out_);
399401
returntrue;
400402
}

‎src/inspector_socket_server.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ class InspectorSocketServer{
7373
return server_sockets_.empty() && connected_sessions_.empty();
7474
}
7575

76-
private:
7776
staticvoidCloseServerSocket(ServerSocket*);
7877
using ServerSocketPtr = DeleteFnPtr<ServerSocket, CloseServerSocket>
7978

79+
private:
8080
voidSendListResponse(InspectorSocket* socket, const std::string& host,
8181
SocketSession* session);
8282
std::string GetFrontendURL(bool is_compat,

0 commit comments

Comments
(0)