JETTY-1270 websocket close protection

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2266 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-09-09 04:36:05 +00:00
parent 51d5da4bbc
commit f919f78f1f
2 changed files with 43 additions and 38 deletions

View File

@ -39,6 +39,7 @@ jetty-7.2-SNAPSHOT
+ JETTY-1261 errant listener usage in StandardDescriptorProcessor
+ JETTY-1263 JDBCSessionIdManager table creation fails on Oracle
+ JETTY-1269 Improve log multithreadedness
+ JETTY-1270 Websocket closed endp protection
+ JETTY-1271 handled unavailable exception
+ Fix jetty-plus.xml for new configuration names
+ Added ignore to Logger interface

View File

@ -1,5 +1,6 @@
package org.eclipse.jetty.websocket;
import java.io.IOError;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@ -24,7 +25,7 @@ public class WebSocketConnection implements Connection, WebSocket.Outbound
final WebSocket _websocket;
String _key1;
String _key2;
ByteArrayBuffer _hixie;
ByteArrayBuffer _hixieBytes;
public WebSocketConnection(WebSocket websocket, EndPoint endpoint,int draft)
throws IOException
@ -141,63 +142,58 @@ public class WebSocketConnection implements Connection, WebSocket.Outbound
{
_key1=key1;
_key2=key2;
_hixie=new IndirectNIOBuffer(16);
_hixieBytes=new IndirectNIOBuffer(16);
}
public Connection handle() throws IOException
{
boolean progress=true;
try
{
// handle stupid hixie random bytes
if (_hixie!=null)
if (_hixieBytes!=null)
{
while(progress)
// take any available bytes from the parser buffer, which may have already been read
Buffer buffer=_parser.getBuffer();
if (buffer!=null && buffer.length()>0)
{
int l=buffer.length();
if (l>(8-_hixieBytes.length()))
l=8-_hixieBytes.length();
_hixieBytes.put(buffer.peek(buffer.getIndex(),l));
buffer.skip(l);
}
// while we are not blocked
while(_endp.isOpen())
{
// take bytes from the parser buffer.
Buffer buffer=_parser.getBuffer();
if (buffer!=null && buffer.length()>0)
{
int l=buffer.length();
if (l>8)
l=8;
_hixie.put(buffer.peek(buffer.getIndex(),l));
buffer.skip(l);
progress=true;
}
// do we have enough?
if (_hixie.length()<8)
{
// no, then let's fill
int filled=_endp.fill(_hixie);
progress |= filled>0;
if (filled<0)
{
_endp.close();
break;
}
}
// do we now have enough
if (_hixie.length()==8)
if (_hixieBytes.length()==8)
{
// we have the silly random bytes
// so let's work out the stupid 16 byte reply.
doTheHixieHixieShake();
_endp.flush(_hixie);
_hixie=null;
_endp.flush(_hixieBytes);
_hixieBytes=null;
_endp.flush();
break;
}
// no, then let's fill
int filled=_endp.fill(_hixieBytes);
if (filled<0)
{
_endp.close();
break;
}
}
return this;
}
// handle the framing protocol
boolean progress=true;
while (progress)
{
int flushed=_generator.flush();
@ -214,6 +210,14 @@ public class WebSocketConnection implements Connection, WebSocket.Outbound
}
catch(IOException e)
{
try
{
_endp.close();
}
catch(IOException e2)
{
Log.ignore(e2);
}
throw e;
}
finally
@ -235,9 +239,9 @@ public class WebSocketConnection implements Connection, WebSocket.Outbound
byte[] result=WebSocketConnection.doTheHixieHixieShake(
WebSocketConnection.hixieCrypt(_key1),
WebSocketConnection.hixieCrypt(_key2),
_hixie.asArray());
_hixie.clear();
_hixie.put(result);
_hixieBytes.asArray());
_hixieBytes.clear();
_hixieBytes.put(result);
}
public boolean isOpen()