Reputation: 53
If I obtain a SocketChannel
that is set to the non-blocking mode, what happens when I write to the channel and the underlying socket buffer is full because the other side cannot keep up? Would the data be discarded or something to that effect?
Upvotes: 1
Views: 523
Reputation: 310913
The write()
method returns zero and the data stays in the ByteBuffer
. At that point you should register the channel for OP_WRITE
, remember the output buffer, return to the select loop. When the channel becomes writable, retry the write, and this time as long as it completes, i.e. doesn't return zero or less than the remaining bytes in the buffer to be written, deregister OP_WRITE
.
Upvotes: 2