@@ -28,21 +28,30 @@ use relay::udprelay::local::run as run_udp;
2828/// run(config);
2929/// ```
3030pub fn run ( mut config : Config ) {
31- // Hold it here, kill all plugins when Core is finished
31+ let mut vf = Vec :: new ( ) ;
32+
33+ if config. enable_udp {
34+ // Clone config here, because the config for TCP relay will be modified
35+ // after plugins started
36+ let udp_config = Arc :: new ( config. clone ( ) ) ;
37+
38+ // Run UDP relay before starting plugins
39+ // Because plugins doesn't support UDP relay
40+ let udp_fut = run_udp ( udp_config) ;
41+ vf. push ( boxed_future ( udp_fut) ) ;
42+ }
43+
44+ // Hold it here, kill all plugins when `tokio::run` is finished
3245 let plugins = launch_plugin ( & mut config, PluginMode :: Client ) . expect ( "Failed to launch plugins" ) ;
3346 let mon = :: monitor:: monitor_signal ( plugins) ;
3447
48+ // Recreate shared config here
3549 let config = Arc :: new ( config) ;
3650
37- let enable_udp = config. enable_udp ;
38-
3951 let tcp_fut = run_tcp ( config. clone ( ) ) ;
40- let mut vf = vec ! [ boxed_future( mon) , boxed_future( tcp_fut) ] ;
41- if enable_udp {
42- let udp_fut = run_udp ( config) ;
43- vf. push ( boxed_future ( udp_fut) ) ;
44- }
4552
53+ vf. push ( boxed_future ( mon) ) ;
54+ vf. push ( boxed_future ( tcp_fut) ) ;
4655 tokio:: run ( join_all ( vf) . then ( |res| match res {
4756 Ok ( ..) => Ok ( ( ) ) ,
4857 Err ( err) => panic ! ( "Failed to run server, err: {}" , err) ,
0 commit comments