Przemyslaw Bielicki wrote:
Hi,
I posted my question on wildfly-dev
(
http://lists.jboss.org/pipermail/wildfly-dev/2014-March/001986.html)
but I think this one is better, as the implementation is in
undertow-servlet, not in wildfly itself.
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).
This is not guaranteed to work, as the underlying request objects are
not thread safe.
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();
}
That is just a question about what happens if you call isReady() when
the stream is not in async mode. Basically the spec does not say what to
do, so we just throw an exception. If you are getting this exception you
are using the stream wrong.
If you want to use async IO you need to register a write listener.
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?
We just buffer the input, and then write it out in the background, then
call the write listener again when we are done.
Stuart
Cheers,
Przemyslaw
_______________________________________________
undertow-dev mailing list
undertow-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/undertow-dev