diff --git a/relay-java/src/main/java/com/genymobile/gnirehtet/relay/DatagramBuffer.java b/relay-java/src/main/java/com/genymobile/gnirehtet/relay/DatagramBuffer.java index 9516bcb..9608bd9 100644 --- a/relay-java/src/main/java/com/genymobile/gnirehtet/relay/DatagramBuffer.java +++ b/relay-java/src/main/java/com/genymobile/gnirehtet/relay/DatagramBuffer.java @@ -65,8 +65,8 @@ public boolean hasEnoughSpaceFor(int datagramLength) { // there is at least the extra space for storing 1 packet return true; } - int remaining = tail - head - 1; - return HEADER_LENGTH + datagramLength < remaining; + int remaining = tail - head - 1; // 1 extra byte to distinguish empty vs full + return HEADER_LENGTH + datagramLength <= remaining; } public int capacity() { diff --git a/relay-rust/src/relay/datagram_buffer.rs b/relay-rust/src/relay/datagram_buffer.rs index 91bfcde..7ab6084 100644 --- a/relay-rust/src/relay/datagram_buffer.rs +++ b/relay-rust/src/relay/datagram_buffer.rs @@ -63,8 +63,9 @@ impl DatagramBuffer { // there is at least the extra space for storing 1 packet return true; } - let remaining = self.tail - self.head + 1; - HEADER_LENGTH + datagram_length < remaining + // 1 extra byte to distinguish empty vs full + let remaining = self.tail - self.head - 1; + HEADER_LENGTH + datagram_length <= remaining } pub fn write_to(&mut self, destination: &mut S) -> io::Result<()> {