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-1261 errant listener usage in StandardDescriptorProcessor
+ JETTY-1263 JDBCSessionIdManager table creation fails on Oracle + JETTY-1263 JDBCSessionIdManager table creation fails on Oracle
+ JETTY-1269 Improve log multithreadedness + JETTY-1269 Improve log multithreadedness
+ JETTY-1270 Websocket closed endp protection
+ JETTY-1271 handled unavailable exception + JETTY-1271 handled unavailable exception
+ Fix jetty-plus.xml for new configuration names + Fix jetty-plus.xml for new configuration names
+ Added ignore to Logger interface + Added ignore to Logger interface

View File

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