Skip to content

Commit 5fd0786

Browse files
authored
RUST-269 Wrap I/O in buffered stream (#113)
1 parent aacd9be commit 5fd0786

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ version = "0.9.0"
1414
base64 = "0.11.0"
1515
bitflags = "1.1.0"
1616
bson = "0.14.0"
17+
bufstream = "0.1.4"
1718
byteorder = "1.3.2"
1819
chrono = "0.4.7"
1920
derivative = "1.0.2"

src/cmap/conn/stream.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{
55
time::Duration,
66
};
77

8+
use bufstream::BufStream;
89
use derivative::Derivative;
910
use webpki::DNSNameRef;
1011

@@ -28,10 +29,13 @@ pub(super) enum Stream {
2829
Null,
2930

3031
/// A basic TCP connection to the server.
31-
Tcp(TcpStream),
32+
Tcp(BufStream<TcpStream>),
3233

3334
/// A TLS connection over TCP.
34-
Tls(#[derivative(Debug = "ignore")] rustls::StreamOwned<rustls::ClientSession, TcpStream>),
35+
Tls(
36+
#[derivative(Debug = "ignore")]
37+
BufStream<rustls::StreamOwned<rustls::ClientSession, TcpStream>>,
38+
),
3539
}
3640

3741
impl Stream {
@@ -54,6 +58,7 @@ impl Stream {
5458
TcpStream::connect_timeout(&socket_addrs[0], timeout)?
5559
};
5660
inner.set_nodelay(true)?;
61+
let inner = inner;
5762

5863
match tls_options {
5964
Some(cfg) => {
@@ -63,9 +68,11 @@ impl Stream {
6368

6469
let session = rustls::ClientSession::new(&Arc::new(tls_config), name);
6570

66-
Ok(Stream::Tls(rustls::StreamOwned::new(session, inner)))
71+
Ok(Stream::Tls(BufStream::new(rustls::StreamOwned::new(
72+
session, inner,
73+
))))
6774
}
68-
None => Ok(Self::Tcp(inner)),
75+
None => Ok(Self::Tcp(BufStream::new(inner))),
6976
}
7077
}
7178
}

0 commit comments

Comments
 (0)