Skip to content
Snippets Groups Projects

fix: don't ignore all but the first resolved socket addresses

Merged Georgy Moshkin requested to merge gmoshkin/reduce-tcp-connect-logic-dubiousness into master
Files
2
@@ -169,11 +169,13 @@ impl TcpStream {
// If no error, then connection is established
};
// If this allocation panics the fd will still be closed
let result = Self {
fd: Rc::new(Cell::new(None)),
};
// Now TcpStream owns the fd and takes responsibility of closing it.
let fd = fd.into_inner();
return Ok(Self {
fd: Rc::new(Cell::new(Some(fd))),
});
result.fd.set(Some(fd.into_inner()));
return Ok(result);
}
#[inline(always)]
@@ -258,6 +260,8 @@ fn nonblocking_socket(kind: libc::c_int) -> io::Result<AutoCloseFd> {
/// A wrapper around a raw file descriptor, which automatically closes the
/// descriptor if dropped.
/// Use [`Self::into_inner`] to disable the automatic close on drop.
///
/// TODO: consider using [`std::os::fd::OwnedFd`] instead
struct AutoCloseFd(RawFd);
impl AutoCloseFd {
@@ -659,7 +663,7 @@ mod tests {
async fn read_timeout() {
let mut stream = TcpStream::connect_timeout("localhost", listen_port(), _10_SEC).unwrap();
// Read greeting
let mut buf = vec![0; 128];
let mut buf = vec![0; 4096];
assert_eq!(
stream
.read_exact(&mut buf)
Loading