12
12
13
13
#[ cfg( not( windows) ) ]
14
14
use std:: fs:: Permissions ;
15
+ use std:: net:: SocketAddr ;
15
16
#[ cfg( not( windows) ) ]
16
17
use std:: os:: unix:: prelude:: * ;
17
18
@@ -41,26 +42,41 @@ static TEST: AtomicUsize = AtomicUsize::new(0);
41
42
42
43
#[ derive( Copy , Clone ) ]
43
44
struct Config {
44
- remote : bool ,
45
45
verbose : bool ,
46
+ bind : SocketAddr ,
46
47
}
47
48
48
49
impl Config {
49
50
pub fn default ( ) -> Config {
50
- Config { remote : false , verbose : false }
51
+ Config {
52
+ verbose : false ,
53
+ bind : if cfg ! ( target_os = "android" ) || cfg ! ( windows) {
54
+ ( [ 0 , 0 , 0 , 0 ] , 12345 ) . into ( )
55
+ } else {
56
+ ( [ 10 , 0 , 2 , 15 ] , 12345 ) . into ( )
57
+ } ,
58
+ }
51
59
}
52
60
53
61
pub fn parse_args ( ) -> Config {
54
62
let mut config = Config :: default ( ) ;
55
63
56
64
let args = env:: args ( ) . skip ( 1 ) ;
65
+ let mut next_is_bind = false ;
57
66
for argument in args {
58
67
match & argument[ ..] {
59
- "--remote" => config. remote = true ,
68
+ bind if next_is_bind => {
69
+ config. bind = t ! ( bind. parse( ) ) ;
70
+ next_is_bind = false ;
71
+ }
72
+ "--bind" => next_is_bind = true ,
60
73
"--verbose" | "-v" => config. verbose = true ,
61
74
arg => panic ! ( "unknown argument: {}" , arg) ,
62
75
}
63
76
}
77
+ if next_is_bind {
78
+ panic ! ( "missing value for --bind" ) ;
79
+ }
64
80
65
81
config
66
82
}
@@ -77,13 +93,7 @@ fn main() {
77
93
78
94
let config = Config :: parse_args ( ) ;
79
95
80
- let bind_addr = if cfg ! ( target_os = "android" ) || cfg ! ( windows) || config. remote {
81
- "0.0.0.0:12345"
82
- } else {
83
- "10.0.2.15:12345"
84
- } ;
85
-
86
- let listener = t ! ( TcpListener :: bind( bind_addr) ) ;
96
+ let listener = t ! ( TcpListener :: bind( config. bind) ) ;
87
97
let ( work, tmp) : ( PathBuf , PathBuf ) = if cfg ! ( target_os = "android" ) {
88
98
( "/data/tmp/work" . into ( ) , "/data/tmp/work/tmp" . into ( ) )
89
99
} else {
@@ -93,7 +103,7 @@ fn main() {
93
103
tmp_dir. push ( "tmp" ) ;
94
104
( work_dir, tmp_dir)
95
105
} ;
96
- println ! ( "listening on {}!" , bind_addr ) ;
106
+ println ! ( "listening on {}!" , config . bind ) ;
97
107
98
108
t ! ( fs:: create_dir_all( & work) ) ;
99
109
t ! ( fs:: create_dir_all( & tmp) ) ;
0 commit comments