@@ -8,11 +8,7 @@ use crate::{
88 ResultType ,
99} ;
1010use bytes:: { Bytes , BytesMut } ;
11- #[ cfg( any( target_os = "android" , target_os = "ios" ) ) ]
12- use futures:: future:: { select_ok, FutureExt } ;
1311use futures:: { SinkExt , StreamExt } ;
14- #[ cfg( any( target_os = "android" , target_os = "ios" ) ) ]
15- use std:: future:: Future ;
1612use std:: {
1713 io:: { Error , ErrorKind } ,
1814 net:: SocketAddr ,
@@ -32,19 +28,6 @@ pub struct WsFramedStream {
3228 send_timeout : u64 ,
3329}
3430
35- #[ cfg( any( target_os = "android" , target_os = "ios" ) ) ]
36- async fn await_timeout_result < F , T , E > ( future : F ) -> ResultType < T >
37- where
38- F : Future < Output = Result < Result < T , E > , tokio:: time:: error:: Elapsed > > ,
39- E : std:: error:: Error + Send + Sync + ' static ,
40- {
41- match future. await {
42- Ok ( Ok ( result) ) => Ok ( result) ,
43- Ok ( Err ( e) ) => Err ( e. into ( ) ) ,
44- Err ( elapsed) => Err ( Error :: new ( ErrorKind :: TimedOut , elapsed) . into ( ) ) ,
45- }
46- }
47-
4831impl WsFramedStream {
4932 pub async fn new < T : AsRef < str > > (
5033 url : T ,
@@ -60,57 +43,8 @@ impl WsFramedStream {
6043 . into_client_request ( )
6144 . map_err ( |e| Error :: new ( ErrorKind :: Other , e) ) ?;
6245
63- let stream;
64- #[ cfg( any( target_os = "android" , target_os = "ios" ) ) ]
65- {
66- let mut futures = vec ! [ ] ;
67-
68- let is_wss = url_str. starts_with ( "wss://" ) ;
69- let rustls_platform_verifier_initialized = !cfg ! ( target_os = "android" )
70- || crate :: config:: RUSTLS_PLATFORM_VERIFIER_INITIALIZED
71- . load ( std:: sync:: atomic:: Ordering :: Relaxed ) ;
72- if is_wss && rustls_platform_verifier_initialized {
73- use rustls_platform_verifier:: ConfigVerifierExt ;
74- use std:: sync:: Arc ;
75- use tokio_rustls:: rustls:: ClientConfig ;
76- use tokio_tungstenite:: { connect_async_tls_with_config, Connector } ;
77- match ClientConfig :: with_platform_verifier ( ) {
78- Ok ( config) => {
79- let connector = Connector :: Rustls ( Arc :: new ( config) ) ;
80- futures. push (
81- await_timeout_result ( timeout (
82- Duration :: from_millis ( ms_timeout) ,
83- connect_async_tls_with_config (
84- request. clone ( ) ,
85- None ,
86- false ,
87- Some ( connector) ,
88- ) ,
89- ) )
90- . boxed ( ) ,
91- ) ;
92- }
93- Err ( e) => {
94- log:: error!( "with_platform_verifier failed: {:?}" , e) ;
95- }
96- }
97- }
98- futures. push (
99- await_timeout_result ( timeout (
100- Duration :: from_millis ( ms_timeout) ,
101- connect_async ( request) ,
102- ) )
103- . boxed ( ) ,
104- ) ;
105- let ( ( s, _) , _) = select_ok ( futures) . await ?;
106- stream = s;
107- }
108- #[ cfg( not( any( target_os = "android" , target_os = "ios" ) ) ) ]
109- {
110- let ( s, _) =
111- timeout ( Duration :: from_millis ( ms_timeout) , connect_async ( request) ) . await ??;
112- stream = s;
113- }
46+ let ( stream, _) =
47+ timeout ( Duration :: from_millis ( ms_timeout) , connect_async ( request) ) . await ??;
11448
11549 let addr = match stream. get_ref ( ) {
11650 MaybeTlsStream :: Plain ( tcp) => tcp. peer_addr ( ) ?,
0 commit comments