Class SendBuffer

java.lang.Object
org.drasyl.handler.connection.SendBuffer

public class SendBuffer extends Object
Represents the send buffer that holds outgoing segments waiting to be sent over a connection.

The send buffer is responsible for managing the buffer of outgoing segments that are waiting to be sent over the network. The send buffer is distinct from the outgoing segment queue, which is a separate data structure that holds segments that have been scheduled for transmission, but not yet sent. The send buffer, on the other hand, stores segments that are waiting to be scheduled for transmission.

  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    void
    enqueue(io.netty.buffer.ByteBuf buf)
     
    void
    enqueue(io.netty.buffer.ByteBuf buf, io.netty.channel.ChannelPromise promise)
    Add a buffer to the end of the queue and associate a promise with it that should be completed when all the buffer's bytes have been consumed from the queue and written.
    void
     
    boolean
     
    long
    The number of readable bytes.
    void
     
    final io.netty.buffer.ByteBuf
    read(long bytes, AtomicBoolean doPush, io.netty.channel.ChannelPromise promise)
    Attempts to retrieve a maximum of bytes from this buffer.
    void
    Release all buffers in the queue and complete all listeners and promises.
     

    Methods inherited from class java.lang.Object

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

    • enqueue

      public void enqueue(io.netty.buffer.ByteBuf buf, io.netty.channel.ChannelPromise promise)
      Add a buffer to the end of the queue and associate a promise with it that should be completed when all the buffer's bytes have been consumed from the queue and written.
      Parameters:
      buf - to add to the tail of the queue
      promise - to complete when all the bytes have been consumed and written, can be void.
    • enqueue

      public void enqueue(io.netty.buffer.ByteBuf buf)
    • push

      public void push()
    • doPush

      public boolean doPush()
    • read

      public final io.netty.buffer.ByteBuf read(long bytes, AtomicBoolean doPush, io.netty.channel.ChannelPromise promise)
      Attempts to retrieve a maximum of bytes from this buffer. However, there are two scenarios where fewer bytes than requested may be returned:
      (1) If the buffer doesn't contain as many bytes as requested. In this case, the entire buffer content is returned.
      (2) If a byte read from the buffer has been marked for immediate delivery to the recipient's application. This "push" mark is set once the sender invokes Channel.flush(). This typically occurs when the sender has finished writing a complete message to the channel.
      Parameters:
      bytes - bytes to read
      doPush - this AtomicBoolean is set to true if a byte that needs to be pushed has been read.
    • length

      public long length()
      The number of readable bytes.
    • isEmpty

      public boolean isEmpty()
    • release

      public void release()
      Release all buffers in the queue and complete all listeners and promises.
    • fail

      public void fail(ConnectionException e)
    • toString

      public String toString()
      Overrides:
      toString in class Object