diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2018-12-02 01:30:30 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2018-12-09 06:26:53 +0800 |
commit | 61a89630ee5664b1f909b310a016b522a6285521 (patch) | |
tree | 621fbd9bfd9c25a43c3ff9ae60251e5bfa2d366c /src/inspector_io.cc | |
parent | 22564b99cb9dff471f40c1ad0245d99b9224a207 (diff) | |
download | node-new-61a89630ee5664b1f909b310a016b522a6285521.tar.gz |
inspector: split the HostPort being used and the one parsed from CLI
Instead of using a shared pointer of the entire debug option set,
pass the parsed debug option to inspector classes by value because
they are set once the CLI argument parsing is done. Add another shared
pointer to HostPort being used by the inspector server, which is copied
from the one in the debug options initially. The port of the shared
HostPort is 9229 by default and can be specified as 0 initially but
will be set to the actual port of the server once it starts listening.
This makes the shared state clearer and makes it possible to use
`require('internal/options')` in JS land to query the CLI options
instead of using `process._breakFirstLine` and other underscored
properties of `process` since we are now certain that these
values should not be altered once the parsing is done and can be
passed around in copies without locks.
PR-URL: https://github.com/nodejs/node/pull/24772
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'src/inspector_io.cc')
-rw-r--r-- | src/inspector_io.cc | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/inspector_io.cc b/src/inspector_io.cc index da44d55d06..7686294b2e 100644 --- a/src/inspector_io.cc +++ b/src/inspector_io.cc @@ -242,9 +242,9 @@ class InspectorIoDelegate: public node::inspector::SocketServerDelegate { std::unique_ptr<InspectorIo> InspectorIo::Start( std::shared_ptr<MainThreadHandle> main_thread, const std::string& path, - std::shared_ptr<DebugOptions> options) { + std::shared_ptr<HostPort> host_port) { auto io = std::unique_ptr<InspectorIo>( - new InspectorIo(main_thread, path, options)); + new InspectorIo(main_thread, path, host_port)); if (io->request_queue_->Expired()) { // Thread is not running return nullptr; } @@ -253,9 +253,12 @@ std::unique_ptr<InspectorIo> InspectorIo::Start( InspectorIo::InspectorIo(std::shared_ptr<MainThreadHandle> main_thread, const std::string& path, - std::shared_ptr<DebugOptions> options) - : main_thread_(main_thread), options_(options), - thread_(), script_name_(path), id_(GenerateID()) { + std::shared_ptr<HostPort> host_port) + : main_thread_(main_thread), + host_port_(host_port), + thread_(), + script_name_(path), + id_(GenerateID()) { Mutex::ScopedLock scoped_lock(thread_start_lock_); CHECK_EQ(uv_thread_create(&thread_, InspectorIo::ThreadMain, this), 0); thread_start_condition_.Wait(scoped_lock); @@ -287,16 +290,17 @@ void InspectorIo::ThreadMain() { std::unique_ptr<InspectorIoDelegate> delegate( new InspectorIoDelegate(queue, main_thread_, id_, script_path, script_name_)); - InspectorSocketServer server(std::move(delegate), &loop, - options_->host().c_str(), - options_->port()); + InspectorSocketServer server(std::move(delegate), + &loop, + host_port_->host().c_str(), + host_port_->port()); request_queue_ = queue->handle(); // Its lifetime is now that of the server delegate queue.reset(); { Mutex::ScopedLock scoped_lock(thread_start_lock_); if (server.Start()) { - port_ = server.Port(); + host_port_->set_port(server.Port()); } thread_start_condition_.Broadcast(scoped_lock); } |