java.lang.Object
io.github.mahmoudimus.quic.connection.Chunks
All Implemented Interfaces:
AutoCloseable

public final class Chunks extends Object implements AutoCloseable
A read in progress on one stream, from StreamsState.read(io.github.mahmoudimus.quic.connection.StreamId, boolean, io.github.mahmoudimus.quic.connection.Retransmits). Take chunks with next(int), then call close(): flow control credit for the bytes read is issued only then, so a peer blocked on this stream stays blocked until the reader closes.

Use it with try-with-resources, within one locked section of the connection; it is not thread-safe.

  • Method Summary

    Modifier and Type
    Method
    Description
    long
    The number of bytes read so far.
    void
    Ends the read and issues flow control credit for what was read: MAX_STREAM_DATA, MAX_DATA and, if the stream was released, MAX_STREAMS, queued as needed.
    next(int maxLength)
    The next chunk.
    boolean
    Whether closing queued a frame that should be sent soon to unblock the peer.

    Methods inherited from class java.lang.Object

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

    • next

      public Chunk next(int maxLength) throws StreamException
      The next chunk. In ordered mode chunks follow each other; otherwise their offsets say where they belong.
      Parameters:
      maxLength - the most bytes to return
      Returns:
      the chunk, or null at the end of the stream (the stream is then released)
      Throws:
      StreamException - BLOCKED if no data is available yet, RESET if the peer reset the stream (the stream is then released)
      IllegalStateException - after close()
    • bytesRead

      public long bytesRead()
      The number of bytes read so far.
      Returns:
      bytes
    • close

      public void close()
      Ends the read and issues flow control credit for what was read: MAX_STREAM_DATA, MAX_DATA and, if the stream was released, MAX_STREAMS, queued as needed. Repeated calls do nothing.
      Specified by:
      close in interface AutoCloseable
    • shouldTransmit

      public boolean shouldTransmit()
      Whether closing queued a frame that should be sent soon to unblock the peer.
      Returns:
      true after close() queued MAX_DATA, MAX_STREAM_DATA or MAX_STREAMS