forked from M-Labs/artiq
1
0
Fork 0

Revert "Ensure that pending data is sent when closing sockets"

This reverts commit 73082d116f.
This commit is contained in:
Sebastien Bourdeauducq 2022-07-08 17:56:33 +08:00
parent 9941ee3d2a
commit 3adcf37625
1 changed files with 4 additions and 45 deletions

View File

@ -250,26 +250,14 @@ impl<'a> Io<'a> {
}) })
} }
pub fn inner_until<F: FnMut() -> bool>( pub fn until<F: FnMut() -> bool>(&self, mut f: F) -> Result<(), Error> {
&self,
timeout: Option<u64>,
mut f: F
) -> Result<(), Error> {
let f = unsafe { mem::transmute::<&mut dyn FnMut() -> bool, *mut dyn FnMut() -> bool>(&mut f) }; let f = unsafe { mem::transmute::<&mut dyn FnMut() -> bool, *mut dyn FnMut() -> bool>(&mut f) };
self.suspend(WaitRequest { self.suspend(WaitRequest {
timeout, timeout: None,
event: Some(f), event: Some(f)
}) })
} }
pub fn until<F: FnMut() -> bool>(&self, f: F) -> Result<(), Error> {
self.inner_until(None, f)
}
pub fn until_with_timeout<F: FnMut() -> bool>(&self, timeout: u64, f: F) -> Result<(), Error> {
self.inner_until(Some(timeout), f)
}
pub fn until_ok<T, E, F>(&self, mut f: F) -> Result<T, Error> pub fn until_ok<T, E, F>(&self, mut f: F) -> Result<T, Error>
where F: FnMut() -> result::Result<T, E> where F: FnMut() -> result::Result<T, E>
{ {
@ -325,15 +313,7 @@ macro_rules! until {
let $var = network.get_socket::<$ty>(handle); let $var = network.get_socket::<$ty>(handle);
$cond $cond
}) })
});
($socket:expr, $ty:ty, timeout=$timeout:expr, |$var:ident| $cond:expr) => ({
let (network, handle) = ($socket.io.network.clone(), $socket.handle);
$socket.io.until_with_timeout($timeout, move || {
let mut network = network.borrow_mut();
let $var = network.get_socket::<$ty>(handle);
$cond
}) })
});
} }
type TcpSocketBuffer = ::smoltcp::socket::TcpSocketBuffer<'static>; type TcpSocketBuffer = ::smoltcp::socket::TcpSocketBuffer<'static>;
@ -587,27 +567,6 @@ impl<'a> Write for TcpStream<'a> {
impl<'a> Drop for TcpStream<'a> { impl<'a> Drop for TcpStream<'a> {
fn drop(&mut self) { fn drop(&mut self) {
self.with_lower(|s| s.close()); self.with_lower(|s| s.close());
let result = until!(
self, TcpSocketLower, timeout=clock::get_ms() + 1000, |s| !s.is_active()
);
let unsent_bytes = self.with_lower(|s| s.send_queue());
match result{
Ok(()) => {
if unsent_bytes != 0 {
// This is normal if we received a reset whilst sending
debug!("Dropping socket with {} bytes unsent", unsent_bytes)
}
}
Err(Error::TimedOut) => {
warn!(
"Timed out whilst waiting for socket to close during drop, with {} unsent bytes",
unsent_bytes
);
}
Err(e) => {
error!("Unexpected error whilst waiting for socket to close during drop: {:?}", e)
}
}
self.io.network.borrow_mut().remove_socket(self.handle); self.io.network.borrow_mut().remove_socket(self.handle);
} }
} }