349897 draft -09 websockets

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@3409 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2011-06-21 05:33:52 +00:00
parent aa990479f6
commit 451580e4ee
15 changed files with 141 additions and 202 deletions

View File

@ -8,6 +8,8 @@ jetty-7.4.3-SNAPSHOT
+ 349344 Passing empty query string to UrlEncoded#decodeTo(String, MultiMap, String) does not yield an empty map
+ 349738 set buffer sizes for http client in proxy servlet
+ 349870 proxy servlet protect continuation against fast failing exchanges
+ 349896 SCEP supports zero maxIdleTime
+ 349897 draft -09 websockets
+ JETTY-1342 Recreate selector in change task
jetty-7.4.2.v20110526

View File

@ -11,36 +11,16 @@ import org.eclipse.jetty.websocket.WebSocketParser.FrameHandler;
public class AbstractExtension implements Extension
{
private static final int[] __mask = { -1, 0x04, 0x02, 0x01};
private final String _name;
private final byte[] _dataOpcodes;
private final byte[] _controlOpcodes;
private final byte[] _bitMasks;
private final Map<String,String> _parameters=new HashMap<String, String>();
private FrameHandler _inbound;
private WebSocketGenerator _outbound;
private WebSocket.FrameConnection _connection;
public AbstractExtension(String name,int dataCodes, int controlCodes, int flags)
public AbstractExtension(String name)
{
_name = name;
_dataOpcodes=new byte[dataCodes];
_controlOpcodes=new byte[controlCodes];
_bitMasks=new byte[flags];
}
public int getDataOpcodes()
{
return _dataOpcodes.length;
}
public int getControlOpcodes()
{
return _controlOpcodes.length;
}
public int getReservedBits()
{
return _bitMasks.length;
}
public WebSocket.FrameConnection getConnection()
@ -75,19 +55,11 @@ public class AbstractExtension implements Extension
}
public void bind(WebSocket.FrameConnection connection, FrameHandler incoming, WebSocketGenerator outgoing, byte[] dataOpcodes, byte[] controlOpcodes, byte[] bitMasks)
public void bind(WebSocket.FrameConnection connection, FrameHandler incoming, WebSocketGenerator outgoing)
{
_connection=connection;
_inbound=incoming;
_outbound=outgoing;
if (dataOpcodes!=null)
System.arraycopy(dataOpcodes,0,_dataOpcodes,0,dataOpcodes.length);
if (controlOpcodes!=null)
System.arraycopy(controlOpcodes,0,_dataOpcodes,0,controlOpcodes.length);
if (bitMasks!=null)
System.arraycopy(bitMasks,0,_bitMasks,0,bitMasks.length);
// System.err.printf("bind %s[%s|%s|%s]\n",_name,TypeUtil.toHexString(dataOpcodes),TypeUtil.toHexString(controlOpcodes),TypeUtil.toHexString(bitMasks));
}
public String getName()
@ -130,46 +102,27 @@ public class AbstractExtension implements Extension
// System.err.printf("addFrame %s %x %x %d\n",getExtensionName(),flags,opcode,length);
_outbound.addFrame(flags,opcode,content,offset,length);
}
public byte dataOpcode(int i)
public byte setFlag(byte flags,int rsv)
{
return _dataOpcodes[i];
}
public int dataIndex(byte op)
{
for (int i=0;i<_dataOpcodes.length;i++)
if (_dataOpcodes[i]==op)
return i;
return -1;
}
public byte controlOpcode(int i)
{
return _dataOpcodes[i];
}
public int controlIndex(byte op)
{
for (int i=0;i<_controlOpcodes.length;i++)
if (_controlOpcodes[i]==op)
return i;
return -1;
if (rsv<1||rsv>3)
throw new IllegalArgumentException("rsv"+rsv);
byte b=(byte)(flags | __mask[rsv]);
return b;
}
public byte setFlag(byte flags,int flag)
public byte clearFlag(byte flags,int rsv)
{
return (byte)(flags | _bitMasks[flag]);
}
public byte clearFlag(byte flags,int flag)
{
return (byte)(flags & ~_bitMasks[flag]);
if (rsv<1||rsv>3)
throw new IllegalArgumentException("rsv"+rsv);
return (byte)(flags & ~__mask[rsv]);
}
public boolean isFlag(byte flags,int flag)
public boolean isFlag(byte flags,int rsv)
{
return (flags & _bitMasks[flag])!=0;
if (rsv<1||rsv>3)
throw new IllegalArgumentException("rsv"+rsv);
return (flags & __mask[rsv])!=0;
}
public String toString()

View File

