| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 06a8243 commit f0de955
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -74,22 +74,27 @@ 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, const std::vector<std::string>& ids) { | ||
| 78 | - fprintf(stderr, | ||
| 77 | + void PrintDebuggerReadyMessage(int port, | ||
| 78 | + const std::vector<std::string>& ids, | ||
| 79 | + FILE* out) { | ||
| 80 | + if (out == NULL) { | ||
| 81 | + return; | ||
| 82 | + } | ||
| 83 | + fprintf(out, | ||
| 79 | 84 | "Debugger listening on port %d.\n" | |
| 80 | 85 | "Warning: This is an experimental feature " | |
| 81 | 86 | "and could change at any time.\n", | |
| 82 | 87 | port); | |
| 83 | 88 | if (ids.size() == 1) | |
| 84 | - fprintf(stderr, "To start debugging, open the following URL in Chrome:\n"); | ||
| 89 | + fprintf(out, "To start debugging, open the following URL in Chrome:\n"); | ||
| 85 | 90 | if (ids.size() > 1) | |
| 86 | - fprintf(stderr, "To start debugging, open the following URLs in Chrome:\n"); | ||
| 91 | + fprintf(out, "To start debugging, open the following URLs in Chrome:\n"); | ||
| 87 | 92 | for (const std::string& id : ids) { | |
| 88 | - fprintf(stderr, | ||
| 93 | + fprintf(out, | ||
| 89 | 94 | " chrome-devtools://devtools/bundled/inspector.html?" | |
| 90 | 95 | "experiments=true&v8only=true&ws=%s\n", GetWsUrl(port, id).c_str()); | |
| 91 | 96 | } | |
| 92 | - fflush(stderr); | ||
| 97 | + fflush(out); | ||
| 93 | 98 | } | |
| 94 | 99 | ||
| 95 | 100 | void SendHttpResponse(InspectorSocket* socket, const std::string& response) { | |
@@ -207,12 +212,14 @@ class SocketSession { | |||
| 207 | 212 | }; | |
| 208 | 213 | ||
| 209 | 214 | InspectorSocketServer::InspectorSocketServer(SocketServerDelegate* delegate, | |
| 210 | - int port) : loop_(nullptr), | ||
| 211 | - delegate_(delegate), | ||
| 212 | - port_(port), | ||
| 213 | - server_(uv_tcp_t()), | ||
| 214 | - closer_(nullptr), | ||
| 215 | - next_session_id_(0) { } | ||
| 215 | + int port, | ||
| 216 | + FILE* out) : loop_(nullptr), | ||
| 217 | + delegate_(delegate), | ||
| 218 | + port_(port), | ||
| 219 | + server_(uv_tcp_t()), | ||
| 220 | + closer_(nullptr), | ||
| 221 | + next_session_id_(0), | ||
| 222 | + out_(out) { } | ||
| 216 | 223 | ||
| 217 | 224 | ||
| 218 | 225 | // static | |
@@ -260,7 +267,7 @@ void InspectorSocketServer::SessionTerminated(int session_id) { | |||
| 260 | 267 | delegate_->EndSession(session_id); | |
| 261 | 268 | if (connected_sessions_.empty() && | |
| 262 | 269 | uv_is_active(reinterpret_cast<uv_handle_t*>(&server_))) { | |
| 263 | - PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds()); | ||
| 270 | + PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds(), out_); | ||
| 264 | 271 | } | |
| 265 | 272 | } | |
| 266 | 273 | ||
@@ -337,10 +344,12 @@ bool InspectorSocketServer::Start(uv_loop_t* loop) { | |||
| 337 | 344 | SocketConnectedCallback); | |
| 338 | 345 | } | |
| 339 | 346 | if (err == 0 && connected_sessions_.empty()) { | |
| 340 | - PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds()); | ||
| 347 | + PrintDebuggerReadyMessage(port_, delegate_->GetTargetIds(), out_); | ||
| 341 | 348 | } | |
| 342 | 349 | if (err != 0 && connected_sessions_.empty()) { | |
| 343 | - fprintf(stderr, "Unable to open devtools socket: %s\n", uv_strerror(err)); | ||
| 350 | + if (out_ != NULL) { | ||
| 351 | + fprintf(out_, "Unable to open devtools socket: %s\n", uv_strerror(err)); | ||
| 352 | + } | ||
| 344 | 353 | uv_close(reinterpret_cast<uv_handle_t*>(&server_), nullptr); | |
| 345 | 354 | return false; | |
| 346 | 355 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,7 +32,9 @@ class SocketServerDelegate { | |||
| 32 | 32 | class InspectorSocketServer { | |
| 33 | 33 | public: | |
| 34 | 34 | using ServerCallback = void (*)(InspectorSocketServer*); | |
| 35 | - InspectorSocketServer(SocketServerDelegate* delegate, int port); | ||
| 35 | + InspectorSocketServer(SocketServerDelegate* delegate, | ||
| 36 | + int port, | ||
| 37 | + FILE* out = stderr); | ||
| 36 | 38 | bool Start(uv_loop_t* loop); | |
| 37 | 39 | void Stop(ServerCallback callback); | |
| 38 | 40 | void Send(int session_id, const std::string& message); | |
@@ -66,6 +68,7 @@ class InspectorSocketServer { | |||
| 66 | 68 | Closer* closer_; | |
| 67 | 69 | std::map<int, SocketSession*> connected_sessions_; | |
| 68 | 70 | int next_session_id_; | |
| 71 | + FILE* out_; | ||
| 69 | 72 | ||
| 70 | 73 | friend class SocketSession; | |
| 71 | 74 | friend class Closer; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -300,9 +300,9 @@ class SocketWrapper { | |||
| 300 | 300 | class ServerHolder { | |
| 301 | 301 | public: | |
| 302 | 302 | template <typename Delegate> | |
| 303 | - ServerHolder(Delegate* delegate, int port) | ||
| 303 | + ServerHolder(Delegate* delegate, int port, FILE* out = NULL) | ||
| 304 | 304 | : closed(false), paused(false), sessions_terminated(false), | |
| 305 | - server_(delegate, port) { | ||
| 305 | + server_(delegate, port, out) { | ||
| 306 | 306 | delegate->Connect(&server_); | |
| 307 | 307 | } | |
| 308 | 308 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments