File tree 5 files changed +15
-11
lines changed
5 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ pub mod tpls;
7
7
8
8
use std:: borrow:: Cow ;
9
9
use std:: collections:: { HashMap , HashSet } ;
10
+ use std:: net:: IpAddr ;
10
11
use std:: path:: { Path , PathBuf } ;
11
12
use std:: sync:: { Arc , Mutex , RwLock } ;
12
13
@@ -149,8 +150,8 @@ impl Site {
149
150
/// We avoid the port the server is going to use as it's not bound yet
150
151
/// when calling this function and we could end up having tried to bind
151
152
/// both http and websocket server to the same port
152
- pub fn enable_live_reload ( & mut self , port_to_avoid : u16 ) {
153
- self . live_reload = get_available_port ( port_to_avoid) ;
153
+ pub fn enable_live_reload ( & mut self , interface : IpAddr , port_to_avoid : u16 ) {
154
+ self . live_reload = get_available_port ( interface , port_to_avoid) ;
154
155
}
155
156
156
157
/// Only used in `zola serve` to re-use the initial websocket port
Original file line number Diff line number Diff line change @@ -237,7 +237,9 @@ fn can_build_site_without_live_reload() {
237
237
#[ test]
238
238
fn can_build_site_with_live_reload_and_drafts ( ) {
239
239
let ( site, _tmp_dir, public) = build_site_with_setup ( "test_site" , |mut site| {
240
- site. enable_live_reload ( 1000 ) ;
240
+ use std:: net:: IpAddr ;
241
+ use std:: str:: FromStr ;
242
+ site. enable_live_reload ( IpAddr :: from_str ( "127.0.0.1" ) . unwrap ( ) , 1000 ) ;
241
243
site. include_drafts ( ) ;
242
244
( site, true )
243
245
} ) ;
Original file line number Diff line number Diff line change
1
+ use std:: net:: IpAddr ;
1
2
use std:: net:: TcpListener ;
2
3
3
- pub fn get_available_port ( avoid : u16 ) -> Option < u16 > {
4
+ pub fn get_available_port ( interface : IpAddr , avoid : u16 ) -> Option < u16 > {
4
5
// Start after "well-known" ports (0–1023) as they require superuser
5
6
// privileges on UNIX-like operating systems.
6
- ( 1024 ..9000 ) . find ( |port| * port != avoid && port_is_available ( * port) )
7
+ ( 1024 ..9000 ) . find ( |port| * port != avoid && port_is_available ( interface , * port) )
7
8
}
8
9
9
- pub fn port_is_available ( port : u16 ) -> bool {
10
- TcpListener :: bind ( ( "127.0.0.1" , port) ) . is_ok ( )
10
+ pub fn port_is_available ( interface : IpAddr , port : u16 ) -> bool {
11
+ TcpListener :: bind ( ( interface , port) ) . is_ok ( )
11
12
}
12
13
13
14
/// Returns whether a link starts with an HTTP(s) scheme.
Original file line number Diff line number Diff line change @@ -409,7 +409,7 @@ fn create_new_site(
409
409
if let Some ( p) = ws_port {
410
410
site. enable_live_reload_with_port ( p) ;
411
411
} else {
412
- site. enable_live_reload ( interface_port) ;
412
+ site. enable_live_reload ( interface , interface_port) ;
413
413
}
414
414
messages:: notify_site_size ( & site) ;
415
415
messages:: warn_about_ignored_pages ( & site) ;
Original file line number Diff line number Diff line change @@ -90,13 +90,13 @@ fn main() {
90
90
no_port_append,
91
91
extra_watch_path,
92
92
} => {
93
- if port != 1111 && !port_is_available ( port) {
93
+ if port != 1111 && !port_is_available ( interface , port) {
94
94
console:: error ( "The requested port is not available" ) ;
95
95
std:: process:: exit ( 1 ) ;
96
96
}
97
97
98
- if !port_is_available ( port) {
99
- port = get_available_port ( 1111 ) . unwrap_or_else ( || {
98
+ if !port_is_available ( interface , port) {
99
+ port = get_available_port ( interface , 1111 ) . unwrap_or_else ( || {
100
100
console:: error ( "No port available" ) ;
101
101
std:: process:: exit ( 1 ) ;
102
102
} ) ;
You can’t perform that action at this time.
0 commit comments