@@ -39,6 +39,10 @@ const DEFAULT_DO_FETCH_SCHEMA_METADATA: bool = true;
39
39
const DEFAULT_SET_TCP_NO_DELAY : bool = true ;
40
40
// - connect timeout is 5000 millis
41
41
const DEFAULT_CONNECT_TIMEOUT : Duration = Duration :: from_millis ( 5000 ) ;
42
+ // - keepalive interval is 30 secs
43
+ const DEFAULT_KEEPALIVE_INTERVAL : Duration = Duration :: from_secs ( 30 ) ;
44
+ // - keepalive timeout is 60 secs
45
+ const DEFAULT_KEEPALIVE_TIMEOUT : Duration = Duration :: from_secs ( 60 ) ;
42
46
43
47
const DRIVER_NAME : & str = "ScyllaDB Cpp-Rust Driver" ;
44
48
const DRIVER_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
@@ -177,6 +181,8 @@ pub unsafe extern "C" fn cass_cluster_new() -> *mut CassCluster {
177
181
. fetch_schema_metadata ( DEFAULT_DO_FETCH_SCHEMA_METADATA )
178
182
. tcp_nodelay ( DEFAULT_SET_TCP_NO_DELAY )
179
183
. connection_timeout ( DEFAULT_CONNECT_TIMEOUT )
184
+ . keepalive_interval ( DEFAULT_KEEPALIVE_INTERVAL )
185
+ . keepalive_timeout ( DEFAULT_KEEPALIVE_TIMEOUT )
180
186
} ;
181
187
182
188
Box :: into_raw ( Box :: new ( CassCluster {
@@ -358,6 +364,28 @@ pub unsafe extern "C" fn cass_cluster_set_tcp_keepalive(
358
364
cluster. session_builder . config . tcp_keepalive_interval = tcp_keepalive_interval;
359
365
}
360
366
367
+ #[ no_mangle]
368
+ pub unsafe extern "C" fn cass_cluster_set_connection_heartbeat_interval (
369
+ cluster_raw : * mut CassCluster ,
370
+ interval_secs : c_uint ,
371
+ ) {
372
+ let cluster = ptr_to_ref_mut ( cluster_raw) ;
373
+ let keepalive_interval = ( interval_secs > 0 ) . then ( || Duration :: from_secs ( interval_secs as u64 ) ) ;
374
+
375
+ cluster. session_builder . config . keepalive_interval = keepalive_interval;
376
+ }
377
+
378
+ #[ no_mangle]
379
+ pub unsafe extern "C" fn cass_cluster_set_connection_idle_timeout (
380
+ cluster_raw : * mut CassCluster ,
381
+ timeout_secs : c_uint ,
382
+ ) {
383
+ let cluster = ptr_to_ref_mut ( cluster_raw) ;
384
+ let keepalive_timeout = ( timeout_secs > 0 ) . then ( || Duration :: from_secs ( timeout_secs as u64 ) ) ;
385
+
386
+ cluster. session_builder . config . keepalive_timeout = keepalive_timeout;
387
+ }
388
+
361
389
#[ no_mangle]
362
390
pub unsafe extern "C" fn cass_cluster_set_connect_timeout (
363
391
cluster_raw : * mut CassCluster ,
0 commit comments