diff --git a/VERSION.txt b/VERSION.txt index 05db01c41e9..a14212e9372 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -39,6 +39,7 @@ jetty-7.2-SNAPSHOT + JETTY-1261 errant listener usage in StandardDescriptorProcessor + JETTY-1263 JDBCSessionIdManager table creation fails on Oracle + JETTY-1269 Improve log multithreadedness + + JETTY-1270 Websocket closed endp protection + JETTY-1271 handled unavailable exception + Fix jetty-plus.xml for new configuration names + Added ignore to Logger interface diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnection.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnection.java index edc7c2b1973..e7ce154384e 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnection.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketConnection.java @@ -1,5 +1,6 @@ package org.eclipse.jetty.websocket; +import java.io.IOError; import java.io.IOException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; @@ -24,7 +25,7 @@ public class WebSocketConnection implements Connection, WebSocket.Outbound final WebSocket _websocket; String _key1; String _key2; - ByteArrayBuffer _hixie; + ByteArrayBuffer _hixieBytes; public WebSocketConnection(WebSocket websocket, EndPoint endpoint,int draft) throws IOException @@ -141,63 +142,58 @@ public class WebSocketConnection implements Connection, WebSocket.Outbound { _key1=key1; _key2=key2; - _hixie=new IndirectNIOBuffer(16); + _hixieBytes=new IndirectNIOBuffer(16); } public Connection handle() throws IOException { - boolean progress=true; - try { // handle stupid hixie random bytes - if (_hixie!=null) + if (_hixieBytes!=null) { - while(progress) + + // take any available bytes from the parser buffer, which may have already been read + Buffer buffer=_parser.getBuffer(); + if (buffer!=null && buffer.length()>0) + { + int l=buffer.length(); + if (l>(8-_hixieBytes.length())) + l=8-_hixieBytes.length(); + _hixieBytes.put(buffer.peek(buffer.getIndex(),l)); + buffer.skip(l); + } + + // while we are not blocked + while(_endp.isOpen()) { - // take bytes from the parser buffer. - Buffer buffer=_parser.getBuffer(); - if (buffer!=null && buffer.length()>0) - { - int l=buffer.length(); - if (l>8) - l=8; - _hixie.put(buffer.peek(buffer.getIndex(),l)); - buffer.skip(l); - progress=true; - } - - // do we have enough? - if (_hixie.length()<8) - { - // no, then let's fill - int filled=_endp.fill(_hixie); - progress |= filled>0; - - if (filled<0) - { - _endp.close(); - break; - } - } - // do we now have enough - if (_hixie.length()==8) + if (_hixieBytes.length()==8) { // we have the silly random bytes // so let's work out the stupid 16 byte reply. doTheHixieHixieShake(); - _endp.flush(_hixie); - _hixie=null; + _endp.flush(_hixieBytes); + _hixieBytes=null; _endp.flush(); break; } + + // no, then let's fill + int filled=_endp.fill(_hixieBytes); + if (filled<0) + { + _endp.close(); + break; + } } return this; } // handle the framing protocol + boolean progress=true; + while (progress) { int flushed=_generator.flush(); @@ -214,6 +210,14 @@ public class WebSocketConnection implements Connection, WebSocket.Outbound } catch(IOException e) { + try + { + _endp.close(); + } + catch(IOException e2) + { + Log.ignore(e2); + } throw e; } finally @@ -235,9 +239,9 @@ public class WebSocketConnection implements Connection, WebSocket.Outbound byte[] result=WebSocketConnection.doTheHixieHixieShake( WebSocketConnection.hixieCrypt(_key1), WebSocketConnection.hixieCrypt(_key2), - _hixie.asArray()); - _hixie.clear(); - _hixie.put(result); + _hixieBytes.asArray()); + _hixieBytes.clear(); + _hixieBytes.put(result); } public boolean isOpen()