1

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.