I would like to use non-blocking input and output at the same time. For the simplicity let's implement EchoProtocol - check the attachments.
As you see, the writer is in a separate thread created by manually (which is a bit smelly IMHO). Another point is that I do the write directly without checking whether I can write without blocking. In fact, when I call ServletOutputStream.isReady() I get the Undertow error: "UT010034: Stream not in async mode"
Checking the source code you are not really sure if it's a correct behaviour:
io.undertow.servlet.spec.UpgradeServletOutputStream
io.undertow.servlet.spec.ServletOutputStreamImpl
@Override
public boolean isReady() {
if (listener == null) {
//TODO: is this the correct behaviour?
throw UndertowServletMessages.MESSAGES.streamNotInAsyncMode();
}Another point - more to non-blocking itself. How can ServletOutputStream.write(byte b[]) be non-blocking at all? Let's imagine that the socket is ready to write and I call write with a buffer of 1000 bytes but the receiver is ready only to receive 500 bytes at this point. My call will be blocked, right?