Skip to content

Commit 99f6e44

Browse files
committed
cluster: set keepalive config options
Sets the defaults, and implements: - cass_cluster_set_connection_heartbeat_interval - cass_cluster_set_connection_idle_timeout
1 parent 8cb3f49 commit 99f6e44

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

scylla-rust-wrapper/src/cluster.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ const DEFAULT_DO_FETCH_SCHEMA_METADATA: bool = true;
3939
const DEFAULT_SET_TCP_NO_DELAY: bool = true;
4040
// - connect timeout is 5000 millis
4141
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);
4246

4347
const DRIVER_NAME: &str = "ScyllaDB Cpp-Rust Driver";
4448
const DRIVER_VERSION: &str = env!("CARGO_PKG_VERSION");
@@ -177,6 +181,8 @@ pub unsafe extern "C" fn cass_cluster_new() -> *mut CassCluster {
177181
.fetch_schema_metadata(DEFAULT_DO_FETCH_SCHEMA_METADATA)
178182
.tcp_nodelay(DEFAULT_SET_TCP_NO_DELAY)
179183
.connection_timeout(DEFAULT_CONNECT_TIMEOUT)
184+
.keepalive_interval(DEFAULT_KEEPALIVE_INTERVAL)
185+
.keepalive_timeout(DEFAULT_KEEPALIVE_TIMEOUT)
180186
};
181187

182188
Box::into_raw(Box::new(CassCluster {
@@ -358,6 +364,28 @@ pub unsafe extern "C" fn cass_cluster_set_tcp_keepalive(
358364
cluster.session_builder.config.tcp_keepalive_interval = tcp_keepalive_interval;
359365
}
360366

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+
361389
#[no_mangle]
362390
pub unsafe extern "C" fn cass_cluster_set_connect_timeout(
363391
cluster_raw: *mut CassCluster,

src/testing_unimplemented.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,6 @@ CASS_EXPORT CassError cass_cluster_set_cloud_secure_connection_bundle_no_ssl_lib
6262
throw std::runtime_error(
6363
"UNIMPLEMENTED cass_cluster_set_cloud_secure_connection_bundle_no_ssl_lib_init\n");
6464
}
65-
CASS_EXPORT void cass_cluster_set_connection_heartbeat_interval(CassCluster* cluster,
66-
unsigned interval_secs) {
67-
throw std::runtime_error("UNIMPLEMENTED cass_cluster_set_connection_heartbeat_interval\n");
68-
}
69-
CASS_EXPORT void cass_cluster_set_connection_idle_timeout(CassCluster* cluster,
70-
unsigned timeout_secs) {
71-
throw std::runtime_error("UNIMPLEMENTED cass_cluster_set_connection_idle_timeout\n");
72-
}
7365
CASS_EXPORT void cass_cluster_set_constant_reconnect(CassCluster* cluster, cass_uint64_t delay_ms) {
7466
throw std::runtime_error("UNIMPLEMENTED cass_cluster_set_constant_reconnect\n");
7567
}

0 commit comments

Comments
 (0)