JETTY-1463 websocket D0 parser should return progress even if no fill done
This commit is contained in:
parent
569e930185
commit
b67961ada3
|
@ -150,11 +150,10 @@ public class WebSocketConnectionD00 extends AbstractConnection implements WebSoc
|
||||||
|
|
||||||
progress = flushed>0 || filled>0;
|
progress = flushed>0 || filled>0;
|
||||||
|
|
||||||
if (filled<0 || flushed<0)
|
_endp.flush();
|
||||||
{
|
|
||||||
_endp.close();
|
if (_endp instanceof AsyncEndPoint && ((AsyncEndPoint)_endp).hasProgressed())
|
||||||
break;
|
progress=true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(IOException e)
|
catch(IOException e)
|
||||||
|
@ -162,7 +161,8 @@ public class WebSocketConnectionD00 extends AbstractConnection implements WebSoc
|
||||||
LOG.debug(e);
|
LOG.debug(e);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_endp.close();
|
if (_endp.isOpen())
|
||||||
|
_endp.close();
|
||||||
}
|
}
|
||||||
catch(IOException e2)
|
catch(IOException e2)
|
||||||
{
|
{
|
||||||
|
|
|
@ -235,7 +235,6 @@ public class WebSocketConnectionRFC6455 extends AbstractConnection implements We
|
||||||
int filled=_parser.parseNext();
|
int filled=_parser.parseNext();
|
||||||
|
|
||||||
progress = flushed>0 || filled>0;
|
progress = flushed>0 || filled>0;
|
||||||
|
|
||||||
_endp.flush();
|
_endp.flush();
|
||||||
|
|
||||||
if (_endp instanceof AsyncEndPoint && ((AsyncEndPoint)_endp).hasProgressed())
|
if (_endp instanceof AsyncEndPoint && ((AsyncEndPoint)_endp).hasProgressed())
|
||||||
|
|
|
@ -33,6 +33,7 @@ import java.io.IOException;
|
||||||
import org.eclipse.jetty.io.Buffer;
|
import org.eclipse.jetty.io.Buffer;
|
||||||
import org.eclipse.jetty.io.Buffers;
|
import org.eclipse.jetty.io.Buffers;
|
||||||
import org.eclipse.jetty.io.EndPoint;
|
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.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
|
|
||||||
|
@ -101,7 +102,7 @@ public class WebSocketParserD00 implements WebSocketParser
|
||||||
if (_buffer==null)
|
if (_buffer==null)
|
||||||
_buffer=_buffers.getBuffer();
|
_buffer=_buffers.getBuffer();
|
||||||
|
|
||||||
int total_filled=0;
|
int progress=0;
|
||||||
|
|
||||||
// Loop until an datagram call back or can't fill anymore
|
// Loop until an datagram call back or can't fill anymore
|
||||||
while(true)
|
while(true)
|
||||||
|
@ -123,14 +124,14 @@ public class WebSocketParserD00 implements WebSocketParser
|
||||||
{
|
{
|
||||||
int filled=_endp.isOpen()?_endp.fill(_buffer):-1;
|
int filled=_endp.isOpen()?_endp.fill(_buffer):-1;
|
||||||
if (filled<=0)
|
if (filled<=0)
|
||||||
return total_filled;
|
return progress;
|
||||||
total_filled+=filled;
|
progress+=filled;
|
||||||
length=_buffer.length();
|
length=_buffer.length();
|
||||||
}
|
}
|
||||||
catch(IOException e)
|
catch(IOException e)
|
||||||
{
|
{
|
||||||
LOG.debug(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;
|
_state=STATE_START;
|
||||||
int l=_buffer.getIndex()-_buffer.markIndex()-1;
|
int l=_buffer.getIndex()-_buffer.markIndex()-1;
|
||||||
|
progress++;
|
||||||
_handler.onFrame((byte)0,_opcode,_buffer.sliceFromMark(l));
|
_handler.onFrame((byte)0,_opcode,_buffer.sliceFromMark(l));
|
||||||
_buffer.setMarkIndex(-1);
|
_buffer.setMarkIndex(-1);
|
||||||
if (_buffer.length()==0)
|
if (_buffer.length()==0)
|
||||||
|
@ -169,7 +171,7 @@ public class WebSocketParserD00 implements WebSocketParser
|
||||||
_buffers.returnBuffer(_buffer);
|
_buffers.returnBuffer(_buffer);
|
||||||
_buffer=null;
|
_buffer=null;
|
||||||
}
|
}
|
||||||
return total_filled;
|
return progress;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -190,6 +192,7 @@ public class WebSocketParserD00 implements WebSocketParser
|
||||||
Buffer data=_buffer.sliceFromMark(_length);
|
Buffer data=_buffer.sliceFromMark(_length);
|
||||||
_buffer.skip(_length);
|
_buffer.skip(_length);
|
||||||
_state=STATE_START;
|
_state=STATE_START;
|
||||||
|
progress++;
|
||||||
_handler.onFrame((byte)0, _opcode, data);
|
_handler.onFrame((byte)0, _opcode, data);
|
||||||
|
|
||||||
if (_buffer.length()==0)
|
if (_buffer.length()==0)
|
||||||
|
@ -198,7 +201,7 @@ public class WebSocketParserD00 implements WebSocketParser
|
||||||
_buffer=null;
|
_buffer=null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return total_filled;
|
return progress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,8 +45,8 @@ public class SafariWebsocketDraft0Test
|
||||||
public static void initLogging()
|
public static void initLogging()
|
||||||
{
|
{
|
||||||
// Configure Logging
|
// Configure Logging
|
||||||
System.setProperty("org.eclipse.jetty.util.log.class",StdErrLog.class.getName());
|
// System.setProperty("org.eclipse.jetty.util.log.class",StdErrLog.class.getName());
|
||||||
System.setProperty("org.eclipse.jetty.LEVEL","DEBUG");
|
// System.setProperty("org.eclipse.jetty.LEVEL","DEBUG");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -74,11 +74,10 @@ public class SafariWebsocketDraft0Test
|
||||||
}
|
}
|
||||||
int port = conn.getLocalPort();
|
int port = conn.getLocalPort();
|
||||||
serverUri = new URI(String.format("ws://%s:%d/",host,port));
|
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
|
@Test
|
||||||
@Ignore
|
|
||||||
public void testSendTextMessages() throws Exception
|
public void testSendTextMessages() throws Exception
|
||||||
{
|
{
|
||||||
SafariD00 safari = new SafariD00(serverUri);
|
SafariD00 safari = new SafariD00(serverUri);
|
||||||
|
@ -106,7 +105,7 @@ public class SafariWebsocketDraft0Test
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
System.out.println("Closing client socket");
|
// System.out.println("Closing client socket");
|
||||||
safari.disconnect();
|
safari.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ public class CaptureSocket implements WebSocket, WebSocket.OnTextMessage
|
||||||
|
|
||||||
public void onMessage(String data)
|
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);
|
messages.add(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ public class SafariD00
|
||||||
req.append("Sec-WebSocket-Key2: 3? C;7~0 8 \" 3 2105 6 `_ {\r\n");
|
req.append("Sec-WebSocket-Key2: 3? C;7~0 8 \" 3 2105 6 `_ {\r\n");
|
||||||
req.append("\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 reqBytes[] = req.toString().getBytes("UTF-8");
|
||||||
byte hixieBytes[] = TypeUtil.fromHexString("e739617916c9daf3");
|
byte hixieBytes[] = TypeUtil.fromHexString("e739617916c9daf3");
|
||||||
|
@ -101,7 +101,7 @@ public class SafariD00
|
||||||
while (!foundEnd)
|
while (!foundEnd)
|
||||||
{
|
{
|
||||||
line = br.readLine();
|
line = br.readLine();
|
||||||
System.out.printf("RESP: %s%n",line);
|
// System.out.printf("RESP: %s%n",line);
|
||||||
if (line.length() == 0)
|
if (line.length() == 0)
|
||||||
{
|
{
|
||||||
foundEnd = true;
|
foundEnd = true;
|
||||||
|
|
Loading…
Reference in New Issue