move payload into control frame, not doing close frame's reason and status code since we can

't create bytebuffers in the frames atm
This commit is contained in:
Jesse McConnell 2012-06-19 13:12:53 -05:00
parent 993c3788b9
commit 289fb7c395
3 changed files with 32 additions and 46 deletions

View File

@ -1,9 +1,14 @@
package org.eclipse.jetty.websocket.frames;
import java.nio.ByteBuffer;
import org.eclipse.jetty.websocket.api.OpCode;
import org.eclipse.jetty.websocket.api.WebSocketException;
public abstract class ControlFrame extends BaseFrame
{
private ByteBuffer payload = null; // TODO decide if payload needs to go all the way down to baseframe
public ControlFrame()
{
super();
@ -18,4 +23,27 @@ public abstract class ControlFrame extends BaseFrame
{
super(opcode);
}
public ByteBuffer getPayload()
{
return payload;
}
public void setPayload(ByteBuffer payload)
{
if ( payload.array().length >= 126 )
{
this.payload = payload;
setPayloadLength(payload.array().length);
}
else
{
throw new WebSocketException("too long, catch this better");
}
}
public boolean hasPayload()
{
return payload != null;
}
}

View File

@ -3,15 +3,12 @@ package org.eclipse.jetty.websocket.frames;
import java.nio.ByteBuffer;
import org.eclipse.jetty.websocket.api.OpCode;
import org.eclipse.jetty.websocket.api.WebSocketException;
/**
* Representation of a <a href="https://tools.ietf.org/html/rfc6455#section-5.5.2">Ping Frame (0x09)</a>.
*/
public class PingFrame extends ControlFrame
{
private ByteBuffer payload;
/**
* Default constructor
*/
@ -37,27 +34,9 @@ public class PingFrame extends ControlFrame
return OpCode.PING;
}
public ByteBuffer getPayload()
{
return payload;
}
public void setPayload(ByteBuffer payload)
{
if ( payload.array().length >= 126 )
{
this.payload = payload;
setPayloadLength(payload.array().length);
}
else
{
throw new WebSocketException("too long, catch this better");
}
}
@Override
public String toString()
{
return String.format("%s ping", super.toString());
return String.format("%s ping, payload=%s", super.toString(), hasPayload());
}
}

View File

@ -3,17 +3,14 @@ package org.eclipse.jetty.websocket.frames;
import java.nio.ByteBuffer;
import org.eclipse.jetty.websocket.api.OpCode;
import org.eclipse.jetty.websocket.api.WebSocketException;
/**
* Representation of a <a href="https://tools.ietf.org/html/rfc6455#section-5.5.3">Pong Frame (0x0A)</a>.
*/
public class PongFrame extends ControlFrame
{
private ByteBuffer payload;
/**
* Default contructor
* Default constructor
*/
public PongFrame()
{
@ -38,7 +35,7 @@ public class PongFrame extends ControlFrame
public PongFrame(PingFrame ping)
{
this();
// TODO: set appropriate pong from ping frame payload + masking
setPayload(ping.getPayload());
}
@Override
@ -47,27 +44,9 @@ public class PongFrame extends ControlFrame
return OpCode.PONG;
}
public ByteBuffer getPayload()
{
return payload;
}
public void setPayload(ByteBuffer payload)
{
if (payload.array().length >= 126)
{
this.payload = payload;
setPayloadLength(payload.array().length);
}
else
{
throw new WebSocketException("too long, catch this better");
}
}
@Override
public String toString()
{
return String.format("%s pong",super.toString());
return String.format("%s pong, payload=%s",super.toString(), hasPayload());
}
}