@@ -26,6 +26,12 @@ use std::time::Duration;
2626
2727include ! ( concat!( env!( "OUT_DIR" ) , "/cppdriver_compression_types.rs" ) ) ;
2828
29+ // According to `cassandra.h` the default CPP driver's
30+ // - consistency for statements is LOCAL_ONE,
31+ // - request client timeout is 12000 millis.
32+ const DEFAULT_CONSISTENCY : Consistency = Consistency :: LocalOne ;
33+ const DEFAULT_REQUEST_TIMEOUT_MILLIS : u64 = 12000 ;
34+
2935#[ derive( Clone , Debug ) ]
3036pub ( crate ) struct LoadBalancingConfig {
3137 pub ( crate ) token_awareness_enabled : bool ,
@@ -115,9 +121,9 @@ pub fn build_session_builder(
115121
116122#[ no_mangle]
117123pub unsafe extern "C" fn cass_cluster_new ( ) -> * mut CassCluster {
118- // According to `cassandra.h` the default CPP driver's consistency for statements is LOCAL_ONE.
119- let default_execution_profile_builder =
120- ExecutionProfileBuilder :: default ( ) . consistency ( Consistency :: LocalOne ) ;
124+ let default_execution_profile_builder = ExecutionProfileBuilder :: default ( )
125+ . consistency ( DEFAULT_CONSISTENCY )
126+ . request_timeout ( Some ( Duration :: from_millis ( DEFAULT_REQUEST_TIMEOUT_MILLIS ) ) ) ;
121127
122128 Box :: into_raw ( Box :: new ( CassCluster {
123129 session_builder : SessionBuilder :: new ( ) ,
@@ -224,6 +230,19 @@ pub unsafe extern "C" fn cass_cluster_set_connect_timeout(
224230 cluster. session_builder . config . connect_timeout = Duration :: from_millis ( timeout_ms. into ( ) ) ;
225231}
226232
233+ #[ no_mangle]
234+ pub unsafe extern "C" fn cass_cluster_set_request_timeout (
235+ cluster_raw : * mut CassCluster ,
236+ timeout_ms : c_uint ,
237+ ) {
238+ let cluster = ptr_to_ref_mut ( cluster_raw) ;
239+
240+ exec_profile_builder_modify ( & mut cluster. default_execution_profile_builder , |builder| {
241+ // 0 -> no timeout
242+ builder. request_timeout ( ( timeout_ms > 0 ) . then ( || Duration :: from_millis ( timeout_ms. into ( ) ) ) )
243+ } )
244+ }
245+
227246#[ no_mangle]
228247pub unsafe extern "C" fn cass_cluster_set_port (
229248 cluster_raw : * mut CassCluster ,
0 commit comments