@@ -729,7 +729,7 @@ where
729
729
///
730
730
/// Note that calling it is not mandatory, because the TLS session is anyway
731
731
/// negotiated during the first read or write operation.
732
- pub fn connect < ' b > ( & mut self ) -> Result < ( ) , TlsError > {
732
+ pub fn connect ( & mut self ) -> Result < ( ) , TlsError > {
733
733
if matches ! ( self . state, SessionState :: Connected ) {
734
734
return Ok ( ( ) ) ;
735
735
} else if matches ! ( self . state, SessionState :: Eof ) {
@@ -739,7 +739,7 @@ where
739
739
unsafe {
740
740
mbedtls_ssl_set_bio (
741
741
self . ssl_context ,
742
- core :: ptr :: addr_of! ( self ) as * mut c_void ,
742
+ self as * mut _ as * mut c_void ,
743
743
Some ( Self :: send) ,
744
744
Some ( Self :: receive) ,
745
745
None ,
@@ -753,6 +753,8 @@ where
753
753
break ;
754
754
}
755
755
if res < 0 && res != MBEDTLS_ERR_SSL_WANT_READ && res != MBEDTLS_ERR_SSL_WANT_WRITE
756
+ // See https://github.com/Mbed-TLS/mbedtls/issues/8749
757
+ && res != MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET
756
758
{
757
759
// real error
758
760
// Reference: https://os.mbed.com/teams/sandbox/code/mbedtls/docs/tip/ssl_8h.html#a4a37e497cd08c896870a42b1b618186e
@@ -789,6 +791,7 @@ where
789
791
let res = self . internal_read ( buf) ;
790
792
#[ allow( non_snake_case) ]
791
793
match res {
794
+ // See https://github.com/Mbed-TLS/mbedtls/issues/8749
792
795
MBEDTLS_ERR_SSL_WANT_READ | MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET => continue , // no data
793
796
0_i32 ..=i32:: MAX => return Ok ( res as usize ) , // data
794
797
i32:: MIN ..=-1_i32 => return Err ( TlsError :: MbedTlsError ( res) ) , // error
@@ -808,8 +811,16 @@ where
808
811
pub fn write ( & mut self , data : & [ u8 ] ) -> Result < usize , TlsError > {
809
812
self . connect ( ) ?;
810
813
811
- let res = self . internal_write ( data) ;
812
- Ok ( res as usize )
814
+ loop {
815
+ let res = self . internal_write ( data) ;
816
+ #[ allow( non_snake_case) ]
817
+ match res {
818
+ // See https://github.com/Mbed-TLS/mbedtls/issues/8749
819
+ MBEDTLS_ERR_SSL_WANT_WRITE | MBEDTLS_ERR_SSL_RECEIVED_NEW_SESSION_TICKET => continue , // no data
820
+ 0_i32 ..=i32:: MAX => return Ok ( res as usize ) , // data
821
+ i32:: MIN ..=-1_i32 => return Err ( TlsError :: MbedTlsError ( res) ) , // error
822
+ }
823
+ }
813
824
}
814
825
815
826
/// Flush the TLS connection
0 commit comments