@ -13,13 +13,13 @@ import org.eclipse.jetty.util.log.Log;
public class DeflateFrameExtension extends AbstractExtension
{
private int _minLength=64;
private int _minLength=8;
private Deflater _deflater;
private Inflater _inflater;
public DeflateFrameExtension()
{
super("x-deflate-frame",0,0,1);
super("x-deflate-frame");
}
@Override
@ -45,12 +45,12 @@ public class DeflateFrameExtension extends AbstractExtension
@Override
public void onFrame(byte flags, byte opcode, Buffer buffer)
{
if (getConnection().isControl(opcode) || !isFlag(flags,0))
if (getConnection().isControl(opcode) || !isFlag(flags,1))
{
super.onFrame(flags,opcode,buffer);
return;
}
if (buffer.array()==null)
buffer=buffer.asMutableBuffer();
@ -61,7 +61,8 @@ public class DeflateFrameExtension extends AbstractExtension
length=0;
while(b-->0)
length=0x100*length+(0xff&buffer.get());
}
}
// TODO check a max framesize
_inflater.setInput(buffer.array(),buffer.getIndex(),buffer.length());
@ -76,12 +77,12 @@ public class DeflateFrameExtension extends AbstractExtension
buf.setPutIndex(buf.putIndex()+inflated);
}
super.onFrame(clearFlag(flags,0),opcode,buf);
super.onFrame(clearFlag(flags,1),opcode,buf);
}
catch(DataFormatException e)
{
Log.warn(e);
getConnection().close(WebSocketConnectionD07.CLOSE_PROTOCOL,e.toString());
getConnection().close(WebSocketConnectionD7_9.CLOSE_PROTOCOL,e.toString());
}
}
@ -91,9 +92,9 @@ public class DeflateFrameExtension extends AbstractExtension
@Override
public void addFrame(byte flags, byte opcode, byte[] content, int offset, int length) throws IOException
{
if (getConnection().isControl(opcode) && length<_minLength)
if (getConnection().isControl(opcode) || length<_minLength)
{
super.addFrame(clearFlag(flags,0),opcode,content,offset,length);
super.addFrame(clearFlag(flags,1),opcode,content,offset,length);
return;
}
@ -133,8 +134,8 @@ public class DeflateFrameExtension extends AbstractExtension
int l = _deflater.deflate(out,out_offset,length-out_offset);
if (_deflater.finished())
super.addFrame(setFlag(flags,0),opcode,out,0,l+out_offset);
super.addFrame(setFlag(flags,1),opcode,out,0,l+out_offset);
else
super.addFrame(clearFlag(flags,0),opcode,content,offset,length);
super.addFrame(clearFlag(flags,1),opcode,content,offset,length);
}
}

View File

@ -6,11 +6,8 @@ public interface Extension extends WebSocketParser.FrameHandler, WebSocketGenera
{
public String getName();
public String getParameterizedName();
public int getDataOpcodes();
public int getControlOpcodes();
public int getReservedBits();
public boolean init(Map<String,String> parameters);
public void bind(WebSocket.FrameConnection connection, WebSocketParser.FrameHandler inbound, WebSocketGenerator outbound,byte[] dataOpCodes, byte[] controlOpcodes, byte[] bitMasks);
public void bind(WebSocket.FrameConnection connection, WebSocketParser.FrameHandler inbound, WebSocketGenerator outbound);
}

View File

@ -10,7 +10,7 @@ public class FragmentExtension extends AbstractExtension
public FragmentExtension()
{
super("fragment",0,0,0);
super("fragment");
}
@Override

View File

@ -4,6 +4,6 @@ public class IdentityExtension extends AbstractExtension
{
public IdentityExtension()
{
super("identity",0,0,0);
super("identity");
}
}

View File

