/** * Utility method that reads a full text or binary message, including all fragmented parts. Once the full message is * read then the {@link #onFullTextMessage(WebSocketChannel, BufferedTextMessage)} or * {@link #onFullBinaryMessage(WebSocketChannel, BufferedBinaryMessage)} method will be invoked. * * @param messageChannel The message channel */ protected final void bufferFullMessage(StreamSourceFrameChannel messageChannel) { if (messageChannel.getType() == WebSocketFrameType.TEXT) { readBufferedText(messageChannel, new BufferedTextMessage(getMaxTextBufferSize(), true)); } else if (messageChannel.getType() == WebSocketFrameType.BINARY) { readBufferedBinary(messageChannel, false, new BufferedBinaryMessage(getMaxBinaryBufferSize(), true)); } else if (messageChannel.getType() == WebSocketFrameType.PONG) { readBufferedBinary(messageChannel, true, new BufferedBinaryMessage(getMaxPongBufferSize(), true)); } else if (messageChannel.getType() == WebSocketFrameType.PING) { readBufferedBinary(messageChannel, true, new BufferedBinaryMessage(getMaxPingBufferSize(), true)); } else if (messageChannel.getType() == WebSocketFrameType.CLOSE) { readBufferedBinary(messageChannel, true, new BufferedBinaryMessage(getMaxCloseBufferSize(), true)); } }
public void readBlocking(StreamSourceFrameChannel channel) throws IOException { if (current == null) { current = channel.getWebSocketChannel().getBufferPool().allocate(); } for (; ; ) { int res = channel.read(current.getBuffer()); if (res == -1) { complete = true; return; } else if (res == 0) { channel.awaitReadable(); } checkMaxSize(channel, res); if (bufferFullMessage) { dealWithFullBuffer(channel); } else if (!current.getBuffer().hasRemaining()) { return; } } }
private void readBufferedBinary(final StreamSourceFrameChannel messageChannel, final boolean controlFrame, final BufferedBinaryMessage buffer) { buffer.read(messageChannel, new WebSocketCallback<BufferedBinaryMessage>() { @Override public void complete(WebSocketChannel channel, BufferedBinaryMessage context) { try { WebSocketFrameType type = messageChannel.getType(); if (!controlFrame) { onFullBinaryMessage(channel, buffer); } else if (type == WebSocketFrameType.PONG) { onFullPongMessage(channel, buffer); } else if (type == WebSocketFrameType.PING) { onFullPingMessage(channel, buffer); } else if (type == WebSocketFrameType.CLOSE) { onFullCloseMessage(channel, buffer); } } catch (IOException e) { AbstractReceiveListener.this.onError(channel, e); } } @Override public void onError(WebSocketChannel channel, BufferedBinaryMessage context, Throwable throwable) { context.getData().close(); AbstractReceiveListener.this.onError(channel, throwable); } }); }
private void readBufferedBinary(final StreamSourceFrameChannel messageChannel, final boolean controlFrame, final BufferedBinaryMessage buffer) { buffer.read(messageChannel, new WebSocketCallback<BufferedBinaryMessage>() { @Override public void complete(WebSocketChannel channel, BufferedBinaryMessage context) { try { WebSocketFrameType type = messageChannel.getType(); if (!controlFrame) { onFullBinaryMessage(channel, buffer); } else if (type == WebSocketFrameType.PONG) { onFullPongMessage(channel, buffer); } else if (type == WebSocketFrameType.PING) { onFullPingMessage(channel, buffer); } else if (type == WebSocketFrameType.CLOSE) { onFullCloseMessage(channel, buffer); } } catch (IOException e) { AbstractReceiveListener.this.onError(channel, e); } } @Override public void onError(WebSocketChannel channel, BufferedBinaryMessage context, Throwable throwable) { context.getData().close(); AbstractReceiveListener.this.onError(channel, throwable); } }); }
checkMaxSize(channel, res); if (bufferFullMessage) { dealWithFullBuffer(channel); } else if (!current.getBuffer().hasRemaining()) { callback.complete(channel.getWebSocketChannel(), BufferedBinaryMessage.this);
/** * Utility method that reads a full text or binary message, including all fragmented parts. Once the full message is * read then the {@link #onFullTextMessage(WebSocketChannel, BufferedTextMessage)} or * {@link #onFullBinaryMessage(WebSocketChannel, BufferedBinaryMessage)} method will be invoked. * * @param messageChannel The message channel */ protected final void bufferFullMessage(StreamSourceFrameChannel messageChannel) { if (messageChannel.getType() == WebSocketFrameType.TEXT) { readBufferedText(messageChannel, new BufferedTextMessage(getMaxTextBufferSize(), true)); } else if (messageChannel.getType() == WebSocketFrameType.BINARY) { readBufferedBinary(messageChannel, false, new BufferedBinaryMessage(getMaxBinaryBufferSize(), true)); } else if (messageChannel.getType() == WebSocketFrameType.PONG) { readBufferedBinary(messageChannel, true, new BufferedBinaryMessage(getMaxPongBufferSize(), true)); } else if (messageChannel.getType() == WebSocketFrameType.PING) { readBufferedBinary(messageChannel, true, new BufferedBinaryMessage(getMaxPingBufferSize(), true)); } else if (messageChannel.getType() == WebSocketFrameType.CLOSE) { readBufferedBinary(messageChannel, true, new BufferedBinaryMessage(getMaxCloseBufferSize(), true)); } }
private void readBufferedBinary(final StreamSourceFrameChannel messageChannel, final boolean controlFrame, final BufferedBinaryMessage buffer) { buffer.read(messageChannel, new WebSocketCallback<BufferedBinaryMessage>() { @Override public void complete(WebSocketChannel channel, BufferedBinaryMessage context) { try { WebSocketFrameType type = messageChannel.getType(); if (!controlFrame) { onFullBinaryMessage(channel, buffer); } else if (type == WebSocketFrameType.PONG) { onFullPongMessage(channel, buffer); } else if (type == WebSocketFrameType.PING) { onFullPingMessage(channel, buffer); } else if (type == WebSocketFrameType.CLOSE) { onFullCloseMessage(channel, buffer); } } catch (IOException e) { AbstractReceiveListener.this.onError(channel, e); } } @Override public void onError(WebSocketChannel channel, BufferedBinaryMessage context, Throwable throwable) { context.getData().close(); AbstractReceiveListener.this.onError(channel, throwable); } }); }
protected void onFullPongMessage(final WebSocketChannel channel, BufferedBinaryMessage message) throws IOException { message.getData().free(); }
public void readBlocking(StreamSourceFrameChannel channel) throws IOException { if (current == null) { current = channel.getWebSocketChannel().getBufferPool().allocate(); } for (; ; ) { int res = channel.read(current.getBuffer()); if (res == -1) { complete = true; return; } else if (res == 0) { channel.awaitReadable(); } checkMaxSize(channel, res); if (bufferFullMessage) { dealWithFullBuffer(channel); } else if (!current.getBuffer().hasRemaining()) { return; } } }
/** * Utility method that reads a full text or binary message, including all fragmented parts. Once the full message is * read then the {@link #onFullTextMessage(WebSocketChannel, BufferedTextMessage)} or * {@link #onFullBinaryMessage(WebSocketChannel, BufferedBinaryMessage)} method will be invoked. * * @param messageChannel The message channel */ protected final void bufferFullMessage(StreamSourceFrameChannel messageChannel) { if (messageChannel.getType() == WebSocketFrameType.TEXT) { readBufferedText(messageChannel, new BufferedTextMessage(getMaxTextBufferSize(), true)); } else if (messageChannel.getType() == WebSocketFrameType.BINARY) { readBufferedBinary(messageChannel, false, new BufferedBinaryMessage(getMaxBinaryBufferSize(), true)); } else if (messageChannel.getType() == WebSocketFrameType.PONG) { readBufferedBinary(messageChannel, true, new BufferedBinaryMessage(getMaxPongBufferSize(), true)); } else if (messageChannel.getType() == WebSocketFrameType.PING) { readBufferedBinary(messageChannel, true, new BufferedBinaryMessage(getMaxPingBufferSize(), true)); } else if (messageChannel.getType() == WebSocketFrameType.CLOSE) { readBufferedBinary(messageChannel, true, new BufferedBinaryMessage(getMaxCloseBufferSize(), true)); } }
protected void onFullBinaryMessage(final WebSocketChannel channel, BufferedBinaryMessage message) throws IOException { message.getData().free(); }
public void readBlocking(StreamSourceFrameChannel channel) throws IOException { if (current == null) { current = channel.getWebSocketChannel().getBufferPool().allocate(); } for (; ; ) { int res = channel.read(current.getBuffer()); if (res == -1) { complete = true; return; } else if (res == 0) { channel.awaitReadable(); } checkMaxSize(channel, res); if (bufferFullMessage) { dealWithFullBuffer(channel); } else if (!current.getBuffer().hasRemaining()) { return; } } }
@Override protected void onFullCloseMessage(WebSocketChannel channel, BufferedBinaryMessage message) { CloseMessage closeMessage = new CloseMessage(message.getData().getResource()); this.session.handleClose(new CloseStatus(closeMessage.getCode(), closeMessage.getReason())); message.getData().free(); }
checkMaxSize(channel, res); if (bufferFullMessage) { dealWithFullBuffer(channel); } else if (!current.getBuffer().hasRemaining()) { callback.complete(channel.getWebSocketChannel(), BufferedBinaryMessage.this);
@Override public void onError(WebSocketChannel channel, BufferedBinaryMessage context, Throwable throwable) { context.getData().close(); AbstractReceiveListener.this.onError(channel, throwable); } });
checkMaxSize(channel, res); if (bufferFullMessage) { dealWithFullBuffer(channel); } else if (!current.getBuffer().hasRemaining()) { callback.complete(channel.getWebSocketChannel(), BufferedBinaryMessage.this);
@Override protected void onFullBinaryMessage(final WebSocketChannel channel, final BufferedBinaryMessage message) throws IOException { ready(); Pooled<ByteBuffer[]> data = message.getData(); try { this.onBinaryCallback.accept(WebSockets.mergeBuffers(data.getResource())); } finally { data.free(); } }
protected void onFullPingMessage(final WebSocketChannel channel, BufferedBinaryMessage message) throws IOException { final Pooled<ByteBuffer[]> data = message.getData(); WebSockets.sendPong(data.getResource(), channel, new FreeDataCallback(data)); }