[undertow-dev] HTTP Upgrade in Servlet 3.1 - how to use non-blocking input & output at the same time

Przemyslaw Bielicki pbielicki at gmail.com
Tue Apr 1 04:52:28 EDT 2014


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). 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?

Cheers,
Przemyslaw
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/undertow-dev/attachments/20140401/9c3cd082/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: EchoHandler.java
Type: application/octet-stream
Size: 1477 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/undertow-dev/attachments/20140401/9c3cd082/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: EchoReadListener.java
Type: application/octet-stream
Size: 1050 bytes
Desc: not available
Url : http://lists.jboss.org/pipermail/undertow-dev/attachments/20140401/9c3cd082/attachment-0001.obj 


More information about the undertow-dev mailing list