Skip to content

Commit d1c2d15

Browse files
da2ce7josecelano
authored andcommitted
fix: [#918] revision for UDP active reqeust buffer comments
1 parent 6495a4c commit d1c2d15

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/servers/udp/server/request_buffer.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,22 @@ impl ActiveRequests {
4949
///
5050
/// * `abort_handle` - The `AbortHandle` for the UDP request processor task.
5151
/// * `local_addr` - A string slice representing the local address for logging.
52-
pub async fn force_push(&mut self, abort_handle: AbortHandle, local_addr: &str) {
52+
pub async fn force_push(&mut self, new_task: AbortHandle, local_addr: &str) {
5353
// Attempt to add the new handle to the buffer.
54-
match self.rb.try_push(abort_handle) {
54+
match self.rb.try_push(new_task) {
5555
Ok(()) => {
5656
// Successfully added the task, no further action needed.
5757
}
58-
Err(abort_handle) => {
58+
Err(new_task) => {
5959
// Buffer is full, attempt to make space.
6060

6161
let mut finished: u64 = 0;
6262
let mut unfinished_task = None;
6363

64-
for removed_abort_handle in self.rb.pop_iter() {
64+
for old_task in self.rb.pop_iter() {
6565
// We found a finished tasks ... increase the counter and
6666
// continue searching for more and ...
67-
if removed_abort_handle.is_finished() {
67+
if old_task.is_finished() {
6868
finished += 1;
6969
continue;
7070
}
@@ -76,7 +76,7 @@ impl ActiveRequests {
7676

7777
// Recheck if it finished ... increase the counter and
7878
// continue searching for more and ...
79-
if removed_abort_handle.is_finished() {
79+
if old_task.is_finished() {
8080
finished += 1;
8181
continue;
8282
}
@@ -95,7 +95,7 @@ impl ActiveRequests {
9595
// unfinished task.
9696
if finished == 0 {
9797
// We make place aborting this task.
98-
removed_abort_handle.abort();
98+
old_task.abort();
9999

100100
tracing::warn!(
101101
target: UDP_TRACKER_LOG_TARGET,
@@ -111,7 +111,7 @@ impl ActiveRequests {
111111
// buffer, so we need to re-insert in in the buffer.
112112

113113
// Save the unfinished task for re-entry.
114-
unfinished_task = Some(removed_abort_handle);
114+
unfinished_task = Some(old_task);
115115
}
116116

117117
// After this point there can't be a race condition because only
@@ -124,11 +124,15 @@ impl ActiveRequests {
124124
self.rb.try_push(h).expect("it was previously inserted");
125125
}
126126

127-
// Insert the new task, ensuring there's space.
128-
if !abort_handle.is_finished() {
129-
self.rb
130-
.try_push(abort_handle)
131-
.expect("it should remove at least one element.");
127+
// Insert the new task.
128+
//
129+
// Notice that space has already been made for this new task in
130+
// the buffer. One or many old task have already been finished
131+
// or yielded, freeing space in the buffer. Or a single
132+
// unfinished task has been aborted to make space for this new
133+
// task.
134+
if !new_task.is_finished() {
135+
self.rb.try_push(new_task).expect("it should have space for this new task.");
132136
}
133137
}
134138
};

0 commit comments

Comments
 (0)