use std::io;
use socket2::{Domain, SockAddr, Socket, Type};
use crate::runtime::IoSource;
pub(crate) fn connect_blocking(domain: Domain, address: &SockAddr) -> io::Result<IoSource> {
let socket = Socket::new(domain, Type::STREAM, None)?;
loop {
match socket.connect(address) {
Ok(()) => break,
Err(e) if e.kind() == io::ErrorKind::Interrupted => {}
#[cfg(unix)]
Err(e) if e.raw_os_error() == Some(libc::EISCONN) => break,
Err(e) => return Err(e),
}
}
socket.set_nonblocking(true)?;
Ok(IoSource::new(socket.into()))
}