From 529e04295f5b7b290c7532cc9f26dce6abca03ba Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Thu, 1 Apr 2010 21:24:25 +0000 Subject: [PATCH] Fixed tests. git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1437 7e9141cc-0065-0410-87d8-b60c137991c4 --- .../jetty/websocket/WebSocketGenerator.java | 64 ++++--------------- .../jetty/websocket/WebSocketParser.java | 32 +++++----- .../websocket/WebSocketGeneratorTest.java | 17 +++-- 3 files changed, 38 insertions(+), 75 deletions(-) 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 0207c0ae762..c13b0f31192 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 @@ -39,7 +39,7 @@ public class WebSocketGenerator if (_buffer.space() == 0) expelBuffer(blockFor); - if ((frame & WebSocket.LENGTH_FRAME) == WebSocket.LENGTH_FRAME) + if (isLengthFrame(frame)) { // Send a length delimited frame @@ -77,7 +77,7 @@ public class WebSocketGenerator remaining -= chunk; if (_buffer.space() > 0) { - if (frame == WebSocket.SENTINEL_FRAME) + if (!isLengthFrame(frame)) _buffer.put((byte)0xFF); // Gently flush the data, issuing a non-blocking write flushBuffer(); @@ -88,7 +88,7 @@ public class WebSocketGenerator expelBuffer(blockFor); if (remaining == 0) { - if (frame == WebSocket.SENTINEL_FRAME) + if (!isLengthFrame(frame)) _buffer.put((byte)0xFF); // Gently flush the data, issuing a non-blocking write flushBuffer(); @@ -97,57 +97,20 @@ public class WebSocketGenerator } } + private boolean isLengthFrame(byte frame) + { + return (frame & WebSocket.LENGTH_FRAME) == WebSocket.LENGTH_FRAME; + } + public synchronized void addFrame(byte frame, String content, int blockFor) throws IOException { byte[] bytes = content.getBytes("UTF-8"); addFrame(frame, bytes, 0, bytes.length, blockFor); } - private synchronized void checkSpace(int needed, long blockFor) - throws IOException + public synchronized int flush(long blockFor) throws IOException { - int space=_buffer.space(); - - if (space0 && _endp.blockWritable(blockFor)) - { - flushBuffer(); - _buffer.compact(); - space=_buffer.space(); - } - } - - if (space>7),0xff&_out.get()); - assertEquals(0x7f&b.length,0xff&_out.get()); + assertEquals(0x80|(0x7f&b.length),0xff&_out.get()); for (int i=0;i