From c8fae312ad9a4350f3aa92b5aa09cc9f8971175e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20Sch=C3=B6lling?= Date: Thu, 30 Apr 2015 20:00:30 +0200 Subject: Add SslStream.pending() --- openssl/src/ssl/tests.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'openssl/src/ssl/tests.rs') diff --git a/openssl/src/ssl/tests.rs b/openssl/src/ssl/tests.rs index e6af551b..c9a2d73a 100644 --- a/openssl/src/ssl/tests.rs +++ b/openssl/src/ssl/tests.rs @@ -337,6 +337,30 @@ fn test_read() { io::copy(&mut stream, &mut io::sink()).ok().expect("read error"); } + +#[test] +fn test_pending() { + let tcp = TcpStream::connect("127.0.0.1:15418").unwrap(); + let mut stream = SslStream::new(&SslContext::new(Sslv23).unwrap(), tcp).unwrap(); + stream.write_all("GET /\r\n\r\n".as_bytes()).unwrap(); + stream.flush().unwrap(); + + // wait for the response and read first byte... + let mut buf = [0u8; 16*1024]; + stream.read(&mut buf[..1]).unwrap(); + + let pending = stream.pending(); + let len = stream.read(&mut buf[1..]).unwrap(); + + assert_eq!(pending, len); + + stream.read(&mut buf[..1]).unwrap(); + + let pending = stream.pending(); + let len = stream.read(&mut buf[1..]).unwrap(); + assert_eq!(pending, len); +} + /// Tests that connecting with the client using NPN, but the server not does not /// break the existing connection behavior. #[test] -- cgit v1.2.3