From aae19c4cb3895749d6a97f255b2ef477b7e0db43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Wed, 8 Mar 2023 14:40:29 +0100 Subject: [PATCH] udp: uring: combine SendBuffers metadata lookups --- aquatic_udp/src/workers/socket/uring/mod.rs | 27 ++++++++++--------- .../src/workers/socket/uring/send_buffers.rs | 8 +++--- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/aquatic_udp/src/workers/socket/uring/mod.rs b/aquatic_udp/src/workers/socket/uring/mod.rs index faf34cd..7adf062 100644 --- a/aquatic_udp/src/workers/socket/uring/mod.rs +++ b/aquatic_udp/src/workers/socket/uring/mod.rs @@ -297,24 +297,25 @@ impl SocketWorker { } else if self.config.statistics.active() { let send_buffer_index = send_buffer_index as usize; - let (statistics, extra_bytes) = - if self.send_buffers.receiver_is_ipv4(send_buffer_index) { - (&self.shared_state.statistics_ipv4, EXTRA_PACKET_SIZE_IPV4) - } else { - (&self.shared_state.statistics_ipv6, EXTRA_PACKET_SIZE_IPV6) - }; + let (response_type, receiver_is_ipv4) = + self.send_buffers.response_type_and_ipv4(send_buffer_index); + + let (statistics, extra_bytes) = if receiver_is_ipv4 { + (&self.shared_state.statistics_ipv4, EXTRA_PACKET_SIZE_IPV4) + } else { + (&self.shared_state.statistics_ipv6, EXTRA_PACKET_SIZE_IPV6) + }; statistics .bytes_sent .fetch_add(result as usize + extra_bytes, Ordering::Relaxed); - let response_counter = - match self.send_buffers.response_type(send_buffer_index) { - ResponseType::Connect => &statistics.responses_sent_connect, - ResponseType::Announce => &statistics.responses_sent_announce, - ResponseType::Scrape => &statistics.responses_sent_scrape, - ResponseType::Error => &statistics.responses_sent_error, - }; + let response_counter = match response_type { + ResponseType::Connect => &statistics.responses_sent_connect, + ResponseType::Announce => &statistics.responses_sent_announce, + ResponseType::Scrape => &statistics.responses_sent_scrape, + ResponseType::Error => &statistics.responses_sent_error, + }; response_counter.fetch_add(1, Ordering::Relaxed); } diff --git a/aquatic_udp/src/workers/socket/uring/send_buffers.rs b/aquatic_udp/src/workers/socket/uring/send_buffers.rs index 6a8d7dd..38fe6c5 100644 --- a/aquatic_udp/src/workers/socket/uring/send_buffers.rs +++ b/aquatic_udp/src/workers/socket/uring/send_buffers.rs @@ -191,12 +191,10 @@ impl SendBuffers { } } - pub fn receiver_is_ipv4(&mut self, index: usize) -> bool { - self.buffers[index].receiver_is_ipv4 - } + pub fn response_type_and_ipv4(&self, index: usize) -> (ResponseType, bool) { + let buffer = self.buffers.get(index).unwrap(); - pub fn response_type(&mut self, index: usize) -> ResponseType { - self.buffers[index].response_type + (buffer.response_type, buffer.receiver_is_ipv4) } pub fn mark_index_as_free(&mut self, index: usize) {