@@ -1572,16 +1572,34 @@ impl SslContextBuilder {
1572
1572
///
1573
1573
/// This can be used to provide data to callbacks registered with the context. Use the
1574
1574
/// `SslContext::new_ex_index` method to create an `Index`.
1575
+ // FIXME should return a result
1575
1576
#[ corresponds( SSL_CTX_set_ex_data ) ]
1576
1577
pub fn set_ex_data < T > ( & mut self , index : Index < SslContext , T > , data : T ) {
1577
1578
self . set_ex_data_inner ( index, data) ;
1578
1579
}
1579
1580
1580
1581
fn set_ex_data_inner < T > ( & mut self , index : Index < SslContext , T > , data : T ) -> * mut c_void {
1582
+ match self . ex_data_mut ( index) {
1583
+ Some ( v) => {
1584
+ * v = data;
1585
+ ( v as * mut T ) . cast ( )
1586
+ }
1587
+ _ => unsafe {
1588
+ let data = Box :: into_raw ( Box :: new ( data) ) as * mut c_void ;
1589
+ ffi:: SSL_CTX_set_ex_data ( self . as_ptr ( ) , index. as_raw ( ) , data) ;
1590
+ data
1591
+ } ,
1592
+ }
1593
+ }
1594
+
1595
+ fn ex_data_mut < T > ( & mut self , index : Index < SslContext , T > ) -> Option < & mut T > {
1581
1596
unsafe {
1582
- let data = Box :: into_raw ( Box :: new ( data) ) as * mut c_void ;
1583
- ffi:: SSL_CTX_set_ex_data ( self . as_ptr ( ) , index. as_raw ( ) , data) ;
1584
- data
1597
+ let data = ffi:: SSL_CTX_get_ex_data ( self . as_ptr ( ) , index. as_raw ( ) ) ;
1598
+ if data. is_null ( ) {
1599
+ None
1600
+ } else {
1601
+ Some ( & mut * data. cast ( ) )
1602
+ }
1585
1603
}
1586
1604
}
1587
1605
@@ -2965,15 +2983,19 @@ impl SslRef {
2965
2983
///
2966
2984
/// This can be used to provide data to callbacks registered with the context. Use the
2967
2985
/// `Ssl::new_ex_index` method to create an `Index`.
2986
+ // FIXME should return a result
2968
2987
#[ corresponds( SSL_set_ex_data ) ]
2969
2988
pub fn set_ex_data < T > ( & mut self , index : Index < Ssl , T > , data : T ) {
2970
- unsafe {
2971
- let data = Box :: new ( data) ;
2972
- ffi:: SSL_set_ex_data (
2973
- self . as_ptr ( ) ,
2974
- index. as_raw ( ) ,
2975
- Box :: into_raw ( data) as * mut c_void ,
2976
- ) ;
2989
+ match self . ex_data_mut ( index) {
2990
+ Some ( v) => * v = data,
2991
+ None => unsafe {
2992
+ let data = Box :: new ( data) ;
2993
+ ffi:: SSL_set_ex_data (
2994
+ self . as_ptr ( ) ,
2995
+ index. as_raw ( ) ,
2996
+ Box :: into_raw ( data) as * mut c_void ,
2997
+ ) ;
2998
+ } ,
2977
2999
}
2978
3000
}
2979
3001
0 commit comments