Package org.drasyl.handler.connection
Class SendBuffer
java.lang.Object
org.drasyl.handler.connection.SendBuffer
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 TypeMethodDescriptionboolean
doPush()
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
isEmpty()
long
length()
The number of readable bytes.void
push()
final io.netty.buffer.ByteBuf
read
(long bytes, AtomicBoolean doPush, io.netty.channel.ChannelPromise promise) Attempts to retrieve a maximum ofbytes
from this buffer.void
release()
Release all buffers in the queue and complete all listeners and promises.toString()
-
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 queuepromise
- 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 ofbytes
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 invokesChannel.flush()
. This typically occurs when the sender has finished writing a complete message to the channel.- Parameters:
bytes
- bytes to readdoPush
- thisAtomicBoolean
is set totrue
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
-
toString
-