Using NO_CODE instead of -1 for close frame with no status code declared

This commit is contained in:
Joakim Erdfelt 2012-10-22 11:37:15 -07:00
parent b6bf6899a9
commit 4f7c66ae81
1 changed files with 15 additions and 13 deletions

View File

@ -38,12 +38,12 @@ public class CloseInfo
public CloseInfo() public CloseInfo()
{ {
this(-1,null); this(StatusCode.NO_CODE,null);
} }
public CloseInfo(ByteBuffer payload, boolean validate) public CloseInfo(ByteBuffer payload, boolean validate)
{ {
this.statusCode = -1; this.statusCode = StatusCode.NO_CODE;
this.reason = null; this.reason = null;
if ((payload == null) || (payload.remaining() == 0)) if ((payload == null) || (payload.remaining() == 0))
@ -130,8 +130,12 @@ public class CloseInfo
public ByteBuffer asByteBuffer() public ByteBuffer asByteBuffer()
{ {
if (statusCode != (-1)) if ((statusCode == StatusCode.NO_CLOSE) || (statusCode == StatusCode.NO_CODE) || (statusCode == (-1)))
{ {
// codes that are not allowed to be used in endpoint.
return null;
}
ByteBuffer buf = ByteBuffer.allocate(WebSocketFrame.MAX_CONTROL_PAYLOAD); ByteBuffer buf = ByteBuffer.allocate(WebSocketFrame.MAX_CONTROL_PAYLOAD);
buf.putChar((char)statusCode); buf.putChar((char)statusCode);
if (StringUtil.isNotBlank(reason)) if (StringUtil.isNotBlank(reason))
@ -142,8 +146,6 @@ public class CloseInfo
BufferUtil.flipToFlush(buf,0); BufferUtil.flipToFlush(buf,0);
return buf; return buf;
} }
return null;
}
public WebSocketFrame asFrame() public WebSocketFrame asFrame()
{ {