1212
1313#[ cfg( not( windows) ) ]
1414use std:: fs:: Permissions ;
15+ use std:: net:: SocketAddr ;
1516#[ cfg( not( windows) ) ]
1617use std:: os:: unix:: prelude:: * ;
1718
@@ -41,26 +42,41 @@ static TEST: AtomicUsize = AtomicUsize::new(0);
4142
4243#[ derive( Copy , Clone ) ]
4344struct Config {
44- remote : bool ,
4545 verbose : bool ,
46+ bind : SocketAddr ,
4647}
4748
4849impl Config {
4950 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+ }
5159 }
5260
5361 pub fn parse_args ( ) -> Config {
5462 let mut config = Config :: default ( ) ;
5563
5664 let args = env:: args ( ) . skip ( 1 ) ;
65+ let mut next_is_bind = false ;
5766 for argument in args {
5867 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 ,
6073 "--verbose" | "-v" => config. verbose = true ,
6174 arg => panic ! ( "unknown argument: {}" , arg) ,
6275 }
6376 }
77+ if next_is_bind {
78+ panic ! ( "missing value for --bind" ) ;
79+ }
6480
6581 config
6682 }
@@ -77,13 +93,7 @@ fn main() {
7793
7894 let config = Config :: parse_args ( ) ;
7995
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) ) ;
8797 let ( work, tmp) : ( PathBuf , PathBuf ) = if cfg ! ( target_os = "android" ) {
8898 ( "/data/tmp/work" . into ( ) , "/data/tmp/work/tmp" . into ( ) )
8999 } else {
@@ -93,7 +103,7 @@ fn main() {
93103 tmp_dir. push ( "tmp" ) ;
94104 ( work_dir, tmp_dir)
95105 } ;
96- println ! ( "listening on {}!" , bind_addr ) ;
106+ println ! ( "listening on {}!" , config . bind ) ;
97107
98108 t ! ( fs:: create_dir_all( & work) ) ;
99109 t ! ( fs:: create_dir_all( & tmp) ) ;
0 commit comments