JETTY-1463 websocket D0 parser should return progress even if no fill done

This commit is contained in:
Greg Wilkins 2011-12-20 12:00:48 +11:00
parent 569e930185
commit b67961ada3
6 changed files with 22 additions and 21 deletions

View File

@ -150,11 +150,10 @@ public class WebSocketConnectionD00 extends AbstractConnection implements WebSoc
progress = flushed>0 || filled>0;
if (filled<0 || flushed<0)
{
_endp.close();
break;
}
_endp.flush();
if (_endp instanceof AsyncEndPoint && ((AsyncEndPoint)_endp).hasProgressed())
progress=true;
}
}
catch(IOException e)
@ -162,6 +161,7 @@ public class WebSocketConnectionD00 extends AbstractConnection implements WebSoc
LOG.debug(e);
try
{
if (_endp.isOpen())
_endp.close();
}
catch(IOException e2)

View File

@ -235,7 +235,6 @@ public class WebSocketConnectionRFC6455 extends AbstractConnection implements We
int filled=_parser.parseNext();
progress = flushed>0 || filled>0;
_endp.flush();
if (_endp instanceof AsyncEndPoint && ((AsyncEndPoint)_endp).hasProgressed())

View File

@ -33,6 +33,7 @@ import java.io.IOException;
import org.eclipse.jetty.io.Buffer;
import org.eclipse.jetty.io.Buffers;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -101,7 +102,7 @@ public class WebSocketParserD00 implements WebSocketParser
if (_buffer==null)
_buffer=_buffers.getBuffer();
int total_filled=0;
int progress=0;
// Loop until an datagram call back or can't fill anymore
while(true)
@ -123,14 +124,14 @@ public class WebSocketParserD00 implements WebSocketParser
{
int filled=_endp.isOpen()?_endp.fill(_buffer):-1;
if (filled<=0)
return total_filled;
total_filled+=filled;
return progress;
progress+=filled;
length=_buffer.length();
}
catch(IOException e)
{
LOG.debug(e);
return total_filled>0?total_filled:-1;
return progress>0?progress:-1;
}
}
@ -162,6 +163,7 @@ public class WebSocketParserD00 implements WebSocketParser
{
_state=STATE_START;
int l=_buffer.getIndex()-_buffer.markIndex()-1;
progress++;
_handler.onFrame((byte)0,_opcode,_buffer.sliceFromMark(l));
_buffer.setMarkIndex(-1);
if (_buffer.length()==0)
@ -169,7 +171,7 @@ public class WebSocketParserD00 implements WebSocketParser
_buffers.returnBuffer(_buffer);
_buffer=null;
}
return total_filled;
return progress;
}
continue;
@ -190,6 +192,7 @@ public class WebSocketParserD00 implements WebSocketParser
Buffer data=_buffer.sliceFromMark(_length);
_buffer.skip(_length);
_state=STATE_START;
progress++;
_handler.onFrame((byte)0, _opcode, data);
if (_buffer.length()==0)
@ -198,7 +201,7 @@ public class WebSocketParserD00 implements WebSocketParser
_buffer=null;
}
return total_filled;
return progress;
}
}
}

View File

@ -45,8 +45,8 @@ public class SafariWebsocketDraft0Test
public static void initLogging()
{
// Configure Logging
System.setProperty("org.eclipse.jetty.util.log.class",StdErrLog.class.getName());
System.setProperty("org.eclipse.jetty.LEVEL","DEBUG");
// System.setProperty("org.eclipse.jetty.util.log.class",StdErrLog.class.getName());
// System.setProperty("org.eclipse.jetty.LEVEL","DEBUG");
}
@Before
@ -74,11 +74,10 @@ public class SafariWebsocketDraft0Test
}
int port = conn.getLocalPort();
serverUri = new URI(String.format("ws://%s:%d/",host,port));
System.out.printf("Server URI: %s%n",serverUri);
// System.out.printf("Server URI: %s%n",serverUri);
}
@Test
@Ignore
public void testSendTextMessages() throws Exception
{
SafariD00 safari = new SafariD00(serverUri);
@ -106,7 +105,7 @@ public class SafariWebsocketDraft0Test
}
finally
{
System.out.println("Closing client socket");
// System.out.println("Closing client socket");
safari.disconnect();
}
}

View File

@ -41,7 +41,7 @@ public class CaptureSocket implements WebSocket, WebSocket.OnTextMessage
public void onMessage(String data)
{
System.out.printf("Received Message \"%s\" [size %d]%n", data, data.length());
// System.out.printf("Received Message \"%s\" [size %d]%n", data, data.length());
messages.add(data);
}

View File

@ -80,7 +80,7 @@ public class SafariD00
req.append("Sec-WebSocket-Key2: 3? C;7~0 8 \" 3 2105 6 `_ {\r\n");
req.append("\r\n");
System.out.printf("--- Request ---%n%s",req);
// System.out.printf("--- Request ---%n%s",req);
byte reqBytes[] = req.toString().getBytes("UTF-8");
byte hixieBytes[] = TypeUtil.fromHexString("e739617916c9daf3");
@ -101,7 +101,7 @@ public class SafariD00
while (!foundEnd)
{
line = br.readLine();
System.out.printf("RESP: %s%n",line);
// System.out.printf("RESP: %s%n",line);
if (line.length() == 0)
{
foundEnd = true;