Skip to content

Commit f683ecc

Browse files
RUST-696 Update to socket2 v0.4 (#306)
1 parent 8697d77 commit f683ecc

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ rand = { version = "0.8.3", features = ["small_rng"] }
4848
serde_with = "1.3.1"
4949
sha-1 = "0.9.4"
5050
sha2 = "0.9.3"
51-
socket2 = "0.3.12"
51+
socket2 = "0.4.0"
5252
stringprep = "0.1.2"
5353
strsim = "0.10.0"
5454
take_mut = "0.2.2"

src/runtime/stream.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ impl AsyncTcpStream {
7777
stream.set_nodelay(true)?;
7878

7979
let socket = socket2::Socket::from(stream.into_std()?);
80-
socket.set_keepalive(Some(KEEPALIVE_TIME))?;
81-
let std_stream = socket.into_tcp_stream();
80+
let conf = socket2::TcpKeepalive::new().with_time(KEEPALIVE_TIME);
81+
socket.set_tcp_keepalive(&conf)?;
82+
let std_stream = std::net::TcpStream::from(socket);
8283
let stream = TcpStream::from_std(std_stream)?;
8384

8485
Ok(stream.into())
@@ -89,12 +90,10 @@ impl AsyncTcpStream {
8990
use async_std::net::TcpStream;
9091
use socket2::{Domain, Protocol, SockAddr, Socket, Type};
9192

92-
let domain = match address {
93-
SocketAddr::V4(_) => Domain::ipv4(),
94-
SocketAddr::V6(_) => Domain::ipv6(),
95-
};
96-
let socket = Socket::new(domain, Type::stream(), Some(Protocol::tcp()))?;
97-
socket.set_keepalive(Some(KEEPALIVE_TIME))?;
93+
let domain = Domain::for_address(*address);
94+
let socket = Socket::new(domain, Type::STREAM, Some(Protocol::TCP))?;
95+
let conf = socket2::TcpKeepalive::new().with_time(KEEPALIVE_TIME);
96+
socket.set_tcp_keepalive(&conf)?;
9897

9998
let address: SockAddr = address.clone().into();
10099
if connect_timeout == Duration::from_secs(0) {
@@ -103,7 +102,7 @@ impl AsyncTcpStream {
103102
socket.connect_timeout(&address, connect_timeout)?;
104103
}
105104

106-
let stream: TcpStream = socket.into_tcp_stream().into();
105+
let stream: TcpStream = std::net::TcpStream::from(socket).into();
107106
stream.set_nodelay(true)?;
108107

109108
Ok(stream.into())

0 commit comments

Comments
 (0)