Refine search
/** * Generates the default log message of the specified event whose argument is a {@link ByteBufHolder}. */ private static String formatByteBufHolder(ChannelHandlerContext ctx, String eventName, ByteBufHolder msg) { String chStr = ctx.channel().toString(); String msgStr = msg.toString(); ByteBuf content = msg.content(); int length = content.readableBytes(); if (length == 0) { StringBuilder buf = new StringBuilder(chStr.length() + 1 + eventName.length() + 2 + msgStr.length() + 4); buf.append(chStr).append(' ').append(eventName).append(", ").append(msgStr).append(", 0B"); return buf.toString(); } else { int rows = length / 16 + (length % 15 == 0? 0 : 1) + 4; StringBuilder buf = new StringBuilder( chStr.length() + 1 + eventName.length() + 2 + msgStr.length() + 2 + 10 + 1 + 2 + rows * 80); buf.append(chStr).append(' ').append(eventName).append(": ") .append(msgStr).append(", ").append(length).append('B').append(NEWLINE); appendPrettyHexDump(buf, content); return buf.toString(); } }
private void releaseCurrentMessage() { if (currentMessage != null) { currentMessage.release(); currentMessage = null; handlingOversizedMessage = false; } } }
private static Object safeDuplicate(Object message) { if (message instanceof ByteBuf) { return ((ByteBuf) message).retainedDuplicate(); } else if (message instanceof ByteBufHolder) { return ((ByteBufHolder) message).retainedDuplicate(); } else { return ReferenceCountUtil.retain(message); } }
@SuppressWarnings("unchecked") private static <T> T retainedDuplicate(ByteBufHolder o) { return (T) o.replace(o.content().retainedDuplicate()); }
private static <T> T copyAndRelease(ByteBufHolder o) { try { final ByteBuf content = Unpooled.wrappedBuffer(ByteBufUtil.getBytes(o.content())); @SuppressWarnings("unchecked") final T copy = (T) o.replace(content); return copy; } finally { ReferenceCountUtil.safeRelease(o); } }
handlingOversizedMessage = false; if (currentMessage != null) { currentMessage.release(); currentMessage = null; throw new MessageAggregationException(); Object continueResponse = newContinueResponse(m, maxContentLength, ctx.pipeline()); if (continueResponse != null) { handlingOversizedMessage = ignoreContentAfterContinueResponse(continueResponse); final ChannelFuture future = ctx.writeAndFlush(continueResponse).addListener(listener); O aggregated; if (m instanceof ByteBufHolder) { aggregated = beginAggregation(m, ((ByteBufHolder) m).content().retain()); } else { aggregated = beginAggregation(m, EMPTY_BUFFER); CompositeByteBuf content = ctx.alloc().compositeBuffer(maxCumulationBufferComponents); if (m instanceof ByteBufHolder) { appendPartialContent(content, ((ByteBufHolder) m).content()); CompositeByteBuf content = (CompositeByteBuf) currentMessage.content(); if (content.readableBytes() > maxContentLength - m.content().readableBytes()) { appendPartialContent(content, m.content());
ChannelFuture doWrite(Object msg, ChannelPromise promise, @Nullable PublisherSender inner) { if (flushOnEach || //fastpath !ctx.channel() ChannelFuture future = ctx.write(msg, promise); if (flushOnEachWithEventLoop && ctx.channel().isWritable()) { scheduleFlush(); if (msg instanceof ByteBuf) { pendingBytes = Operators.addCap(pendingBytes, ((ByteBuf) msg).readableBytes()); ((ByteBufHolder) msg).content() .readableBytes());
@Override public int size(Object msg) { if (msg instanceof ByteBuf) { return ((ByteBuf) msg).readableBytes(); } if (msg instanceof ByteBufHolder) { return ((ByteBufHolder) msg).content().readableBytes(); } if (msg instanceof FileRegion) { return 0; } return unknownSize; } }
/** * Decodes an {@link InetAddress} from an A or AAAA {@link DnsRawRecord}. * * @param record the {@link DnsRecord}, most likely a {@link DnsRawRecord} * @param name the host name of the decoded address * @param decodeIdn whether to convert {@code name} to a unicode host name * * @return the {@link InetAddress}, or {@code null} if {@code record} is not a {@link DnsRawRecord} or * its content is malformed */ static InetAddress decodeAddress(DnsRecord record, String name, boolean decodeIdn) { if (!(record instanceof DnsRawRecord)) { return null; } final ByteBuf content = ((ByteBufHolder) record).content(); final int contentLen = content.readableBytes(); if (contentLen != INADDRSZ4 && contentLen != INADDRSZ6) { return null; } final byte[] addrBytes = new byte[contentLen]; content.getBytes(content.readerIndex(), addrBytes); try { return InetAddress.getByAddress(decodeIdn ? IDN.toUnicode(name) : name, addrBytes); } catch (UnknownHostException e) { // Should never reach here. throw new Error(e); } }
ChannelOperations<?, ?> ops = ChannelOperations.get(ctx.channel()); if (ops != null) { ops.onInboundNext(ctx, msg); DecoderResult decoderResult = ((DecoderResultProvider) msg).decoderResult(); if (decoderResult.isFailure()) { log.debug(format(ctx.channel(), "Decoding failed: " + msg + " : "), decoderResult.cause()); if (msg instanceof ByteBufHolder && ((ByteBufHolder)msg).content() != Unpooled.EMPTY_BUFFER) { ByteBuf buffer = ((ByteBufHolder) msg).content(); loggingMsg = buffer.readCharSequence(buffer.readableBytes(), Charset.defaultCharset()).toString(); log.debug(format(ctx.channel(), "No ChannelOperation attached. Dropping: {}"), loggingMsg); ReferenceCountUtil.release(msg); Exceptions.throwIfFatal(err); exceptionCaught(ctx, err); ReferenceCountUtil.safeRelease(msg);
final ByteBuf content = ((ByteBufHolder) r).content(); if (!content.isReadable()) { // Missing length octet warnInvalidRecord(DnsRecordType.TXT, content); continue; content.markReaderIndex(); final int txtLen = content.readUnsignedByte(); if (txtLen == 0) { // Empty content continue;
HttpResponseStatus status = response.status(); if (status.equals(HttpResponseStatus.CONTINUE)) { ctx.write(msg, promise); return; accessLog.increaseContentLength(((LastHttpContent) msg).content().readableBytes()); ctx.write(msg, promise) .addListener(future -> { if (future.isSuccess()) { accessLog.increaseContentLength(((ByteBuf) msg).readableBytes()); accessLog.increaseContentLength(((ByteBufHolder) msg).content().readableBytes()); ctx.write(msg, promise);
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof CloseWebSocketFrame) { ctx.channel().writeAndFlush(msg).addListener(ChannelFutureListener.CLOSE); } else if (msg instanceof BinaryWebSocketFrame || msg instanceof TextWebSocketFrame) { ByteBufHolder frame = (ByteBufHolder) msg; ClientHead client = clientsBox.get(ctx.channel()); if (client == null) { log.debug("Client with was already disconnected. Channel closed!"); ctx.channel().close(); frame.release(); return; ctx.pipeline().fireChannelRead(new PacketsMessage(client, frame.content(), Transport.WEBSOCKET)); frame.release(); } else if (msg instanceof FullHttpRequest) { FullHttpRequest req = (FullHttpRequest) msg;
Long keepAliveTimeoutSeconds = rxResponse.getKeepAliveTimeoutSeconds(); if (null != keepAliveTimeoutSeconds) { ctx.channel().attr(KEEP_ALIVE_TIMEOUT_MILLIS_ATTR).set(keepAliveTimeoutSeconds * 1000); ctx.channel().attr(DISCARD_CONNECTION).set(true); ByteBuf content = ((ByteBufHolder) msg).content(); if (LastHttpContent.class.isAssignableFrom(recievedMsgClass)) { stateToUse.responseReceiveComplete(); if (content.isReadable()) { invokeContentOnNext(content, stateToUse); } else { ReferenceCountUtil.release(content);
final ByteBuf content = ((ByteBufHolder) r).content(); if (content.readableBytes() <= 6) { // Too few bytes warnInvalidRecord(DnsRecordType.SRV, content); continue; content.markReaderIndex(); content.skipBytes(2); // priority unused final int weight = content.readUnsignedShort(); final int port = content.readUnsignedShort();
final ByteBuf message; if (content instanceof ByteBufHolder) { message = ((ByteBufHolder) content).content(); } else { message = ctx.alloc().buffer(content.length()); message.writeBytes(content.array(), content.offset(), content.length()); } finally { if (!success) { message.release();
EventLoop eventLoop = ctx.channel().eventLoop(); ByteBuf content = ((ByteBufHolder) msg).content(); if (content.isReadable()) { contentProducer.ifPresent(producer -> producer.newChunk(retain(content)));
ChannelOperations<?, ?> ops = ChannelOperations.get(ctx.channel()); if (ops != null) { ops.onInboundNext(ctx, msg); DecoderResult decoderResult = ((HttpResponse) msg).decoderResult(); if (decoderResult.isFailure()) { log.debug(format(ctx.channel(), "Decoding failed: " + msg + " : "), decoderResult.cause()); loggingMsg = ((ByteBufHolder) msg).content() .toString(Charset.defaultCharset()); log.debug(format(ctx.channel(), "No ChannelOperation attached. Dropping: {}"), loggingMsg); ReferenceCountUtil.release(msg); Exceptions.throwIfFatal(err); exceptionCaught(ctx, err); ReferenceCountUtil.safeRelease(msg);
@Override public void startAsync(final Executor executor, final Runnable runnable) { Channel channel = ctx.channel(); channel.attr(NEED_FLUSH).set(false); channel.attr(ASYNC).set(true); ReferenceCounted body = ((ByteBufHolder) req).content(); body.retain(); executor.execute(() -> { try { runnable.run(); } finally { body.release(); } }); }