Skip to content

Commit 287782c

Browse files
committed
Don't use socket2s connect_timeout function
This function sets the socket to blocking mode. Not ok.
1 parent 6a54e68 commit 287782c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/connection.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,12 @@ impl NetConnection for socket2::Socket {
148148
let addr = addr.to_socket_addrs()?.next().ok_or(io::ErrorKind::AddrNotAvailable)?;
149149
let socket =
150150
socket2::Socket::new(socket2::Domain::for_address(addr), socket2::Type::STREAM, None)?;
151+
151152
socket.set_nonblocking(true)?;
152-
match socket2::Socket::connect_timeout(&socket, &addr.into(), timeout) {
153+
socket.set_read_timeout(Some(timeout))?;
154+
socket.set_write_timeout(Some(timeout))?;
155+
156+
match socket2::Socket::connect(&socket, &addr.into()) {
153157
Ok(()) => {
154158
#[cfg(feature = "log")]
155159
log::debug!(target: "netservices", "Connected to {}", addr);

0 commit comments

Comments
 (0)