Loading openssl-sys/src/lib.rs +5 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,7 @@ pub type PasswordCallback = extern "C" fn(buf: *mut c_char, size: c_int, -> c_int; pub const BIO_CTRL_EOF: c_int = 2; pub const BIO_C_SET_BUF_MEM_EOF_RETURN: c_int = 130; pub const CRYPTO_LOCK: c_int = 1; Loading Loading @@ -271,6 +272,10 @@ pub unsafe fn SSL_CTX_set_options(ssl: *mut SSL_CTX, op: c_long) -> c_long { SSL_CTX_ctrl(ssl, SSL_CTRL_OPTIONS, op, ptr::null_mut()) } pub unsafe fn BIO_set_mem_eof_return(b: *mut BIO, v: c_int) { BIO_ctrl(b, BIO_C_SET_BUF_MEM_EOF_RETURN, v as c_long, ptr::null_mut()); } pub unsafe fn SSL_CTX_get_options(ssl: *mut SSL_CTX) -> c_long { SSL_CTX_ctrl(ssl, SSL_CTRL_OPTIONS, 0, ptr::null_mut()) } Loading openssl/src/bio/mod.rs +6 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,12 @@ impl MemBio { pub unsafe fn get_handle(&self) -> *mut ffi::BIO { self.bio } /// Sets the BIO's EOF state. pub fn set_eof(&self, eof: bool) { let v = if eof { 0 } else { -1 }; unsafe { ffi::BIO_set_mem_eof_return(self.bio, v); } } } impl Read for MemBio { Loading openssl/src/ssl/mod.rs +6 −4 Original line number Diff line number Diff line Loading @@ -851,14 +851,16 @@ impl<S: Read+Write> SslStream<S> { try_ssl_stream!(self.flush()); let len = try_ssl_stream!(self.stream.read(&mut self.buf[..])); if len == 0 { return Ok(0); } self.ssl.get_rbio().set_eof(true); } else { try_ssl_stream!(self.ssl.get_rbio().write_all(&self.buf[..len])); } } LibSslError::ErrorWantWrite => { try_ssl_stream!(self.flush()) } LibSslError::ErrorZeroReturn => return Err(SslSessionClosed), LibSslError::ErrorSsl => return Err(SslError::get()), err => panic!("unexpected error {:?}", err), LibSslError::ErrorSyscall if ret == 0 => return Ok(0), err => panic!("unexpected error {:?} with ret {}", err, ret), } } } Loading openssl/src/ssl/tests.rs +1 −1 File changed.Contains only whitespace changes. Show changes Loading
openssl-sys/src/lib.rs +5 −0 Original line number Diff line number Diff line Loading @@ -116,6 +116,7 @@ pub type PasswordCallback = extern "C" fn(buf: *mut c_char, size: c_int, -> c_int; pub const BIO_CTRL_EOF: c_int = 2; pub const BIO_C_SET_BUF_MEM_EOF_RETURN: c_int = 130; pub const CRYPTO_LOCK: c_int = 1; Loading Loading @@ -271,6 +272,10 @@ pub unsafe fn SSL_CTX_set_options(ssl: *mut SSL_CTX, op: c_long) -> c_long { SSL_CTX_ctrl(ssl, SSL_CTRL_OPTIONS, op, ptr::null_mut()) } pub unsafe fn BIO_set_mem_eof_return(b: *mut BIO, v: c_int) { BIO_ctrl(b, BIO_C_SET_BUF_MEM_EOF_RETURN, v as c_long, ptr::null_mut()); } pub unsafe fn SSL_CTX_get_options(ssl: *mut SSL_CTX) -> c_long { SSL_CTX_ctrl(ssl, SSL_CTRL_OPTIONS, 0, ptr::null_mut()) } Loading
openssl/src/bio/mod.rs +6 −0 Original line number Diff line number Diff line Loading @@ -56,6 +56,12 @@ impl MemBio { pub unsafe fn get_handle(&self) -> *mut ffi::BIO { self.bio } /// Sets the BIO's EOF state. pub fn set_eof(&self, eof: bool) { let v = if eof { 0 } else { -1 }; unsafe { ffi::BIO_set_mem_eof_return(self.bio, v); } } } impl Read for MemBio { Loading
openssl/src/ssl/mod.rs +6 −4 Original line number Diff line number Diff line Loading @@ -851,14 +851,16 @@ impl<S: Read+Write> SslStream<S> { try_ssl_stream!(self.flush()); let len = try_ssl_stream!(self.stream.read(&mut self.buf[..])); if len == 0 { return Ok(0); } self.ssl.get_rbio().set_eof(true); } else { try_ssl_stream!(self.ssl.get_rbio().write_all(&self.buf[..len])); } } LibSslError::ErrorWantWrite => { try_ssl_stream!(self.flush()) } LibSslError::ErrorZeroReturn => return Err(SslSessionClosed), LibSslError::ErrorSsl => return Err(SslError::get()), err => panic!("unexpected error {:?}", err), LibSslError::ErrorSyscall if ret == 0 => return Ok(0), err => panic!("unexpected error {:?} with ret {}", err, ret), } } } Loading