Merge fixes
This commit is contained in:
commit
a4a5108da4
|
@ -1,18 +1,21 @@
|
|||
package org.eclipse.jetty.websocket.frames;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.OpCode;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
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 final int pingId;
|
||||
private ByteBuffer payload;
|
||||
|
||||
public PingFrame(int pingId)
|
||||
public PingFrame(ByteBuffer payload)
|
||||
{
|
||||
super(OpCode.PING);
|
||||
this.pingId = pingId;
|
||||
setPayload(payload);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -21,14 +24,27 @@ public class PingFrame extends ControlFrame
|
|||
return OpCode.PING;
|
||||
}
|
||||
|
||||
public int getPingId()
|
||||
public void setPayload(ByteBuffer payload)
|
||||
{
|
||||
return pingId;
|
||||
if ( payload.array().length >= 126 )
|
||||
{
|
||||
this.payload = payload;
|
||||
setPayloadLength(payload.array().length);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new WebSocketException("too long, catch this better");
|
||||
}
|
||||
}
|
||||
|
||||
public ByteBuffer getPayload()
|
||||
{
|
||||
return payload;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s ping=%d", super.toString(), getPingId());
|
||||
return String.format("%s ping", super.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,16 +2,30 @@ package org.eclipse.jetty.websocket.generator;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.websocket.api.OpCode;
|
||||
import org.eclipse.jetty.websocket.frames.CloseFrame;
|
||||
import org.eclipse.jetty.websocket.frames.ControlFrame;
|
||||
|
||||
public class CloseFrameGenerator extends ControlFrameGenerator
|
||||
{
|
||||
|
||||
public CloseFrameGenerator(ByteBufferPool bufferPool)
|
||||
{
|
||||
super(bufferPool);
|
||||
}
|
||||
@Override
|
||||
public ByteBuffer generate(ControlFrame frame)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
CloseFrame close = (CloseFrame)frame;
|
||||
|
||||
ByteBuffer buffer = super.generate(frame);
|
||||
|
||||
buffer.putInt(OpCode.CLOSE.getCode());
|
||||
buffer.put(frame.getMask());
|
||||
buffer.putLong(frame.getPayloadLength());
|
||||
buffer.put(close.getReason().getBytes());
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,10 +2,39 @@ package org.eclipse.jetty.websocket.generator;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.websocket.frames.BaseFrame;
|
||||
import org.eclipse.jetty.websocket.frames.ControlFrame;
|
||||
|
||||
public abstract class ControlFrameGenerator
|
||||
{
|
||||
private final ByteBufferPool bufferPool;
|
||||
|
||||
public abstract ByteBuffer generate(ControlFrame frame);
|
||||
protected ControlFrameGenerator(ByteBufferPool bufferPool)
|
||||
{
|
||||
this.bufferPool = bufferPool;
|
||||
}
|
||||
|
||||
protected ByteBufferPool getByteBufferPool()
|
||||
{
|
||||
return bufferPool;
|
||||
}
|
||||
|
||||
public ByteBuffer generate(ControlFrame frame)
|
||||
{
|
||||
// how to calculate the size since control frames may hold
|
||||
// application data
|
||||
// grabing 125 now since that is _max_ possible
|
||||
ByteBuffer buffer = getByteBufferPool().acquire(125,true);
|
||||
|
||||
// all control frames are FIN as they can not be fragmented
|
||||
buffer.putInt(BaseFrame.FLAG_FIN);
|
||||
|
||||
// revisit this on extensions since they can negotiate this
|
||||
buffer.putInt(0);
|
||||
buffer.putInt(0);
|
||||
buffer.putInt(0);
|
||||
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,9 +39,9 @@ public class Generator {
|
|||
public Generator(ByteBufferPool bufferPool) //, CompressionFactory.Compressor compressor)
|
||||
{
|
||||
HeadersBlockGenerator headerBlockGenerator = new HeadersBlockGenerator();
|
||||
generators.put(OpCode.PING,new PingFrameGenerator());
|
||||
generators.put(OpCode.PONG,new PongFrameGenerator());
|
||||
generators.put(OpCode.CLOSE,new CloseFrameGenerator());
|
||||
generators.put(OpCode.PING,new PingFrameGenerator(bufferPool));
|
||||
generators.put(OpCode.PONG,new PongFrameGenerator(bufferPool));
|
||||
generators.put(OpCode.CLOSE,new CloseFrameGenerator(bufferPool));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -2,16 +2,31 @@ package org.eclipse.jetty.websocket.generator;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.websocket.api.OpCode;
|
||||
import org.eclipse.jetty.websocket.frames.ControlFrame;
|
||||
import org.eclipse.jetty.websocket.frames.PingFrame;
|
||||
|
||||
public class PingFrameGenerator extends ControlFrameGenerator
|
||||
{
|
||||
public PingFrameGenerator(ByteBufferPool bufferPool)
|
||||
{
|
||||
super(bufferPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer generate(ControlFrame frame)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
PingFrame ping = (PingFrame)frame;
|
||||
|
||||
ByteBuffer buffer = super.generate(frame);
|
||||
|
||||
buffer.putInt(OpCode.PING.getCode());
|
||||
buffer.put(frame.getMask());
|
||||
buffer.putLong(frame.getPayloadLength());
|
||||
|
||||
buffer.put(ping.getPayload().array());
|
||||
return buffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,10 +2,15 @@ package org.eclipse.jetty.websocket.generator;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.io.ByteBufferPool;
|
||||
import org.eclipse.jetty.websocket.frames.ControlFrame;
|
||||
|
||||
public class PongFrameGenerator extends ControlFrameGenerator
|
||||
{
|
||||
public PongFrameGenerator(ByteBufferPool bufferPool)
|
||||
{
|
||||
super(bufferPool);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuffer generate(ControlFrame frame)
|
||||
|
|
Loading…
Reference in New Issue