Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inspector: print all listening addresses #26008

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 21 additions & 19 deletions src/inspector_socket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/inspector_socket_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ class InspectorSocketServer {
return server_sockets_.empty() && connected_sessions_.empty();
}

private:
static void CloseServerSocket(ServerSocket*);
using ServerSocketPtr = DeleteFnPtr<ServerSocket, CloseServerSocket>;

private:
void SendListResponse(InspectorSocket* socket, const std::string& host,
SocketSession* session);
std::string GetFrontendURL(bool is_compat,
Expand Down