From 9a02a4e57af67bca97fe28d647b1797f24b01b8b Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 1 Feb 2010 02:59:43 +0000 Subject: [PATCH] no frame byte git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1225 7e9141cc-0065-0410-87d8-b60c137991c4 --- .../eclipse/jetty/websocket/WebSocket.java | 1 + .../jetty/websocket/WebSocketConnection.java | 7 + .../jetty/websocket/WebSocketTest.java | 2 +- .../jetty/websocket/WebSocketTestClient.java | 206 ------------------ 4 files changed, 9 insertions(+), 207 deletions(-) delete mode 100644 jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketTestClient.java diff --git a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocket.java b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocket.java index 525dddf39b0..05a5106c2e1 100644 --- a/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocket.java +++ b/jetty-websocket/src/main/java/org/eclipse/jetty/websocket/WebSocket.java @@ -13,6 +13,7 @@ public interface WebSocket public interface Outbound { + void sendMessage(String data) throws IOException; void sendMessage(byte frame,String data) throws IOException; void sendMessage(byte frame,byte[] data) throws IOException; void sendMessage(byte frame,byte[] data, int offset, int length) throws IOException; 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 7844e2a168d..ebd8715a5b1 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 @@ -142,6 +142,13 @@ public class WebSocketConnection implements Connection, WebSocket.Outbound return _timestamp; } + public void sendMessage(String content) throws IOException + { + _generator.addFrame(WebSocket.SENTINEL_FRAME,content,_maxIdleTimeMs); + _generator.flush(); + _idle.access(_endp); + } + public void sendMessage(byte frame, String content) throws IOException { _generator.addFrame(frame,content,_maxIdleTimeMs); diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketTest.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketTest.java index 7fa6bf850cd..438acdbde08 100644 --- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketTest.java +++ b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketTest.java @@ -114,7 +114,7 @@ public class WebSocketTest extends TestCase _outbound=outbound; try { - _outbound.sendMessage(SENTINEL_FRAME,"Roger That"); + _outbound.sendMessage("Roger That"); } catch (IOException e) { diff --git a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketTestClient.java b/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketTestClient.java deleted file mode 100644 index baef2429ddd..00000000000 --- a/jetty-websocket/src/test/java/org/eclipse/jetty/websocket/WebSocketTestClient.java +++ /dev/null @@ -1,206 +0,0 @@ -package org.eclipse.jetty.websocket; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.nio.channels.SelectionKey; -import java.nio.channels.SocketChannel; - -import org.eclipse.jetty.io.ByteArrayBuffer; -import org.eclipse.jetty.io.ConnectedEndPoint; -import org.eclipse.jetty.io.Connection; -import org.eclipse.jetty.io.nio.IndirectNIOBuffer; -import org.eclipse.jetty.io.nio.SelectChannelEndPoint; -import org.eclipse.jetty.io.nio.SelectorManager; -import org.eclipse.jetty.io.nio.SelectorManager.SelectSet; -import org.eclipse.jetty.util.StringUtil; -import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.eclipse.jetty.util.component.LifeCycle; -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.thread.QueuedThreadPool; -import org.eclipse.jetty.util.thread.ThreadPool; - -public class WebSocketTestClient extends AbstractLifeCycle -{ - final ThreadPool _threadpool = new QueuedThreadPool(); - final WebSocketBuffers _buffers = new WebSocketBuffers(4*4096); - - SelectorManager _manager = new SelectorManager() - { - @Override - protected SocketChannel acceptChannel(SelectionKey key) throws IOException - { - throw new IllegalStateException(); - } - - @Override - public boolean dispatch(Runnable task) - { - return _threadpool.dispatch(task); - } - - @Override - protected void endPointClosed(SelectChannelEndPoint endpoint) - { - } - - @Override - protected void endPointOpened(SelectChannelEndPoint endpoint) - { - } - - @Override - protected void endPointUpgraded(ConnectedEndPoint endpoint, Connection oldConnection) - { - } - - @Override - protected Connection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint) - { - WebSocket ws=(WebSocket)endpoint.getSelectionKey().attachment(); - WebSocketConnection connection = new WebSocketConnection(ws,endpoint,_buffers,System.currentTimeMillis(), 30000); - - // TODO Blocking upgrade code. Should be async - ByteArrayBuffer upgrade=new ByteArrayBuffer( - "GET / HTTP/1.1\r\n"+ - "Host: localhost:8080\r\n" + - "Upgrade: WebSocket\r\n" + - "Connection: Upgrade\r\n" + - "\r\n"); - try - { - while (upgrade.length()>0 && endpoint.isOpen()) - { - int l = endpoint.flush(upgrade); - if (l>0) - upgrade.skip(l); - Thread.sleep(10); - } - IndirectNIOBuffer upgraded = new IndirectNIOBuffer(2048); - String up; - do - { - endpoint.fill(upgraded); - up=upgraded.toString(); - } - while(endpoint.isOpen() && !up.contains("\r\n\r\n")); - } - catch(Exception e) - { - Log.warn(e); - } - - ws.onConnect(connection); - - return connection; - } - - @Override - protected SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key) throws IOException - { - SelectChannelEndPoint ep=new SelectChannelEndPoint(channel,selectSet,key); - return ep; - } - - }; - - protected void doStart() - throws Exception - { - ((LifeCycle)_threadpool).start(); - _manager.start(); - - _threadpool.dispatch(new Runnable() - { - - public void run() - { - while (isRunning()) - { - try - { - _manager.doSelect(0); - } - catch (Exception e) - { - Log.warn(e.toString()); - Log.debug(e); - Thread.yield(); - } - } - } - }); - - - } - - public void open(SocketAddress addr, WebSocket websocket) - throws IOException - { - SocketChannel channel = SocketChannel.open(); - channel.configureBlocking( false ); - channel.connect(addr); - - _manager.register( channel, websocket); - } - - public static void main(String[] args) - throws Exception - { - WebSocketTestClient client = new WebSocketTestClient(); - client.start(); - - TestWebSocket[] ws=new TestWebSocket[100]; - - for (int i=0;i