3
3
#[ cfg( feature = "runtime" ) ]
4
4
use crate :: connect:: connect;
5
5
use crate :: connect_raw:: connect_raw;
6
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
6
7
use crate :: keepalive:: KeepaliveConfig ;
7
8
#[ cfg( feature = "runtime" ) ]
8
9
use crate :: tls:: MakeTlsConnect ;
@@ -165,6 +166,7 @@ pub struct Config {
165
166
pub ( crate ) connect_timeout : Option < Duration > ,
166
167
pub ( crate ) tcp_user_timeout : Option < Duration > ,
167
168
pub ( crate ) keepalives : bool ,
169
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
168
170
pub ( crate ) keepalive_config : KeepaliveConfig ,
169
171
pub ( crate ) target_session_attrs : TargetSessionAttrs ,
170
172
pub ( crate ) channel_binding : ChannelBinding ,
@@ -179,11 +181,6 @@ impl Default for Config {
179
181
impl Config {
180
182
/// Creates a new configuration.
181
183
pub fn new ( ) -> Config {
182
- let keepalive_config = KeepaliveConfig {
183
- idle : Duration :: from_secs ( 2 * 60 * 60 ) ,
184
- interval : None ,
185
- retries : None ,
186
- } ;
187
184
Config {
188
185
user : None ,
189
186
password : None ,
@@ -196,7 +193,12 @@ impl Config {
196
193
connect_timeout : None ,
197
194
tcp_user_timeout : None ,
198
195
keepalives : true ,
199
- keepalive_config,
196
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
197
+ keepalive_config : KeepaliveConfig {
198
+ idle : Duration :: from_secs ( 2 * 60 * 60 ) ,
199
+ interval : None ,
200
+ retries : None ,
201
+ } ,
200
202
target_session_attrs : TargetSessionAttrs :: Any ,
201
203
channel_binding : ChannelBinding :: Prefer ,
202
204
}
@@ -377,13 +379,15 @@ impl Config {
377
379
/// Sets the amount of idle time before a keepalive packet is sent on the connection.
378
380
///
379
381
/// This is ignored for Unix domain sockets, or if the `keepalives` option is disabled. Defaults to 2 hours.
382
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
380
383
pub fn keepalives_idle ( & mut self , keepalives_idle : Duration ) -> & mut Config {
381
384
self . keepalive_config . idle = keepalives_idle;
382
385
self
383
386
}
384
387
385
388
/// Gets the configured amount of idle time before a keepalive packet will
386
389
/// be sent on the connection.
390
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
387
391
pub fn get_keepalives_idle ( & self ) -> Duration {
388
392
self . keepalive_config . idle
389
393
}
@@ -392,25 +396,29 @@ impl Config {
392
396
/// On Windows, this sets the value of the tcp_keepalive struct’s keepaliveinterval field.
393
397
///
394
398
/// This is ignored for Unix domain sockets, or if the `keepalives` option is disabled.
399
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
395
400
pub fn keepalives_interval ( & mut self , keepalives_interval : Duration ) -> & mut Config {
396
401
self . keepalive_config . interval = Some ( keepalives_interval) ;
397
402
self
398
403
}
399
404
400
405
/// Gets the time interval between TCP keepalive probes.
406
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
401
407
pub fn get_keepalives_interval ( & self ) -> Option < Duration > {
402
408
self . keepalive_config . interval
403
409
}
404
410
405
411
/// Sets the maximum number of TCP keepalive probes that will be sent before dropping a connection.
406
412
///
407
413
/// This is ignored for Unix domain sockets, or if the `keepalives` option is disabled.
414
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
408
415
pub fn keepalives_retries ( & mut self , keepalives_retries : u32 ) -> & mut Config {
409
416
self . keepalive_config . retries = Some ( keepalives_retries) ;
410
417
self
411
418
}
412
419
413
420
/// Gets the maximum number of TCP keepalive probes that will be sent before dropping a connection.
421
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
414
422
pub fn get_keepalives_retries ( & self ) -> Option < u32 > {
415
423
self . keepalive_config . retries
416
424
}
@@ -503,12 +511,14 @@ impl Config {
503
511
self . tcp_user_timeout ( Duration :: from_secs ( timeout as u64 ) ) ;
504
512
}
505
513
}
514
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
506
515
"keepalives" => {
507
516
let keepalives = value
508
517
. parse :: < u64 > ( )
509
518
. map_err ( |_| Error :: config_parse ( Box :: new ( InvalidValue ( "keepalives" ) ) ) ) ?;
510
519
self . keepalives ( keepalives != 0 ) ;
511
520
}
521
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
512
522
"keepalives_idle" => {
513
523
let keepalives_idle = value
514
524
. parse :: < i64 > ( )
@@ -517,6 +527,7 @@ impl Config {
517
527
self . keepalives_idle ( Duration :: from_secs ( keepalives_idle as u64 ) ) ;
518
528
}
519
529
}
530
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
520
531
"keepalives_interval" => {
521
532
let keepalives_interval = value. parse :: < i64 > ( ) . map_err ( |_| {
522
533
Error :: config_parse ( Box :: new ( InvalidValue ( "keepalives_interval" ) ) )
@@ -525,6 +536,7 @@ impl Config {
525
536
self . keepalives_interval ( Duration :: from_secs ( keepalives_interval as u64 ) ) ;
526
537
}
527
538
}
539
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
528
540
"keepalives_retries" => {
529
541
let keepalives_retries = value. parse :: < u32 > ( ) . map_err ( |_| {
530
542
Error :: config_parse ( Box :: new ( InvalidValue ( "keepalives_retries" ) ) )
@@ -614,7 +626,8 @@ impl fmt::Debug for Config {
614
626
}
615
627
}
616
628
617
- f. debug_struct ( "Config" )
629
+ let mut config_dbg = & mut f. debug_struct ( "Config" ) ;
630
+ config_dbg = config_dbg
618
631
. field ( "user" , & self . user )
619
632
. field ( "password" , & self . password . as_ref ( ) . map ( |_| Redaction { } ) )
620
633
. field ( "dbname" , & self . dbname )
@@ -625,10 +638,17 @@ impl fmt::Debug for Config {
625
638
. field ( "port" , & self . port )
626
639
. field ( "connect_timeout" , & self . connect_timeout )
627
640
. field ( "tcp_user_timeout" , & self . tcp_user_timeout )
628
- . field ( "keepalives" , & self . keepalives )
629
- . field ( "keepalives_idle" , & self . keepalive_config . idle )
630
- . field ( "keepalives_interval" , & self . keepalive_config . interval )
631
- . field ( "keepalives_retries" , & self . keepalive_config . retries )
641
+ . field ( "keepalives" , & self . keepalives ) ;
642
+
643
+ #[ cfg( not( target_arch = "wasm32" ) ) ]
644
+ {
645
+ config_dbg = config_dbg
646
+ . field ( "keepalives_idle" , & self . keepalive_config . idle )
647
+ . field ( "keepalives_interval" , & self . keepalive_config . interval )
648
+ . field ( "keepalives_retries" , & self . keepalive_config . retries ) ;
649
+ }
650
+
651
+ config_dbg
632
652
. field ( "target_session_attrs" , & self . target_session_attrs )
633
653
. field ( "channel_binding" , & self . channel_binding )
634
654
. finish ( )
0 commit comments