Mercurial Hosting > luan
changeset 962:94498d6daf5b
remove SelectChannelEndPoint._interestOps
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 13 Oct 2016 22:56:15 -0600 |
parents | 790c01734386 |
children | 4b6216fa9cec |
files | src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java src/org/eclipse/jetty/io/nio/SelectorManager.java |
diffstat | 2 files changed, 20 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
diff -r 790c01734386 -r 94498d6daf5b src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java --- a/src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java Thu Oct 13 22:03:24 2016 -0600 +++ b/src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java Thu Oct 13 22:56:15 2016 -0600 @@ -53,9 +53,6 @@ public void run() { handle(); } }; - /** The desired value for {@link SelectionKey#interestOps()} */ - private int _interestOps; - /** * The connection instance is the handler for any IO activity on the endpoint. * There is a different type of connection for HTTP, AJP, WebSocket and @@ -141,8 +138,8 @@ if ((_key.readyOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE && (_key.interestOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) { // Remove writeable op - _interestOps = _key.interestOps() & ~SelectionKey.OP_WRITE; - _key.interestOps(_interestOps); + int interestOps = _key.interestOps() & ~SelectionKey.OP_WRITE; + _key.interestOps(interestOps); _writable = true; // Once writable is in ops, only removed with dispatch. } @@ -325,57 +322,27 @@ * are removed as this is only done during dispatch. This method records the new key and * schedules a call to doUpdateKey to do the keyChange */ - private void updateKey() + private synchronized void updateKey() { - final boolean changed; - synchronized (this) + if( getChannel().isOpen() && _key.isValid()) { - int current_ops=-1; - if (getChannel().isOpen()) - { - boolean read_interest = _readBlocked || (_state<STATE_DISPATCHED && !_connection.isSuspended()); - boolean write_interest= _writeBlocked || (_state<STATE_DISPATCHED && !_writable); + boolean read_interest = _readBlocked || (_state<STATE_DISPATCHED && !_connection.isSuspended()); + boolean write_interest= _writeBlocked || (_state<STATE_DISPATCHED && !_writable); - _interestOps = - ((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0) - | ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0); - try - { - current_ops = ((_key.isValid())?_key.interestOps():-1); - } - catch(Exception e) - { - _key.cancel(); - LOG.trace("",e); - } + int interestOps = + ((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0) + | ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0); + if( _key.interestOps() != interestOps ) { + _key.interestOps(interestOps); + _selectSet.getSelector().update(); } - changed = _interestOps!=current_ops; - } - - if(changed) - { - doUpdateKey(); - _selectSet.getSelector().update(); + } else { + _key.cancel(); + // update needed? } } - /* ------------------------------------------------------------ */ - /** - * Synchronize the interestOps with the actual key. Call is scheduled by a call to updateKey - */ - synchronized void doUpdateKey() - { - if (getChannel().isOpen()) - { - _key.interestOps(_interestOps); - } - else - { - _key.cancel(); - } - } - private void handle() { try @@ -478,7 +445,7 @@ { keyString += "!"; } - return String.format("SCEP@%x{l(%s)<->r(%s),s=%d,open=%b,ishut=%b,oshut=%b,rb=%b,wb=%b,w=%b,i=%d%s}-{%s}", + return String.format("SCEP@%x{l(%s)<->r(%s),s=%d,open=%b,ishut=%b,oshut=%b,rb=%b,wb=%b,w=%b,i=%s}-{%s}", hashCode(), _socket.getRemoteSocketAddress(), _socket.getLocalSocketAddress(), @@ -489,7 +456,6 @@ _readBlocked, _writeBlocked, _writable, - _interestOps, keyString, _connection); }
diff -r 790c01734386 -r 94498d6daf5b src/org/eclipse/jetty/io/nio/SelectorManager.java --- a/src/org/eclipse/jetty/io/nio/SelectorManager.java Thu Oct 13 22:03:24 2016 -0600 +++ b/src/org/eclipse/jetty/io/nio/SelectorManager.java Thu Oct 13 22:56:15 2016 -0600 @@ -211,7 +211,7 @@ endpoint.setConnection(newConnection(channel,endpoint)); key.attach(endpoint); - key.interestOps(SelectionKey.OP_READ); +// key.interestOps(SelectionKey.OP_READ); _selector.update(); //System.out.println("qqqqqqqqqqqqqqqqqqqqqqqqqqqqq b"); endpoint.schedule(); @@ -239,9 +239,6 @@ if (!key.isValid()) { key.cancel(); - SelectChannelEndPoint endpoint = (SelectChannelEndPoint)key.attachment(); - if (endpoint != null) - endpoint.doUpdateKey(); continue; } @@ -252,14 +249,12 @@ } catch (CancelledKeyException e) { - LOG.trace("",e); +// LOG.trace("",e); + LOG.warn("",e); } catch (Exception e) { - if (isRunning()) - LOG.warn("",e); - else - LOG.trace("",e); + LOG.warn("",e); } }