Skip to content

Commit 1009f99

Browse files
committed
Better end-of-stream handling for UDP when buffer is full
1 parent a822772 commit 1009f99

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/stream/udp.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,20 @@ pub mod sender {
602602
})))
603603
} else {
604604
//indicate that the test is over by sending the test ID by itself
605-
for _ in 0..4 { //do it a few times in case of loss
606-
let send_result = self.socket.send(&self.staged_packet[0..16]);
607-
if send_result.is_err() {
608-
return Some(Err(Box::new(send_result.unwrap_err())));
605+
let mut remaining_announcements = 5;
606+
while remaining_announcements > 0 { //do it a few times in case of loss
607+
match self.socket.send(&self.staged_packet[0..16]) {
608+
Ok(packet_size) => {
609+
log::trace!("wrote {} bytes of test-end signal in UDP stream {}", packet_size, self.stream_idx);
610+
remaining_announcements -= 1;
611+
},
612+
Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => { //send-buffer is full
613+
//wait to try again and avoid burning CPU cycles
614+
sleep(BUFFER_FULL_TIMEOUT);
615+
},
616+
Err(e) => {
617+
return Some(Err(Box::new(e)));
618+
},
609619
}
610620
}
611621
None

0 commit comments

Comments
 (0)