udp: mio socket worker: make send_response plain fn

This commit is contained in:
Joakim Frostegård 2024-02-02 13:48:06 +01:00
parent 405bbaca93
commit be5165bcf2

View file

@ -130,7 +130,7 @@ impl SocketWorker {
// If resend buffer is enabled, send any responses in it // If resend buffer is enabled, send any responses in it
if let Some(resend_buffer) = self.opt_resend_buffer.as_mut() { if let Some(resend_buffer) = self.opt_resend_buffer.as_mut() {
for (addr, response) in resend_buffer.drain(..) { for (addr, response) in resend_buffer.drain(..) {
Self::send_response( send_response(
&self.config, &self.config,
&self.statistics, &self.statistics,
&mut self.socket, &mut self.socket,
@ -241,7 +241,7 @@ impl SocketWorker {
message: err.into(), message: err.into(),
}; };
Self::send_response( send_response(
&self.config, &self.config,
&self.statistics, &self.statistics,
&mut self.socket, &mut self.socket,
@ -288,7 +288,7 @@ impl SocketWorker {
transaction_id: request.transaction_id, transaction_id: request.transaction_id,
}; };
Self::send_response( send_response(
&self.config, &self.config,
&self.statistics, &self.statistics,
&mut self.socket, &mut self.socket,
@ -324,7 +324,7 @@ impl SocketWorker {
message: "Info hash not allowed".into(), message: "Info hash not allowed".into(),
}; };
Self::send_response( send_response(
&self.config, &self.config,
&self.statistics, &self.statistics,
&mut self.socket, &mut self.socket,
@ -392,7 +392,7 @@ impl SocketWorker {
ConnectedResponse::AnnounceIpv6(r) => Response::AnnounceIpv6(r), ConnectedResponse::AnnounceIpv6(r) => Response::AnnounceIpv6(r),
}; };
Self::send_response( send_response(
&self.config, &self.config,
&self.statistics, &self.statistics,
&mut self.socket, &mut self.socket,
@ -403,6 +403,7 @@ impl SocketWorker {
); );
} }
} }
}
fn send_response( fn send_response(
config: &Config, config: &Config,
@ -467,7 +468,8 @@ impl SocketWorker {
} }
} }
Ok(_) => (), Ok(_) => (),
Err(err) => match opt_resend_buffer.as_mut() { Err(err) => {
match opt_resend_buffer.as_mut() {
Some(resend_buffer) Some(resend_buffer)
if (err.raw_os_error() == Some(libc::ENOBUFS)) if (err.raw_os_error() == Some(libc::ENOBUFS))
|| (err.kind() == ErrorKind::WouldBlock) => || (err.kind() == ErrorKind::WouldBlock) =>
@ -483,7 +485,7 @@ impl SocketWorker {
_ => { _ => {
::log::warn!("Sending response to {} failed: {:#}", addr, err); ::log::warn!("Sending response to {} failed: {:#}", addr, err);
} }
}, }
} }
} }
} }