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

src: reduce test_inspector_socket_server output #10537

Closed
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
39 changes: 24 additions & 15 deletions src/inspector_socket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,27 @@ void OnBufferAlloc(uv_handle_t* handle, size_t len, uv_buf_t* buf) {
buf->len = len;
}

void PrintDebuggerReadyMessage(int port, const std::vector<std::string>& ids) {
fprintf(stderr,
void PrintDebuggerReadyMessage(int port,
const std::vector<std::string>& ids,
FILE* out) {
if (out == NULL) {
return;
}
fprintf(out,
"Debugger listening on port %d.\n"
"Warning: This is an experimental feature "
"and could change at any time.\n",
port);
if (ids.size() == 1)
fprintf(stderr, "To start debugging, open the following URL in Chrome:\n");
fprintf(out, "To start debugging, open the following URL in Chrome:\n");
if (ids.size() > 1)
fprintf(stderr, "To start debugging, open the following URLs in Chrome:\n");
fprintf(out, "To start debugging, open the following URLs in Chrome:\n");
for (const std::string& id : ids) {
fprintf(stderr,
fprintf(out,
" chrome-devtools://devtools/bundled/inspector.html?"
"experiments=true&v8only=true&ws=%s\n", GetWsUrl(port, id).c_str());
}
fflush(stderr);
fflush(out);
}

void SendHttpResponse(InspectorSocket* socket, const std::string& response) {
Expand Down Expand Up @@ -207,12 +212,14 @@ class SocketSession {
};

InspectorSocketServer::InspectorSocketServer(SocketServerDelegate* delegate,
int port) : loop_(nullptr),
delegate_(delegate),
port_(port),
server_(uv_tcp_t()),
closer_(nullptr),
next_session_id_(0) { }
int port,
FILE* out) : loop_(nullptr),
delegate_(delegate),
port_(port),
server_(uv_tcp_t()),
closer_(nullptr),
next_session_id_(0),
out_(out) { }


// static
Expand Down Expand Up @@ -260,7 +267,7 @@ void InspectorSocketServer::SessionTerminated(int session_id) {
delegate_->EndSession(session_id);
if (connected_sessions_.empty() &&
uv_is_active(reinterpret_cast<uv_handle_t*>(&server_))) {
PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds());
PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds(), out_);
}
}

Expand Down Expand Up @@ -337,10 +344,12 @@ bool InspectorSocketServer::Start(uv_loop_t* loop) {
SocketConnectedCallback);
}
if (err == 0 && connected_sessions_.empty()) {
PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds());
PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds(), out_);
}
if (err != 0 && connected_sessions_.empty()) {
fprintf(stderr, "Unable to open devtools socket: %s\n", uv_strerror(err));
if (out_ != NULL) {
fprintf(out_, "Unable to open devtools socket: %s\n", uv_strerror(err));
}
uv_close(reinterpret_cast<uv_handle_t*>(&server_), nullptr);
return false;
}
Expand Down
5 changes: 4 additions & 1 deletion src/inspector_socket_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ class SocketServerDelegate {
class InspectorSocketServer {
public:
using ServerCallback = void (*)(InspectorSocketServer*);
InspectorSocketServer(SocketServerDelegate* delegate, int port);
InspectorSocketServer(SocketServerDelegate* delegate,
int port,
FILE* out = stderr);
bool Start(uv_loop_t* loop);
void Stop(ServerCallback callback);
void Send(int session_id, const std::string& message);
Expand Down Expand Up @@ -66,6 +68,7 @@ class InspectorSocketServer {
Closer* closer_;
std::map<int, SocketSession*> connected_sessions_;
int next_session_id_;
FILE* out_;

friend class SocketSession;
friend class Closer;
Expand Down
4 changes: 2 additions & 2 deletions test/cctest/test_inspector_socket_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ class SocketWrapper {
class ServerHolder {
public:
template <typename Delegate>
ServerHolder(Delegate* delegate, int port)
ServerHolder(Delegate* delegate, int port, FILE* out = NULL)
: closed(false), paused(false), sessions_terminated(false),
server_(delegate, port) {
server_(delegate, port, out) {
delegate->Connect(&server_);
}

Expand Down