diff --git a/VERSION.txt b/VERSION.txt index f4f7f27657e..838d8e8dff7 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1,3 +1,6 @@ +jetty-7.1.5-SNAPSHOT + + 316449 Websocket disconnect fix + jetty-7.1.4.v20100610 + 298551 SslSocketConnector does not need keystore stream + 295715 AbstractSessionManager decoupled from Context 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 6f37933cdfa..4da76115069 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 @@ -186,7 +186,6 @@ public class WebSocketConnection implements Connection, WebSocket.Outbound } catch(IOException e) { - e.printStackTrace(); throw e; } finally diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketGenerator.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketGenerator.java index 7c4b4ef0422..3666b3b07d3 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketGenerator.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocketGenerator.java @@ -7,6 +7,7 @@ import java.security.NoSuchAlgorithmException; import org.eclipse.jetty.io.Buffer; import org.eclipse.jetty.io.EndPoint; +import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.util.log.Log; @@ -98,6 +99,8 @@ public class WebSocketGenerator private synchronized void bufferPut(byte datum, long blockFor) throws IOException { + if (_buffer==null) + _buffer=_buffers.getDirectBuffer(); _buffer.put(datum); if (_buffer.space() == 0) expelBuffer(blockFor); @@ -128,7 +131,7 @@ public class WebSocketGenerator private synchronized int flushBuffer() throws IOException { if (!_endp.isOpen()) - throw new IOException("Closed"); + throw new EofException(); if (_buffer!=null) return _endp.flush(_buffer); @@ -138,6 +141,8 @@ public class WebSocketGenerator private synchronized int expelBuffer(long blockFor) throws IOException { + if (_buffer==null) + return 0; int result = flushBuffer(); _buffer.compact(); if (!_endp.isBlocking()) diff --git a/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java b/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java index 4ba4b542042..3b1e3090f4a 100644 --- a/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java +++ b/test-jetty-webapp/src/main/java/com/acme/WebSocketChatServlet.java @@ -50,16 +50,21 @@ public class WebSocketChatServlet extends WebSocketServlet public void onMessage(byte frame, String data) { - // Log.info(this+" onMessage: "+data); - for (ChatWebSocket member : _members) + if (data.indexOf("disconnect")>=0) + _outbound.disconnect(); + else { - try + // Log.info(this+" onMessage: "+data); + for (ChatWebSocket member : _members) { - member._outbound.sendMessage(frame,data); - } - catch(IOException e) - { - Log.warn(e); + try + { + member._outbound.sendMessage(frame,data); + } + catch(IOException e) + { + Log.warn(e); + } } } }