Class SendBuffer
java.lang.Object
io.github.mahmoudimus.quic.connection.SendBuffer
The outgoing data of one stream that is not yet acknowledged: what the application wrote, what
has been sent, what was deemed lost and must be sent again, and which ranges the peer has
acknowledged.
Data stays buffered until every byte before it is acknowledged, so a selectively acknowledged range keeps its storage until the gap before it closes.
Threads. Not thread-safe; a buffer belongs to one stream of one connection, which serializes access.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordThe rangepollTransmit(int)chose to send next. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidack(long start, long end) Records that the peer acknowledged a range, releasing any acknowledged prefix.longbuffered()The bytes still held from application writes, including acknowledged bytes that cannot be released yet.voiddiscard()Releases all data while keeping the final offset, for RESET_STREAM.get(long start, long end) The data of a range.booleanWhether there is data to send, new or lost.booleanWhether every written byte has been acknowledged.longoffset()The offset the next write starts at.pollTransmit(int maxLength) Chooses the next range to send, lost data first, and records it as sent.voidretransmit(long start, long end) Queues a sent but unacknowledged range to be sent again.voidMarks everything unsent again, after the server rejected 0-RTT data.voidwrite(ByteBuffer data) Appends data to the end of the stream.
-
Constructor Details
-
SendBuffer
public SendBuffer()An empty buffer at offset zero.
-
-
Method Details
-
write
Appends data to the end of the stream. The buffer keeps a view ofdata; the caller must not change its contents afterwards.- Parameters:
data- the bytes between the position and limit; the buffer itself is not changed
-
ack
public void ack(long start, long end) Records that the peer acknowledged a range, releasing any acknowledged prefix.- Parameters:
start- the first acknowledged offsetend- one past the last acknowledged offset
-
pollTransmit
Chooses the next range to send, lost data first, and records it as sent.maxLengthincludes the space for the STREAM frame's Offset and Length fields; it must be at least 16 so that both fit at their largest.- Parameters:
maxLength- the bytes available for the offset, length and data- Returns:
- the range to send, empty when there is nothing (but perhaps a FIN) to send
-
get
The data of a range. The data may be stored in pieces, so the result can be a prefix of the range; call again from the next offset for the rest.- Parameters:
start- the first offset, which must still be bufferedend- one past the last offset- Returns:
- a read-only view of a prefix of the range, empty if
startis not buffered
-
discard
public void discard()Releases all data while keeping the final offset, for RESET_STREAM. -
retransmit
public void retransmit(long start, long end) Queues a sent but unacknowledged range to be sent again.- Parameters:
start- the first lost offsetend- one past the last lost offset, at most the first unsent offset
-
retransmitAllForZeroRtt
public void retransmitAllForZeroRtt()Marks everything unsent again, after the server rejected 0-RTT data. -
offset
public long offset()The offset the next write starts at.- Returns:
- the total bytes written
-
isFullyAcked
public boolean isFullyAcked()Whether every written byte has been acknowledged.- Returns:
- true if nothing is unacknowledged
-
hasUnsentData
public boolean hasUnsentData()Whether there is data to send, new or lost. There may be unacknowledged data even when there is not.- Returns:
- true if
pollTransmit(int)would return data
-
buffered
public long buffered()The bytes still held from application writes, including acknowledged bytes that cannot be released yet.- Returns:
- the retained bytes
-