tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From igaz <>
Subject Re: Getting my head around NIO 'simulated' blocking (trying to)
Date Sat, 23 Mar 2013 16:46:44 GMT
OK, did a quick check of the servlet spec - and I could find nothing that
proscribes the kind of thing I was thinking about (in fact it has nothing to
say even about the semantics of using the javax.servlet.ServletInputStream)

Here is some pseudocode for what I had in mind (I'm eliding quite a bit:

    void readSocket(SocketChannel sc)
               ByteBuffer bb = ..
               while (requestIncomplete(bb))
                          int bread =; //non-blocking read
                          if (bread == 0) // socket has no bytes in
receive-buffer, need to re-register with selector
// 're-register socket with selector for reads
                          else if (bread == -1) // socket closed - clean up     
               //all bytes on socket (constituting an http request) have
been read
               RequestExecutor r  = ...
               r.execute(new Handler(bb))


Note requestIncomplete() returns true only when the *entire* http request
(headers and body) has been read.
Now, this is idiomatic java nio and I have used this pattern in implementing
my own nio server (not for http requests)
I see nothing in the servlet spec that would proscribe this and it scales

Yet it seems that Tomcats NIO connector does not do this.  Hence, my

View this message in context:
Sent from the Tomcat - Dev mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message