diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2020-03-16 07:22:33 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-16 07:22:33 -0400 |
commit | 58ff35f5bf26994b519d1591b24aca903b051d8c (patch) | |
tree | 6db4c4341ad7c4d2f8152798d762a97dd1a3fc9d /components | |
parent | e8e0b702662704572e7c04a78d0ab9e023a0ad5c (diff) | |
parent | 94db0d61cb6a92e36b2047ec6c643b3fa4734789 (diff) | |
download | servo-58ff35f5bf26994b519d1591b24aca903b051d8c.tar.gz servo-58ff35f5bf26994b519d1591b24aca903b051d8c.zip |
Auto merge of #25941 - kunalmohan:25907-DevtoolsServer, r=paulrouget
Add support for launching devtools server on random port
In case the default port(6000) or the port specified by user for
devtools server is already taken, random port will be assigned to
it which is reported to the embedding layer for display to user.
r?@jdm @paulrouget
<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25907 (GitHub issue number if applicable)
<!-- Either: -->
- [ ] There are tests for these changes OR
- [ ] These changes do not require tests because ___
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
Diffstat (limited to 'components')
-rw-r--r-- | components/config/opts.rs | 10 | ||||
-rw-r--r-- | components/devtools/lib.rs | 15 | ||||
-rw-r--r-- | components/embedder_traits/lib.rs | 3 |
3 files changed, 20 insertions, 8 deletions
diff --git a/components/config/opts.rs b/components/config/opts.rs index 9bdd7bc9061..796bd7d6b96 100644 --- a/components/config/opts.rs +++ b/components/config/opts.rs @@ -653,12 +653,7 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR "Start remote debugger server on port", "2794", ); - opts.optflagopt( - "", - "devtools", - "Start remote devtools server on port", - "6000", - ); + opts.optflagopt("", "devtools", "Start remote devtools server on port", "0"); opts.optflagopt( "", "webdriver", @@ -886,7 +881,8 @@ pub fn from_cmdline_args(mut opts: Options, args: &[String]) -> ArgumentParsingR }) }); - let devtools_port = opt_match.opt_default("devtools", "6000").map(|port| { + // Set default port 0 for a random port to be selected. + let devtools_port = opt_match.opt_default("devtools", "0").map(|port| { port.parse() .unwrap_or_else(|err| args_fail(&format!("Error parsing option: --devtools ({})", err))) }); diff --git a/components/devtools/lib.rs b/components/devtools/lib.rs index a33294f078f..661d6ac94e1 100644 --- a/components/devtools/lib.rs +++ b/components/devtools/lib.rs @@ -154,7 +154,20 @@ fn run_server( port: u16, embedder: EmbedderProxy, ) { - let listener = TcpListener::bind(&("0.0.0.0", port)).unwrap(); + let bound = TcpListener::bind(&("0.0.0.0", port)).ok().and_then(|l| { + l.local_addr() + .map(|addr| addr.port()) + .ok() + .map(|port| (l, port)) + }); + + let port = bound.as_ref().map(|(_, port)| *port).ok_or(()); + embedder.send((None, EmbedderMsg::OnDevtoolsStarted(port))); + + let listener = match bound { + Some((l, _)) => l, + None => return, + }; let mut registry = ActorRegistry::new(); diff --git a/components/embedder_traits/lib.rs b/components/embedder_traits/lib.rs index cacaf80ca50..45fa6e1d7b4 100644 --- a/components/embedder_traits/lib.rs +++ b/components/embedder_traits/lib.rs @@ -198,6 +198,8 @@ pub enum EmbedderMsg { /// Notifies the embedder about media session events /// (i.e. when there is metadata for the active media session, playback state changes...). MediaSessionEvent(MediaSessionEvent), + /// Report the status of Devtools Server + OnDevtoolsStarted(Result<u16, ()>), } impl Debug for EmbedderMsg { @@ -232,6 +234,7 @@ impl Debug for EmbedderMsg { EmbedderMsg::BrowserCreated(..) => write!(f, "BrowserCreated"), EmbedderMsg::ReportProfile(..) => write!(f, "ReportProfile"), EmbedderMsg::MediaSessionEvent(..) => write!(f, "MediaSessionEvent"), + EmbedderMsg::OnDevtoolsStarted(..) => write!(f, "OnDevtoolsStarted"), } } } |