From 8aa6e5db9b79736d25646e7be7dff4cc21cee690 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Tue, 10 Jul 2012 14:45:37 -0700 Subject: [PATCH] Fixing WebSocketAsyncConnection.write() of byte[] arrays --- .../org/eclipse/jetty/websocket/io/ControlFrameBytes.java | 4 +--- .../org/eclipse/jetty/websocket/protocol/WebSocketFrame.java | 1 + .../jetty/websocket/server/WebSocketServletRFCTest.java | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/io/ControlFrameBytes.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/io/ControlFrameBytes.java index fe9fab4e889..74af9bc3de1 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/io/ControlFrameBytes.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/io/ControlFrameBytes.java @@ -4,7 +4,6 @@ import java.nio.ByteBuffer; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.websocket.generator.Generator; import org.eclipse.jetty.websocket.protocol.OpCode; import org.eclipse.jetty.websocket.protocol.WebSocketFrame; @@ -34,8 +33,7 @@ public class ControlFrameBytes extends FrameBytes { if (buffer == null) { - buffer = connection.getBufferPool().acquire(frame.getPayloadLength() + Generator.OVERHEAD,false); - connection.getGenerator().generate(frame); + buffer = connection.getGenerator().generate(frame); BufferUtil.flipToFlush(buffer,0); } return buffer; diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/WebSocketFrame.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/WebSocketFrame.java index 7212e9a2514..9b602b75d9d 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/WebSocketFrame.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/WebSocketFrame.java @@ -354,6 +354,7 @@ public class WebSocketFrame implements Frame data = ByteBuffer.allocate(len); BufferUtil.clearToFill(data); data.put(buf,0,len); + BufferUtil.flipToFill(data); return this; } diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java index 37006d003b1..607a8bb2920 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java @@ -160,7 +160,7 @@ public class WebSocketServletRFCTest int ccCount = 0; ByteBuffer echod = binmsg.getPayload(); - while (echod.remaining() > 1) + while (echod.remaining() >= 1) { byte b = echod.get(); switch (b)