Skip to content

Commit

Permalink
Better end-of-stream handling for UDP when buffer is full
Browse files Browse the repository at this point in the history
  • Loading branch information
flan committed Sep 16, 2022
1 parent a822772 commit 1009f99
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/stream/udp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,10 +602,20 @@ pub mod sender {
})))
} else {
//indicate that the test is over by sending the test ID by itself
for _ in 0..4 { //do it a few times in case of loss
let send_result = self.socket.send(&self.staged_packet[0..16]);
if send_result.is_err() {
return Some(Err(Box::new(send_result.unwrap_err())));
let mut remaining_announcements = 5;
while remaining_announcements > 0 { //do it a few times in case of loss
match self.socket.send(&self.staged_packet[0..16]) {
Ok(packet_size) => {
log::trace!("wrote {} bytes of test-end signal in UDP stream {}", packet_size, self.stream_idx);
remaining_announcements -= 1;
},
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => { //send-buffer is full
//wait to try again and avoid burning CPU cycles
sleep(BUFFER_FULL_TIMEOUT);
},
Err(e) => {
return Some(Err(Box::new(e)));
},
}
}
None
Expand Down

0 comments on commit 1009f99

Please sign in to comment.