use of com.webpieces.http2.api.dto.lowlevel.WindowUpdateFrame in project webpieces by deanhiller.
the class WindowUpdateMarshaller method unmarshal.
@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper payload) {
FrameHeaderData frameHeaderData = state.getFrameHeaderData();
int streamId = frameHeaderData.getStreamId();
if (state.getFrameHeaderData().getPayloadLength() != 4)
throw new ConnectionException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "window update size not 4 and instead is=" + state.getFrameHeaderData().getPayloadLength());
WindowUpdateFrame frame = new WindowUpdateFrame();
super.unmarshalFrame(state, frame);
ByteBuffer payloadByteBuffer = bufferPool.createWithDataWrapper(payload);
frame.setWindowSizeIncrement(payloadByteBuffer.getInt());
bufferPool.releaseBuffer(payloadByteBuffer);
if (frame.getWindowSizeIncrement() == 0)
throw new ConnectionException(CancelReasonCode.WINDOW_SIZE_INVALID, streamId, "Window size increment cannot be 0 per http/2 spec and was");
return frame;
}
use of com.webpieces.http2.api.dto.lowlevel.WindowUpdateFrame in project webpieces by deanhiller.
the class WindowUpdateMarshaller method marshal.
@Override
public DataWrapper marshal(Http2Frame frame) {
WindowUpdateFrame castFrame = (WindowUpdateFrame) frame;
ByteBuffer payload = bufferPool.nextBuffer(4).putInt(castFrame.getWindowSizeIncrement());
payload.flip();
DataWrapper dataPayload = DATA_GEN.wrapByteBuffer(payload);
return super.marshalFrame(frame, (byte) 0, dataPayload);
}
use of com.webpieces.http2.api.dto.lowlevel.WindowUpdateFrame in project webpieces by deanhiller.
the class Level6RemoteFlowControl method updateStreamWindowSize.
public XFuture<Void> updateStreamWindowSize(Stream stream, WindowUpdateFrame msg) {
if (msg.getWindowSizeIncrement() == 0) {
throw new ConnectionException(CancelReasonCode.WINDOW_SIZE_INVALID, logId, msg.getStreamId(), "Received windowUpdate size increment=0");
}
DataTry dataTry = null;
DataTry temp = dataQueue.peek();
synchronized (remoteLock) {
long remoteWindowSize = stream.incrementRemoteWindow(msg.getWindowSizeIncrement());
if (temp != null && remoteWindowSize > temp.getDataFrame().getTransmitFrameLength())
dataTry = dataQueue.poll();
log.info("updated stream " + stream.getStreamId() + " window to=" + stream.getRemoteWindowSize() + " increment=" + msg.getWindowSizeIncrement() + " dataTry to submit=" + dataTry);
}
if (dataTry != null) {
dataTry.setWasQueuedBefore(true);
trySendPayload(dataTry);
}
// someday, remove synchronized above and then complete future when it is complete instead maybe
return XFuture.completedFuture(null);
}
use of com.webpieces.http2.api.dto.lowlevel.WindowUpdateFrame in project webpieces by deanhiller.
the class Level6RemoteFlowControl method updateConnectionWindowSize.
public XFuture<Void> updateConnectionWindowSize(WindowUpdateFrame msg) {
int increment = msg.getWindowSizeIncrement();
if (increment == 0) {
throw new ConnectionException(CancelReasonCode.WINDOW_SIZE_INVALID, logId, msg.getStreamId(), "Received windowUpdate size increment=0");
}
DataTry dataTry = null;
DataTry temp = dataQueue.peek();
synchronized (remoteLock) {
// TODO: Use AsyncLock instead so we do not block threads!!!
remoteWindowSize += increment;
if (remoteWindowSize > Integer.MAX_VALUE)
throw new ConnectionException(CancelReasonCode.FLOW_CONTROL_ERROR, logId, 0, "(remote end bad)global remoteWindowSize too large=" + remoteWindowSize + " from windows increment=" + increment);
if (temp != null && remoteWindowSize > temp.getDataFrame().getTransmitFrameLength())
dataTry = dataQueue.poll();
log.info("updated window to=" + remoteWindowSize + " increment=" + msg.getWindowSizeIncrement() + " dataTry to submit=" + dataTry);
}
if (dataTry != null) {
dataTry.setWasQueuedBefore(true);
trySendPayload(dataTry);
}
return XFuture.completedFuture(null);
}
use of com.webpieces.http2.api.dto.lowlevel.WindowUpdateFrame in project webpieces by deanhiller.
the class Level6LocalFlowControl method updateFlowControl.
private Void updateFlowControl(long frameLength, Stream stream) {
if (frameLength == 0)
// nothing to do if it is a 0 length frame.
return null;
// TODO: we could optimize this to send very large window updates and send less window updates instead of
// what we do currently sending many increase window by 13 byte updates and such.
connectionLocalWindowSize += frameLength;
stream.incrementLocalWindow(frameLength);
totalRecovered += frameLength;
int len = (int) frameLength;
WindowUpdateFrame w1 = new WindowUpdateFrame();
w1.setStreamId(0);
w1.setWindowSizeIncrement(len);
marshalLayer.sendFrameToSocket(w1);
if (!stream.isClosed()) {
// IF the stream is not closed, update flow control
WindowUpdateFrame w2 = new WindowUpdateFrame();
w2.setStreamId(stream.getStreamId());
w2.setWindowSizeIncrement(len);
log.info("sending BOTH WUF increments. framelen=" + frameLength + " recovered=" + totalRecovered);
marshalLayer.sendFrameToSocket(w2);
} else {
log.info("sending WUF increments. framelen=" + frameLength + " recovered=" + totalRecovered);
}
return null;
}
Aggregations