@@ -26,6 +26,12 @@ use std::time::Duration;
26
26
27
27
include ! ( concat!( env!( "OUT_DIR" ) , "/cppdriver_compression_types.rs" ) ) ;
28
28
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
+
29
35
#[ derive( Clone , Debug ) ]
30
36
pub ( crate ) struct LoadBalancingConfig {
31
37
pub ( crate ) token_awareness_enabled : bool ,
@@ -115,9 +121,9 @@ pub fn build_session_builder(
115
121
116
122
#[ no_mangle]
117
123
pub 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 ) ) ) ;
121
127
122
128
Box :: into_raw ( Box :: new ( CassCluster {
123
129
session_builder : SessionBuilder :: new ( ) ,
@@ -224,6 +230,19 @@ pub unsafe extern "C" fn cass_cluster_set_connect_timeout(
224
230
cluster. session_builder . config . connect_timeout = Duration :: from_millis ( timeout_ms. into ( ) ) ;
225
231
}
226
232
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
+
227
246
#[ no_mangle]
228
247
pub unsafe extern "C" fn cass_cluster_set_port (
229
248
cluster_raw : * mut CassCluster ,
0 commit comments