353073 better close messages
This commit is contained in:
parent
1f1bf28cd6
commit
2cb0cd377e
|
@ -119,6 +119,12 @@ public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPo
|
|||
_manager.endPointUpgraded(this,old);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public long getIdleTimestamp()
|
||||
{
|
||||
return _idleTimestamp;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Called by selectSet to schedule handling
|
||||
*
|
||||
|
|
|
@ -228,7 +228,7 @@ public class TestClient implements WebSocket.OnFrame
|
|||
__start=System.currentTimeMillis();
|
||||
for (int i=0;i<clients;i++)
|
||||
{
|
||||
client[i]=new TestClient(host,port,protocol==null?null:protocol,10000);
|
||||
client[i]=new TestClient(host,port,protocol==null?null:protocol,60000);
|
||||
client[i].open();
|
||||
}
|
||||
|
||||
|
|
|
@ -90,7 +90,8 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
|
|||
private final String _protocol;
|
||||
private final int _draft;
|
||||
private final ClassLoader _context;
|
||||
private int _close;
|
||||
private volatile int _closeCode;
|
||||
private volatile String _closeMessage;
|
||||
private volatile boolean _closedIn;
|
||||
private volatile boolean _closedOut;
|
||||
private int _maxTextMessageSize;
|
||||
|
@ -275,7 +276,8 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
|
|||
@Override
|
||||
public void idleExpired()
|
||||
{
|
||||
closeOut(WebSocketConnectionD10.CLOSE_NORMAL,"Idle");
|
||||
long idle = System.currentTimeMillis()-((SelectChannelEndPoint)_endp).getIdleTimestamp();
|
||||
closeOut(WebSocketConnectionD10.CLOSE_NORMAL,"Idle for "+idle+"ms");
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -290,9 +292,9 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
|
|||
final boolean closed;
|
||||
synchronized (this)
|
||||
{
|
||||
closed=_close==0;
|
||||
closed=_closeCode==0;
|
||||
if (closed)
|
||||
_close=WebSocketConnectionD10.CLOSE_NOCLOSE;
|
||||
_closeCode=WebSocketConnectionD10.CLOSE_NOCLOSE;
|
||||
}
|
||||
if (closed)
|
||||
_webSocket.onClose(WebSocketConnectionD10.CLOSE_NOCLOSE,"closed");
|
||||
|
@ -309,9 +311,12 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
|
|||
{
|
||||
closedOut=_closedOut;
|
||||
_closedIn=true;
|
||||
closed=_close==0;
|
||||
closed=_closeCode==0;
|
||||
if (closed)
|
||||
_close=code;
|
||||
{
|
||||
_closeCode=code;
|
||||
_closeMessage=message;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -346,9 +351,12 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
|
|||
{
|
||||
close=_closedIn || _closedOut;
|
||||
_closedOut=true;
|
||||
closed=_close==0;
|
||||
closed=_closeCode==0;
|
||||
if (closed)
|
||||
_close=code;
|
||||
{
|
||||
_closeCode=code;
|
||||
_closeMessage=message;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
|
@ -409,7 +417,7 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
|
|||
public void sendMessage(String content) throws IOException
|
||||
{
|
||||
if (_closedOut)
|
||||
throw new IOException("closing");
|
||||
throw new IOException("closedOut "+_closeCode+":"+_closeMessage);
|
||||
byte[] data = content.getBytes(StringUtil.__UTF8);
|
||||
_outbound.addFrame((byte)FLAG_FIN,WebSocketConnectionD10.OP_TEXT,data,0,data.length);
|
||||
checkWriteable();
|
||||
|
@ -420,7 +428,7 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
|
|||
public void sendMessage(byte[] content, int offset, int length) throws IOException
|
||||
{
|
||||
if (_closedOut)
|
||||
throw new IOException("closing");
|
||||
throw new IOException("closedOut "+_closeCode+":"+_closeMessage);
|
||||
_outbound.addFrame((byte)FLAG_FIN,WebSocketConnectionD10.OP_BINARY,content,offset,length);
|
||||
checkWriteable();
|
||||
_idle.access(_endp);
|
||||
|
@ -430,7 +438,7 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
|
|||
public void sendFrame(byte flags,byte opcode, byte[] content, int offset, int length) throws IOException
|
||||
{
|
||||
if (_closedOut)
|
||||
throw new IOException("closing");
|
||||
throw new IOException("closedOut "+_closeCode+":"+_closeMessage);
|
||||
_outbound.addFrame(flags,opcode,content,offset,length);
|
||||
checkWriteable();
|
||||
_idle.access(_endp);
|
||||
|
@ -440,7 +448,7 @@ public class WebSocketConnectionD10 extends AbstractConnection implements WebSoc
|
|||
public void sendControl(byte ctrl, byte[] data, int offset, int length) throws IOException
|
||||
{
|
||||
if (_closedOut)
|
||||
throw new IOException("closing");
|
||||
throw new IOException("closedOut "+_closeCode+":"+_closeMessage);
|
||||
_outbound.addFrame((byte)FLAG_FIN,ctrl,data,offset,length);
|
||||
checkWriteable();
|
||||
_idle.access(_endp);
|
||||
|
|
|
@ -745,7 +745,7 @@ public class WebSocketMessageD10Test
|
|||
lookFor("sent on connect",input);
|
||||
|
||||
assertEquals((byte)0x88,(byte)input.read());
|
||||
assertEquals(0x06,input.read());
|
||||
assertEquals(17,input.read());
|
||||
assertEquals(1000/0x100,input.read());
|
||||
assertEquals(1000%0x100,input.read());
|
||||
lookFor("Idle",input);
|
||||
|
|
Loading…
Reference in New Issue