Class SendBuffer

java.lang.Object
io.github.mahmoudimus.quic.connection.SendBuffer

public final class SendBuffer extends Object
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 Classes
    Modifier and Type
    Class
    Description
    static final record 
    The range pollTransmit(int) chose to send next.
  • Constructor Summary

    Constructors
    Constructor
    Description
    An empty buffer at offset zero.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    ack(long start, long end)
    Records that the peer acknowledged a range, releasing any acknowledged prefix.
    long
    The bytes still held from application writes, including acknowledged bytes that cannot be released yet.
    void
    Releases all data while keeping the final offset, for RESET_STREAM.
    get(long start, long end)
    The data of a range.
    boolean
    Whether there is data to send, new or lost.
    boolean
    Whether every written byte has been acknowledged.
    long
    The offset the next write starts at.
    pollTransmit(int maxLength)
    Chooses the next range to send, lost data first, and records it as sent.
    void
    retransmit(long start, long end)
    Queues a sent but unacknowledged range to be sent again.
    void
    Marks everything unsent again, after the server rejected 0-RTT data.
    void
    Appends data to the end of the stream.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SendBuffer

      public SendBuffer()
      An empty buffer at offset zero.
  • Method Details

    • write

      public void write(ByteBuffer data)
      Appends data to the end of the stream. The buffer keeps a view of data; 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 offset
      end - one past the last acknowledged offset
    • pollTransmit

      public SendBuffer.Transmit pollTransmit(int maxLength)
      Chooses the next range to send, lost data first, and records it as sent.

      maxLength includes 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

      public ByteBuffer get(long start, long end)
      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 buffered
      end - one past the last offset
      Returns:
      a read-only view of a prefix of the range, empty if start is 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 offset
      end - 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