@@ -18,14 +18,14 @@ extern crate tokio;
1818
1919use std:: env;
2020use std:: io:: { self , Write } ;
21- use std:: process;
2221
2322use clap:: { App , Arg } ;
2423
2524use env_logger:: fmt:: Formatter ;
2625use env_logger:: Builder ;
2726use futures:: Future ;
2827use log:: { LevelFilter , Record } ;
28+ use tokio:: runtime:: Runtime ;
2929
3030use shadowsocks:: plugin:: PluginConfig ;
3131use shadowsocks:: { run_server, Config , ConfigType , ServerAddr , ServerConfig } ;
@@ -133,18 +133,16 @@ fn main() {
133133
134134 let mut has_provided_config = false ;
135135 let mut config = match matches. value_of ( "CONFIG" ) {
136- Some ( cpath) => {
137- match Config :: load_from_file ( cpath, ConfigType :: Server ) {
138- Ok ( cfg) => {
139- has_provided_config = true ;
140- cfg
141- }
142- Err ( err) => {
143- error ! ( "{:?}" , err) ;
144- return ;
145- }
136+ Some ( cpath) => match Config :: load_from_file ( cpath, ConfigType :: Server ) {
137+ Ok ( cfg) => {
138+ has_provided_config = true ;
139+ cfg
146140 }
147- }
141+ Err ( err) => {
142+ error ! ( "{:?}" , err) ;
143+ return ;
144+ }
145+ } ,
148146 None => Config :: new ( ) ,
149147 } ;
150148
@@ -198,16 +196,11 @@ fn main() {
198196
199197 debug ! ( "Config: {:?}" , config) ;
200198
201- tokio:: run ( run_server ( config) . then ( |res| -> Result < ( ) , ( ) > {
202- match res {
203- Ok ( ..) => error ! ( "Server exited without error" ) ,
204- Err ( err) => error ! ( "Server exited with error: {}" , err) ,
205- }
206-
207- // Kill the whole process
208- // Otherwise the users on this crashed server won't be able to connect
209- // until manually restart the server.
210- // Just crash and restart.
211- process:: exit ( 1 ) ;
212- } ) ) ;
199+ let mut runtime = Runtime :: new ( ) . expect ( "Creating runtime" ) ;
200+
201+ let result = runtime. block_on ( run_server ( config) ) ;
202+
203+ runtime. shutdown_now ( ) . wait ( ) . unwrap ( ) ;
204+
205+ panic ! ( "Server exited unexpectly with result: {:?}" , result) ;
213206}
0 commit comments