@ -37,8 +37,8 @@ public class TestClient
private final BufferedWriter _output;
private final BufferedReader _input;
private final SocketEndPoint _endp;
private final WebSocketGeneratorD07 _generator;
private final WebSocketParserD07 _parser;
private final WebSocketGeneratorD7_9 _generator;
private final WebSocketParserD7_9 _parser;
private int _framesSent;
private int _messagesSent;
private int _framesReceived;
@ -59,19 +59,19 @@ public class TestClient
{
_framesReceived++;
_frames++;
if (opcode == WebSocketConnectionD07.OP_CLOSE)
if (opcode == WebSocketConnectionD7_9.OP_CLOSE)
{
byte[] data=buffer.asArray();
// System.err.println("CLOSED: "+((0xff&data[0])*0x100+(0xff&data[1]))+" "+new String(data,2,data.length-2,StringUtil.__UTF8));
_generator.addFrame((byte)0x8,WebSocketConnectionD07.OP_CLOSE,data,0,data.length);
_generator.addFrame((byte)0x8,WebSocketConnectionD7_9.OP_CLOSE,data,0,data.length);
_generator.flush();
_socket.shutdownOutput();
_socket.close();
return;
}
else if (opcode == WebSocketConnectionD07.OP_PING)
else if (opcode == WebSocketConnectionD7_9.OP_PING)
{
_generator.addFrame((byte)0x8,WebSocketConnectionD07.OP_PONG,buffer.array(),buffer.getIndex(),buffer.length());
_generator.addFrame((byte)0x8,WebSocketConnectionD7_9.OP_PONG,buffer.array(),buffer.getIndex(),buffer.length());
_generator.flush();
}
@ -81,7 +81,7 @@ public class TestClient
_opcode=opcode;
if (WebSocketConnectionD07.isLastFrame(flags))
if (WebSocketConnectionD7_9.isLastFrame(flags))
{
_messagesReceived++;
Long start=_starts.take();
@ -123,8 +123,8 @@ public class TestClient
_input = new BufferedReader(new InputStreamReader(_socket.getInputStream(), "ISO-8859-1"));
_endp=new SocketEndPoint(_socket);
_generator = new WebSocketGeneratorD07(new WebSocketBuffers(32*1024),_endp,new WebSocketGeneratorD07.FixedMaskGen(new byte[4]));
_parser = new WebSocketParserD07(new WebSocketBuffers(32*1024),_endp,_handler,false);
_generator = new WebSocketGeneratorD7_9(new WebSocketBuffers(32*1024),_endp,new WebSocketGeneratorD7_9.FixedMaskGen(new byte[4]));
_parser = new WebSocketParserD7_9(new WebSocketBuffers(32*1024),_endp,_handler,false);
}
public int getSize()
@ -170,7 +170,7 @@ public class TestClient
if (line.startsWith("Sec-WebSocket-Accept:"))
{
String accept=line.substring(21).trim();
accepted=accept.equals(WebSocketConnectionD07.hashKey(new String(B64Code.encode(key))));
accepted=accept.equals(WebSocketConnectionD7_9.hashKey(new String(B64Code.encode(key))));
}
else if (line.startsWith("Sec-WebSocket-Protocol:"))
{
@ -205,7 +205,7 @@ public class TestClient
break;
byte data[]=null;
if (opcode==WebSocketConnectionD07.OP_TEXT)
if (opcode==WebSocketConnectionD7_9.OP_TEXT)
{
StringBuilder b = new StringBuilder();
while (b.length()<_size)
@ -228,7 +228,7 @@ public class TestClient
{
_framesSent++;
byte flags= (byte)(off+len==data.length?0x8:0);
byte op=(byte)(off==0?opcode:WebSocketConnectionD07.OP_CONTINUATION);
byte op=(byte)(off==0?opcode:WebSocketConnectionD7_9.OP_CONTINUATION);
if (_verbose)
System.err.printf("%s#addFrame %s|%s %s\n",this.getClass().getSimpleName(),TypeUtil.toHexString(flags),TypeUtil.toHexString(op),TypeUtil.toHexString(data,off,len));
@ -330,9 +330,9 @@ public class TestClient
{
client.open();
if (protocol!=null && protocol.startsWith("echo"))
client.ping(count,binary?WebSocketConnectionD07.OP_BINARY:WebSocketConnectionD07.OP_TEXT,fragment);
client.ping(count,binary?WebSocketConnectionD7_9.OP_BINARY:WebSocketConnectionD7_9.OP_TEXT,fragment);
else
client.ping(count,WebSocketConnectionD07.OP_PING,-1);
client.ping(count,WebSocketConnectionD7_9.OP_PING,-1);
}
finally
{

View File

@ -38,7 +38,7 @@ import org.eclipse.jetty.websocket.WebSocket.OnTextMessage;
import org.eclipse.jetty.websocket.WebSocket.OnBinaryMessage;
import org.eclipse.jetty.websocket.WebSocket.OnControl;
public class WebSocketConnectionD07 extends AbstractConnection implements WebSocketConnection
public class WebSocketConnectionD7_9 extends AbstractConnection implements WebSocketConnection
{
final static byte OP_CONTINUATION = 0x00;
final static byte OP_TEXT = 0x01;
@ -69,9 +69,9 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
private final static byte[] MAGIC;
private final IdleCheck _idle;
private final List<Extension> _extensions;
private final WebSocketParserD07 _parser;
private final WebSocketParserD7_9 _parser;
private final WebSocketParser.FrameHandler _inbound;
private final WebSocketGeneratorD07 _generator;
private final WebSocketGeneratorD7_9 _generator;
private final WebSocketGenerator _outbound;
private final WebSocket _webSocket;
private final OnFrame _onFrame;
@ -79,6 +79,7 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
private final OnTextMessage _onTextMessage;
private final OnControl _onControl;
private final String _protocol;
private final int _draft;
private boolean _closedIn;
private boolean _closedOut;
private int _maxTextMessageSize;
@ -106,7 +107,7 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
/* ------------------------------------------------------------ */
public WebSocketConnectionD07(WebSocket websocket, EndPoint endpoint, WebSocketBuffers buffers, long timestamp, int maxIdleTime, String protocol, List<Extension> extensions)
public WebSocketConnectionD7_9(WebSocket websocket, EndPoint endpoint, WebSocketBuffers buffers, long timestamp, int maxIdleTime, String protocol, List<Extension> extensions,int draft)
throws IOException
{
super(endpoint,timestamp);
@ -115,6 +116,7 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
if (endpoint instanceof AsyncEndPoint)
((AsyncEndPoint)endpoint).cancelIdle();
_draft=draft;
_endp.setMaxIdleTime(maxIdleTime);
_webSocket = websocket;
@ -122,35 +124,18 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
_onTextMessage=_webSocket instanceof OnTextMessage ? (OnTextMessage)_webSocket : null;
_onBinaryMessage=_webSocket instanceof OnBinaryMessage ? (OnBinaryMessage)_webSocket : null;
_onControl=_webSocket instanceof OnControl ? (OnControl)_webSocket : null;
_generator = new WebSocketGeneratorD07(buffers, _endp,null);
_generator = new WebSocketGeneratorD7_9(buffers, _endp,null);
_extensions=extensions;
if (_extensions!=null)
{
byte data_op=OP_EXT_DATA;
byte ctrl_op=OP_EXT_CTRL;
byte flag_mask=0x4;
int e=0;
for (Extension extension : _extensions)
{
byte[] data_ops=new byte[extension.getDataOpcodes()];
for (int i=0;i<data_ops.length;i++)
data_ops[i]=data_op++;
byte[] ctrl_ops=new byte[extension.getControlOpcodes()];
for (int i=0;i<ctrl_ops.length;i++)
ctrl_ops[i]=ctrl_op++;
byte[] flag_masks=new byte[extension.getReservedBits()];
for (int i=0;i<flag_masks.length;i++)
{
flag_masks[i]=flag_mask;
flag_mask= (byte)(flag_mask>>1);
}
extension.bind(
_connection,
e==extensions.size()-1?_frameHandler:extensions.get(e+1),
e==0?_generator:extensions.get(e-1),
data_ops,ctrl_ops,flag_masks);
e==0?_generator:extensions.get(e-1));
e++;
}
}
@ -158,7 +143,7 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
_outbound=_extensions.size()==0?_generator:extensions.get(extensions.size()-1);
_inbound=_extensions.size()==0?_frameHandler:extensions.get(0);
_parser = new WebSocketParserD07(buffers, endpoint,_inbound,true);
_parser = new WebSocketParserD7_9(buffers, endpoint,_inbound,true);
_protocol=protocol;
@ -266,7 +251,7 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
@Override
public void idleExpired()
{
closeOut(WebSocketConnectionD07.CLOSE_NORMAL,"Idle");
closeOut(WebSocketConnectionD7_9.CLOSE_NORMAL,"Idle");
}
/* ------------------------------------------------------------ */
@ -278,7 +263,7 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
/* ------------------------------------------------------------ */
public void closed()
{
_webSocket.onClose(WebSocketConnectionD07.CLOSE_NORMAL,"");
_webSocket.onClose(WebSocketConnectionD7_9.CLOSE_NORMAL,"");
}
/* ------------------------------------------------------------ */
@ -313,11 +298,11 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
else
{
if (code<=0)
code=WebSocketConnectionD07.CLOSE_NORMAL;
code=WebSocketConnectionD7_9.CLOSE_NORMAL;
byte[] bytes = ("xx"+(message==null?"":message)).getBytes(StringUtil.__ISO_8859_1);
bytes[0]=(byte)(code/0x100);
bytes[1]=(byte)(code%0x100);
_outbound.addFrame((byte)0x8,WebSocketConnectionD07.OP_CLOSE,bytes,0,bytes.length);
_outbound.addFrame((byte)0x8,WebSocketConnectionD7_9.OP_CLOSE,bytes,0,bytes.length);
}
_outbound.flush();
@ -353,8 +338,8 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
private class FrameConnectionD07 implements WebSocket.FrameConnection
{
volatile boolean _disconnecting;
int _maxTextMessage=WebSocketConnectionD07.this._maxTextMessageSize;
int _maxBinaryMessage=WebSocketConnectionD07.this._maxBinaryMessageSize;
int _maxTextMessage=WebSocketConnectionD7_9.this._maxTextMessageSize;
int _maxBinaryMessage=WebSocketConnectionD7_9.this._maxBinaryMessageSize;
/* ------------------------------------------------------------ */
public synchronized void sendMessage(String content) throws IOException
@ -362,7 +347,7 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
if (_closedOut)
throw new IOException("closing");
byte[] data = content.getBytes(StringUtil.__UTF8);
_outbound.addFrame((byte)0x8,WebSocketConnectionD07.OP_TEXT,data,0,data.length);
_outbound.addFrame((byte)0x8,WebSocketConnectionD7_9.OP_TEXT,data,0,data.length);
checkWriteable();
_idle.access(_endp);
}
@ -372,7 +357,7 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
{
if (_closedOut)
throw new IOException("closing");
_outbound.addFrame((byte)0x8,WebSocketConnectionD07.OP_BINARY,content,offset,length);
_outbound.addFrame((byte)0x8,WebSocketConnectionD7_9.OP_BINARY,content,offset,length);
checkWriteable();
_idle.access(_endp);
}
@ -415,7 +400,7 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
if (_disconnecting)
return;
_disconnecting=true;
WebSocketConnectionD07.this.closeOut(code,message);
WebSocketConnectionD7_9.this.closeOut(code,message);
}
/* ------------------------------------------------------------ */
@ -540,7 +525,7 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
{
boolean lastFrame = isLastFrame(flags);
synchronized(WebSocketConnectionD07.this)
synchronized(WebSocketConnectionD7_9.this)
{
// Ignore incoming after a close
if (_closedIn)
@ -565,10 +550,10 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
switch(opcode)
{
case WebSocketConnectionD07.OP_CONTINUATION:
case WebSocketConnectionD7_9.OP_CONTINUATION:
{
// If text, append to the message buffer
if (_opcode==WebSocketConnectionD07.OP_TEXT && _connection.getMaxTextMessageSize()>=0)
if (_opcode==WebSocketConnectionD7_9.OP_TEXT && _connection.getMaxTextMessageSize()>=0)
{
if (_utf8.append(buffer.array(),buffer.getIndex(),buffer.length(),_connection.getMaxTextMessageSize()))
{
@ -583,7 +568,7 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
}
else
{
_connection.close(WebSocketConnectionD07.CLOSE_LARGE,"Text message size > "+_connection.getMaxTextMessageSize()+" chars");
_connection.close(WebSocketConnectionD7_9.CLOSE_LARGE,"Text message size > "+_connection.getMaxTextMessageSize()+" chars");
_utf8.reset();
_opcode=-1;
}
@ -592,7 +577,7 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
{
if (_aggregate.space()<_aggregate.length())
{
_connection.close(WebSocketConnectionD07.CLOSE_LARGE,"Message size > "+_connection.getMaxBinaryMessageSize());
_connection.close(WebSocketConnectionD7_9.CLOSE_LARGE,"Message size > "+_connection.getMaxBinaryMessageSize());
_aggregate.clear();
_opcode=-1;
}
@ -617,21 +602,21 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
}
break;
}
case WebSocketConnectionD07.OP_PING:
case WebSocketConnectionD7_9.OP_PING:
{
Log.debug("PING {}",this);
if (!_closedOut)
_connection.sendControl(WebSocketConnectionD07.OP_PONG,buffer.array(),buffer.getIndex(),buffer.length());
_connection.sendControl(WebSocketConnectionD7_9.OP_PONG,buffer.array(),buffer.getIndex(),buffer.length());
break;
}
case WebSocketConnectionD07.OP_PONG:
case WebSocketConnectionD7_9.OP_PONG:
{
Log.debug("PONG {}",this);
break;
}
case WebSocketConnectionD07.OP_CLOSE:
case WebSocketConnectionD7_9.OP_CLOSE:
{
int code=-1;
String message=null;
@ -646,7 +631,7 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
}
case WebSocketConnectionD07.OP_TEXT:
case WebSocketConnectionD7_9.OP_TEXT:
{
if(_onTextMessage!=null)
{
@ -661,12 +646,12 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
{
// If this is a text fragment, append to buffer
if (_utf8.append(buffer.array(),buffer.getIndex(),buffer.length(),_connection.getMaxTextMessageSize()))
_opcode=WebSocketConnectionD07.OP_TEXT;
_opcode=WebSocketConnectionD7_9.OP_TEXT;
else
{
_utf8.reset();
_opcode=-1;
_connection.close(WebSocketConnectionD07.CLOSE_LARGE,"Text message size > "+_connection.getMaxTextMessageSize()+" chars");
_connection.close(WebSocketConnectionD7_9.CLOSE_LARGE,"Text message size > "+_connection.getMaxTextMessageSize()+" chars");
}
}
}
@ -688,7 +673,7 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
{
if (buffer.length()>_connection.getMaxBinaryMessageSize())
{
_connection.close(WebSocketConnectionD07.CLOSE_LARGE,"Message size > "+_connection.getMaxBinaryMessageSize());
_connection.close(WebSocketConnectionD7_9.CLOSE_LARGE,"Message size > "+_connection.getMaxBinaryMessageSize());
if (_aggregate!=null)
_aggregate.clear();
_opcode=-1;
@ -726,7 +711,7 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
public String toString()
{
return WebSocketConnectionD07.this.toString()+"FH";
return WebSocketConnectionD7_9.this.toString()+"FH";
}
}
@ -776,4 +761,10 @@ public class WebSocketConnectionD07 extends AbstractConnection implements WebSoc
throw new RuntimeException(e);
}
}
/* ------------------------------------------------------------ */
public String toString()
{
return "WS/D"+_draft+"-"+_endp;
}
}

View File

@ -164,8 +164,10 @@ public class WebSocketFactory
connection = new WebSocketConnectionD06(websocket, endp, _buffers, http.getTimeStamp(), _maxIdleTime, protocol);
break;
case 7:
extensions= initExtensions(extensions_requested,8-WebSocketConnectionD07.OP_EXT_DATA, 16-WebSocketConnectionD07.OP_EXT_CTRL,3);
connection = new WebSocketConnectionD07(websocket, endp, _buffers, http.getTimeStamp(), _maxIdleTime, protocol,extensions);
case 8:
case 9:
extensions= initExtensions(extensions_requested,8-WebSocketConnectionD7_9.OP_EXT_DATA, 16-WebSocketConnectionD7_9.OP_EXT_CTRL,3);
connection = new WebSocketConnectionD7_9(websocket, endp, _buffers, http.getTimeStamp(), _maxIdleTime, protocol,extensions,draft);
break;
default:
Log.warn("Unsupported Websocket version: "+draft);
@ -256,14 +258,8 @@ public class WebSocketFactory
if (extension.init(parameters))
{
if (extension.getDataOpcodes()<=maxDataOpcodes && extension.getControlOpcodes()<=maxControlOpcodes && extension.getReservedBits()<=maxReservedBits)
{
Log.debug("add {} {}",extName,parameters);
extensions.add(extension);
maxDataOpcodes-=extension.getDataOpcodes();
maxControlOpcodes-=extension.getControlOpcodes();
maxReservedBits-=extension.getReservedBits();
}
Log.debug("add {} {}",extName,parameters);
extensions.add(extension);
}
}
Log.debug("extensions={}",extensions);

View File

@ -30,7 +30,7 @@ import org.eclipse.jetty.util.TypeUtil;
* threads will call the addMessage methods while other
* threads are flushing the generator.
*/
public class WebSocketGeneratorD07 implements WebSocketGenerator
public class WebSocketGeneratorD7_9 implements WebSocketGenerator
{
final private WebSocketBuffers _buffers;
final private EndPoint _endp;
@ -95,14 +95,14 @@ public class WebSocketGeneratorD07 implements WebSocketGenerator
}
public WebSocketGeneratorD07(WebSocketBuffers buffers, EndPoint endp)
public WebSocketGeneratorD7_9(WebSocketBuffers buffers, EndPoint endp)
{
_buffers=buffers;
_endp=endp;
_maskGen=null;
}
public WebSocketGeneratorD07(WebSocketBuffers buffers, EndPoint endp, MaskGen maskGen)
public WebSocketGeneratorD7_9(WebSocketBuffers buffers, EndPoint endp, MaskGen maskGen)
{
_buffers=buffers;
_endp=endp;
@ -118,14 +118,14 @@ public class WebSocketGeneratorD07 implements WebSocketGenerator
if (_buffer==null)
_buffer=mask?_buffers.getBuffer():_buffers.getDirectBuffer();
boolean last=WebSocketConnectionD07.isLastFrame(flags);
boolean last=WebSocketConnectionD7_9.isLastFrame(flags);
byte orig=opcode;
int space=mask?14:10;
do
{
opcode = _opsent?WebSocketConnectionD07.OP_CONTINUATION:opcode;
opcode = _opsent?WebSocketConnectionD7_9.OP_CONTINUATION:opcode;
opcode=(byte)(((0xf&flags)<<4)+(0xf&opcode));
_opsent=true;

View File

@ -29,7 +29,7 @@ import org.eclipse.jetty.util.log.Log;
* Parser the WebSocket protocol.
*
*/
public class WebSocketParserD07 implements WebSocketParser
public class WebSocketParserD7_9 implements WebSocketParser
{
public enum State {
@ -72,7 +72,7 @@ public class WebSocketParserD07 implements WebSocketParser
* @param endp
* @param handler
*/
public WebSocketParserD07(WebSocketBuffers buffers, EndPoint endp, FrameHandler handler, boolean shouldBeMasked)
public WebSocketParserD7_9(WebSocketBuffers buffers, EndPoint endp, FrameHandler handler, boolean shouldBeMasked)
{
_buffers=buffers;
_endp=endp;
@ -160,11 +160,11 @@ public class WebSocketParserD07 implements WebSocketParser
_opcode=(byte)(b&0xf);
_flags=(byte)(0xf&(b>>4));
if (WebSocketConnectionD07.isControlFrame(_opcode)&&!WebSocketConnectionD07.isLastFrame(_flags))
if (WebSocketConnectionD7_9.isControlFrame(_opcode)&&!WebSocketConnectionD7_9.isLastFrame(_flags))
{
events++;
Log.warn("Fragmented Control from "+_endp);
_handler.close(WebSocketConnectionD07.CLOSE_PROTOCOL,"Fragmented control");
_handler.close(WebSocketConnectionD7_9.CLOSE_PROTOCOL,"Fragmented control");
_skip=true;
}
@ -205,7 +205,7 @@ public class WebSocketParserD07 implements WebSocketParser
if (_length>_buffer.capacity())
{
events++;
_handler.close(WebSocketConnectionD07.CLOSE_LARGE,"frame size "+_length+">"+_buffer.capacity());
_handler.close(WebSocketConnectionD7_9.CLOSE_LARGE,"frame size "+_length+">"+_buffer.capacity());
_skip=true;
}
@ -224,7 +224,7 @@ public class WebSocketParserD07 implements WebSocketParser
if (_length>=_buffer.capacity())
{
events++;
_handler.close(WebSocketConnectionD07.CLOSE_LARGE,"frame size "+_length+">"+_buffer.capacity());
_handler.close(WebSocketConnectionD7_9.CLOSE_LARGE,"frame size "+_length+">"+_buffer.capacity());
_skip=true;
}
@ -267,7 +267,7 @@ public class WebSocketParserD07 implements WebSocketParser
_buffer.skip(_bytesNeeded);
_state=State.START;
events++;
_handler.close(WebSocketConnectionD07.CLOSE_PROTOCOL,"bad mask");
_handler.close(WebSocketConnectionD7_9.CLOSE_PROTOCOL,"bad mask");
}
else
{

View File

@ -11,7 +11,7 @@ import org.junit.Test;
/**
* @version $Revision$ $Date$
*/
public class WebSocketGeneratorD07Test
public class WebSocketGeneratorD7_9Test
{
private ByteArrayBuffer _out;
private WebSocketGenerator _generator;
@ -20,7 +20,7 @@ public class WebSocketGeneratorD07Test
byte[] _mask = new byte[4];
int _m;
public WebSocketGeneratorD07.MaskGen _maskGen = new WebSocketGeneratorD07.FixedMaskGen(
public WebSocketGeneratorD7_9.MaskGen _maskGen = new WebSocketGeneratorD7_9.FixedMaskGen(
new byte[]{(byte)0x00,(byte)0x00,(byte)0x0f,(byte)0xff});
@Before
@ -42,7 +42,7 @@ public class WebSocketGeneratorD07Test
@Test
public void testOneString() throws Exception
{
_generator = new WebSocketGeneratorD07(_buffers, _endPoint,null);
_generator = new WebSocketGeneratorD7_9(_buffers, _endPoint,null);
byte[] data = "Hell\uFF4F W\uFF4Frld".getBytes(StringUtil.__UTF8);
_generator.addFrame((byte)0x8,(byte)0x04,data,0,data.length);
@ -69,7 +69,7 @@ public class WebSocketGeneratorD07Test
@Test
public void testOneBuffer() throws Exception
{
_generator = new WebSocketGeneratorD07(_buffers, _endPoint,null);
_generator = new WebSocketGeneratorD7_9(_buffers, _endPoint,null);
String string = "Hell\uFF4F W\uFF4Frld";
byte[] bytes=string.getBytes(StringUtil.__UTF8);
@ -97,7 +97,7 @@ public class WebSocketGeneratorD07Test
@Test
public void testOneLongBuffer() throws Exception
{
_generator = new WebSocketGeneratorD07(_buffers, _endPoint,null);
_generator = new WebSocketGeneratorD7_9(_buffers, _endPoint,null);
byte[] b=new byte[150];
for (int i=0;i<b.length;i++)
@ -118,7 +118,7 @@ public class WebSocketGeneratorD07Test
@Test
public void testOneStringMasked() throws Exception
{
_generator = new WebSocketGeneratorD07(_buffers, _endPoint,_maskGen);
_generator = new WebSocketGeneratorD7_9(_buffers, _endPoint,_maskGen);
byte[] data = "Hell\uFF4F W\uFF4Frld".getBytes(StringUtil.__UTF8);
_generator.addFrame((byte)0x8,(byte)0x04,data,0,data.length);
@ -147,7 +147,7 @@ public class WebSocketGeneratorD07Test
@Test
public void testOneBufferMasked() throws Exception
{
_generator = new WebSocketGeneratorD07(_buffers, _endPoint,_maskGen);
_generator = new WebSocketGeneratorD7_9(_buffers, _endPoint,_maskGen);
String string = "Hell\uFF4F W\uFF4Frld";
byte[] bytes=string.getBytes(StringUtil.__UTF8);
@ -177,7 +177,7 @@ public class WebSocketGeneratorD07Test
@Test
public void testOneLongBufferMasked() throws Exception
{
_generator = new WebSocketGeneratorD07(_buffers, _endPoint,_maskGen);
_generator = new WebSocketGeneratorD7_9(_buffers, _endPoint,_maskGen);
byte[] b=new byte[150];
for (int i=0;i<b.length;i++)

View File

@ -33,7 +33,7 @@ import org.junit.Test;
/**
* @version $Revision$ $Date$
*/
public class WebSocketLoadD07Test
public class WebSocketLoadD7_9Test
{
private static Server _server;
private static Connector _connector;
@ -142,8 +142,8 @@ public class WebSocketLoadD07Test
private final int iterations;
private final CountDownLatch latch;
private final SocketEndPoint _endp;
private final WebSocketGeneratorD07 _generator;
private final WebSocketParserD07 _parser;
private final WebSocketGeneratorD7_9 _generator;
private final WebSocketParserD7_9 _parser;
private final WebSocketParser.FrameHandler _handler = new WebSocketParser.FrameHandler()
{
public void onFrame(byte flags, byte opcode, Buffer buffer)
@ -167,8 +167,8 @@ public class WebSocketLoadD07Test
this.iterations = iterations;
_endp=new SocketEndPoint(socket);
_generator = new WebSocketGeneratorD07(new WebSocketBuffers(32*1024),_endp,new WebSocketGeneratorD07.FixedMaskGen());
_parser = new WebSocketParserD07(new WebSocketBuffers(32*1024),_endp,_handler,false);
_generator = new WebSocketGeneratorD7_9(new WebSocketBuffers(32*1024),_endp,new WebSocketGeneratorD7_9.FixedMaskGen());
_parser = new WebSocketParserD7_9(new WebSocketBuffers(32*1024),_endp,_handler,false);
}
@ -202,7 +202,7 @@ public class WebSocketLoadD07Test
for (int i = 0; i < iterations; ++i)
{
byte[] data = message.getBytes(StringUtil.__UTF8);
_generator.addFrame((byte)0x8,WebSocketConnectionD07.OP_TEXT,data,0,data.length);
_generator.addFrame((byte)0x8,WebSocketConnectionD7_9.OP_TEXT,data,0,data.length);
_generator.flush();
//System.err.println("-> "+message);

View File

@ -34,7 +34,7 @@ import org.junit.Test;
/**
* @version $Revision$ $Date$
*/
public class WebSocketMessageD07Test
public class WebSocketMessageD7_9Test
{
private static Server _server;
private static Connector _connector;
@ -75,7 +75,7 @@ public class WebSocketMessageD07Test
@Test
public void testHash()
{
assertEquals("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=",WebSocketConnectionD07.hashKey("dGhlIHNhbXBsZSBub25jZQ=="));
assertEquals("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=",WebSocketConnectionD7_9.hashKey("dGhlIHNhbXBsZSBub25jZQ=="));
}
@Test
@ -116,7 +116,7 @@ public class WebSocketMessageD07Test
String data=message.toString();
_serverWebSocket.connection.sendMessage(data);
assertEquals(WebSocketConnectionD07.OP_TEXT,input.read());
assertEquals(WebSocketConnectionD7_9.OP_TEXT,input.read());
assertEquals(0x7e,input.read());
assertEquals(0x1f,input.read());
assertEquals(0xf6,input.read());
@ -272,7 +272,7 @@ public class WebSocketMessageD07Test
"Sec-WebSocket-Origin: http://example.com\r\n"+
"Sec-WebSocket-Protocol: echo\r\n" +
"Sec-WebSocket-Version: 7\r\n"+
"Sec-WebSocket-Extensions: x-deflate-frame\r\n"+
"Sec-WebSocket-Extensions: x-deflate-frame;minLength=64\r\n"+
"Sec-WebSocket-Extensions: fragment;minFragments=2\r\n"+
"\r\n").getBytes("ISO-8859-1"));
output.flush();
@ -322,8 +322,7 @@ public class WebSocketMessageD07Test
output.write(buf,0,l+3);
output.flush();
assertEquals(0x40+WebSocketConnectionD07.OP_TEXT,input.read());
assertEquals(0x40+WebSocketConnectionD7_9.OP_TEXT,input.read());
assertEquals(0x20+3,input.read());
assertEquals(0x7e,input.read());
assertEquals(0x02,input.read());
@ -491,7 +490,7 @@ public class WebSocketMessageD07Test
output.write(bytes[i]^0xff);
output.flush();
assertEquals(0x80|WebSocketConnectionD07.OP_CLOSE,input.read());
assertEquals(0x80|WebSocketConnectionD7_9.OP_CLOSE,input.read());
assertEquals(30,input.read());
int code=(0xff&input.read())*0x100+(0xff&input.read());
assertEquals(1004,code);
@ -542,7 +541,7 @@ public class WebSocketMessageD07Test
assertEquals(0x80|WebSocketConnectionD07.OP_CLOSE,input.read());
assertEquals(0x80|WebSocketConnectionD7_9.OP_CLOSE,input.read());
assertEquals(30,input.read());
int code=(0xff&input.read())*0x100+(0xff&input.read());
assertEquals(1004,code);
@ -578,7 +577,7 @@ public class WebSocketMessageD07Test
assertNotNull(_serverWebSocket.connection);
_serverWebSocket.getConnection().setMaxBinaryMessageSize(1024);
output.write(WebSocketConnectionD07.OP_BINARY);
output.write(WebSocketConnectionD7_9.OP_BINARY);
output.write(0x8a);
output.write(0xff);
output.write(0xff);
@ -599,7 +598,7 @@ public class WebSocketMessageD07Test
output.write(bytes[i]^0xff);
output.flush();
assertEquals(0x80+WebSocketConnectionD07.OP_BINARY,input.read());
assertEquals(0x80+WebSocketConnectionD7_9.OP_BINARY,input.read());
assertEquals(20,input.read());
lookFor("01234567890123456789",input);
}
@ -656,7 +655,7 @@ public class WebSocketMessageD07Test
output.flush();
assertEquals(0x80|WebSocketConnectionD07.OP_CLOSE,input.read());
assertEquals(0x80|WebSocketConnectionD7_9.OP_CLOSE,input.read());
assertEquals(19,input.read());
int code=(0xff&input.read())*0x100+(0xff&input.read());
assertEquals(1004,code);
@ -705,7 +704,7 @@ public class WebSocketMessageD07Test
output.write(bytes[i]^0xff);
output.flush();
assertEquals(0x80|WebSocketConnectionD07.OP_CLOSE,input.read());
assertEquals(0x80|WebSocketConnectionD7_9.OP_CLOSE,input.read());
assertEquals(19,input.read());
int code=(0xff&input.read())*0x100+(0xff&input.read());
assertEquals(1004,code);
@ -831,14 +830,14 @@ public class WebSocketMessageD07Test
final AtomicReference<String> received = new AtomicReference<String>();
ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
WebSocketGeneratorD07 gen = new WebSocketGeneratorD07(new WebSocketBuffers(8096),endp,null);
WebSocketGeneratorD7_9 gen = new WebSocketGeneratorD7_9(new WebSocketBuffers(8096),endp,null);
byte[] data = message.getBytes(StringUtil.__UTF8);
gen.addFrame((byte)0x8,(byte)0x4,data,0,data.length);
endp = new ByteArrayEndPoint(endp.getOut().asArray(),4096);
WebSocketParserD07 parser = new WebSocketParserD07(new WebSocketBuffers(8096),endp,new WebSocketParser.FrameHandler()
WebSocketParserD7_9 parser = new WebSocketParserD7_9(new WebSocketBuffers(8096),endp,new WebSocketParser.FrameHandler()
{
public void onFrame(byte flags, byte opcode, Buffer buffer)
{
@ -863,15 +862,15 @@ public class WebSocketMessageD07Test
final AtomicReference<String> received = new AtomicReference<String>();
ByteArrayEndPoint endp = new ByteArrayEndPoint(new byte[0],4096);
WebSocketGeneratorD07.MaskGen maskGen = new WebSocketGeneratorD07.RandomMaskGen();
WebSocketGeneratorD7_9.MaskGen maskGen = new WebSocketGeneratorD7_9.RandomMaskGen();
WebSocketGeneratorD07 gen = new WebSocketGeneratorD07(new WebSocketBuffers(8096),endp,maskGen);
WebSocketGeneratorD7_9 gen = new WebSocketGeneratorD7_9(new WebSocketBuffers(8096),endp,maskGen);
byte[] data = message.getBytes(StringUtil.__UTF8);
gen.addFrame((byte)0x8,(byte)0x1,data,0,data.length);
endp = new ByteArrayEndPoint(endp.getOut().asArray(),4096);
WebSocketParserD07 parser = new WebSocketParserD07(new WebSocketBuffers(8096),endp,new WebSocketParser.FrameHandler()
WebSocketParserD7_9 parser = new WebSocketParserD7_9(new WebSocketBuffers(8096),endp,new WebSocketParser.FrameHandler()
{
public void onFrame(byte flags, byte opcode, Buffer buffer)
{
@ -994,9 +993,9 @@ public class WebSocketMessageD07Test
{
switch(opcode)
{
case WebSocketConnectionD07.OP_CLOSE:
case WebSocketConnectionD07.OP_PING:
case WebSocketConnectionD07.OP_PONG:
case WebSocketConnectionD7_9.OP_CLOSE:
case WebSocketConnectionD7_9.OP_PING:
case WebSocketConnectionD7_9.OP_PONG:
break;
default:

View File

@ -20,7 +20,7 @@ import org.junit.Test;
/**
* @version $Revision$ $Date$
*/
public class WebSocketParserD07Test
public class WebSocketParserD7_9Test
{
private MaskedByteArrayBuffer _in;
private Handler _handler;
@ -87,7 +87,7 @@ public class WebSocketParserD07Test
ByteArrayEndPoint endPoint = new ByteArrayEndPoint();
endPoint.setNonBlocking(true);
_handler = new Handler();
_parser=new WebSocketParserD07(buffers, endPoint,_handler,true);
_parser=new WebSocketParserD7_9(buffers, endPoint,_handler,true);
_in = new MaskedByteArrayBuffer();
endPoint.setIn(_in);
@ -187,7 +187,7 @@ public class WebSocketParserD07Test
{
WebSocketBuffers buffers = new WebSocketBuffers(0x20000);
ByteArrayEndPoint endPoint = new ByteArrayEndPoint();
WebSocketParser parser=new WebSocketParserD07(buffers, endPoint,_handler,false);
WebSocketParser parser=new WebSocketParserD7_9(buffers, endPoint,_handler,false);
ByteArrayBuffer in = new ByteArrayBuffer(0x20000);
endPoint.setIn(in);
@ -261,7 +261,7 @@ public class WebSocketParserD07Test
assertTrue(progress>0);
assertEquals(WebSocketConnectionD07.CLOSE_LARGE,_handler._code);
assertEquals(WebSocketConnectionD7_9.CLOSE_LARGE,_handler._code);
for (int i=0;i<2048;i++)
_in.put((byte)'a');
progress =_parser.parseNext();