GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Remove method from Channel.Unsafe to retrieve ChannelOutboundBuffer · netty/netty@b42c5df

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-classes-quic/src/main/java/io/netty/handler/codec/quic
    • QuicheQuicStreamChannel.java
  • codec-http2/src
    • main/java/io/netty/handler/codec/http2
      • AbstractHttp2StreamChannel.java
    • test/java/io/netty/handler/codec/http2
      • Http2MultiplexTest.java
  • codec-http3/src/test/java/io/netty/handler/codec/http3
    • EmbeddedQuicStreamChannel.java
  • handler/src
    • main/java/io/netty/handler
      • ssl
        • SslHandler.java
      • timeout
        • IdleStateHandler.java
      • traffic
        • AbstractTrafficShapingHandler.java
    • test/java/io/netty/handler
      • timeout
        • IdleStateHandlerTest.java
      • traffic
        • TrafficShapingHandlerTest.java
  • testsuite/src/main/java/io/netty/testsuite/transport/socket
    • TrafficShapingHandlerTest.java
  • transport-classes-epoll/src/main/java/io/netty/channel/epoll
    • EpollSocketChannel.java
  • transport-classes-io_uring/src/main/java/io/netty/channel/uring
    • AbstractIoUringChannel.java
    • AbstractIoUringStreamChannel.java
    • IoUringDomainSocketChannel.java
    • IoUringSocketChannel.java
  • transport-classes-kqueue/src/main/java/io/netty/channel/kqueue
    • KQueueSocketChannel.java
  • transport/src
    • main/java/io/netty/channel
      • AbstractChannel.java
      • Channel.java
      • DefaultChannelPipeline.java
      • PendingBytesTracker.java
      • embedded
        • EmbeddedChannel.java
    • test/java/io/netty/channel
      • ChannelOutboundBufferTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicheQuicStreamChannel.java‎

Copy file name to clipboardExpand all lines: codec-classes-quic/src/main/java/io/netty/handler/codec/quic/QuicheQuicStreamChannel.java
+14-8Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import io.netty.channel.ChannelFuture;
2323
import io.netty.channel.ChannelId;
2424
import io.netty.channel.ChannelMetadata;
25-
import io.netty.channel.ChannelOutboundBuffer;
2625
import io.netty.channel.ChannelPipeline;
2726
import io.netty.channel.ChannelPromise;
2827
import io.netty.channel.DefaultChannelId;
@@ -75,6 +74,7 @@ final class QuicheQuicStreamChannel extends DefaultAttributeMap implements QuicS
7574
private volatile boolean outputShutdown;
7675
private volatile QuicStreamPriority priority;
7776
private volatile long capacity;
77+
private volatile boolean hasPending;
7878

7979
QuicheQuicStreamChannel(QuicheQuicChannel parent, long streamId) {
8080
this.parent = parent;
@@ -94,6 +94,11 @@ final class QuicheQuicStreamChannel extends DefaultAttributeMap implements QuicS
9494
}
9595
}
9696

97+
@Override
98+
public boolean hasPendingBytes() {
99+
return hasPending;
100+
}
101+
97102
@Override
98103
public QuicStreamAddress localAddress() {
99104
return address;
@@ -686,6 +691,7 @@ boolean writeQueued() {
686691
}
687692
return written;
688693
} finally {
694+
updateHasPending();
689695
closeIfNeeded(wasFinSent);
690696
inWriteQueued = false;
691697
}
@@ -718,7 +724,7 @@ public void write(Object msg, ChannelPromise promise) {
718724
// Touch the message to make things easier in terms of debugging buffer leaks.
719725
ReferenceCountUtil.touch(msg);
720726
queue.add(msg, promise);
721-
727+
updateHasPending();
722728
// Try again to write queued messages.
723729
writeQueued();
724730
} else {
@@ -732,7 +738,13 @@ private void queueAndFailAll(Object msg, ChannelPromise promise, Throwable cause
732738
ReferenceCountUtil.touch(msg);
733739

734740
queue.add(msg, promise);
741+
updateHasPending();
735742
queue.removeAndFailAll(cause);
743+
updateHasPending();
744+
}
745+
746+
private void updateHasPending() {
747+
hasPending = queue.bytes() > 0;
736748
}
737749

738750
private Object filterMsg(Object msg) {
@@ -866,12 +878,6 @@ public void flush() {
866878
// NOOP.
867879
}
868880

869-
@Override
870-
@Nullable
871-
public ChannelOutboundBuffer outboundBuffer() {
872-
return null;
873-
}
874-
875881
private void closeOnRead(ChannelPipeline pipeline, boolean readFrames) {
876882
if (readFrames && finReceived && finSent) {
877883
close(newPromise());
Collapse file

‎codec-http2/src/main/java/io/netty/handler/codec/http2/AbstractHttp2StreamChannel.java‎

Copy file name to clipboardExpand all lines: codec-http2/src/main/java/io/netty/handler/codec/http2/AbstractHttp2StreamChannel.java
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ public void run() {
334334
pipeline.fireChannelWritabilityChanged();
335335
}
336336
}
337+
338+
@Override
339+
public boolean hasPendingBytes() {
340+
return false;
341+
}
342+
337343
@Override
338344
public Http2FrameStream stream() {
339345
return stream;
@@ -1169,12 +1175,6 @@ public void flush() {
11691175
writeDoneAndNoFlush = false;
11701176
flush0(parentContext());
11711177
}
1172-
1173-
@Override
1174-
public ChannelOutboundBuffer outboundBuffer() {
1175-
// Always return null as we not use the ChannelOutboundBuffer and not even support it.
1176-
return null;
1177-
}
11781178
}
11791179

11801180
/**
Collapse file

‎codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTest.java‎

Copy file name to clipboardExpand all lines: codec-http2/src/test/java/io/netty/handler/codec/http2/Http2MultiplexTest.java
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public abstract class Http2MultiplexTest<C extends Http2FrameCodec> {
9090
.method(HttpMethod.GET.asciiName()).scheme(HttpScheme.HTTPS.name())
9191
.authority(new AsciiString("example.org")).path(new AsciiString("/foo"));
9292

93-
private EmbeddedChannel parentChannel;
93+
private ParentChannel parentChannel;
9494
private Http2FrameWriter frameWriter;
9595
private Http2FrameInboundWriter frameInboundWriter;
9696
private TestChannelInitializer childChannelInitializer;
@@ -104,7 +104,7 @@ public abstract class Http2MultiplexTest<C extends Http2FrameCodec> {
104104
@BeforeEach
105105
public void setUp() {
106106
childChannelInitializer = new TestChannelInitializer();
107-
parentChannel = new EmbeddedChannel();
107+
parentChannel = new ParentChannel();
108108
frameInboundWriter = new Http2FrameInboundWriter(parentChannel);
109109
parentChannel.connect(new InetSocketAddress(0));
110110
frameWriter = Http2TestUtil.mockedFrameWriter();
@@ -1136,8 +1136,7 @@ public void writabilityOfParentIsRespected() {
11361136
// Add something to the ChannelOutboundBuffer of the parent to simulate queuing in the parents channel buffer
11371137
// and verify that this only affect the writability of the parent channel while the child stays writable
11381138
// until it used all of its credits.
1139-
parentChannel.unsafe().outboundBuffer().addMessage(
1140-
Unpooled.buffer().writeZero(800), 800, parentChannel.newPromise());
1139+
parentChannel.addBuffer(Unpooled.buffer().writeZero(800));
11411140
assertFalse(parentChannel.isWritable());
11421141

11431142
assertTrue(childChannel.isWritable());
@@ -1724,4 +1723,11 @@ private static void verifyFramesMultiplexedToCorrectChannel(Http2StreamChannel s
17241723
private static int eqStreamId(Http2StreamChannel channel) {
17251724
return eq(channel.stream().id());
17261725
}
1726+
1727+
private static final class ParentChannel extends EmbeddedChannel {
1728+
1729+
void addBuffer(ByteBuf buf) {
1730+
outboundBuffer().addMessage(buf, buf.readableBytes(), newPromise());
1731+
}
1732+
}
17271733
}
Collapse file

‎codec-http3/src/test/java/io/netty/handler/codec/http3/EmbeddedQuicStreamChannel.java‎

Copy file name to clipboardExpand all lines: codec-http3/src/test/java/io/netty/handler/codec/http3/EmbeddedQuicStreamChannel.java
-5Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,6 @@ public void write(Object msg, ChannelPromise promise) {
263263
public void flush() {
264264
superUnsafe.flush();
265265
}
266-
267-
@Override
268-
public ChannelOutboundBuffer outboundBuffer() {
269-
return superUnsafe.outboundBuffer();
270-
}
271266
};
272267
}
273268
return unsafe;
Collapse file

‎handler/src/main/java/io/netty/handler/ssl/SslHandler.java‎

Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/SslHandler.java
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,8 +2181,7 @@ protected int wrapDataSize() {
21812181
// If we weren't able to include client_hello in the TCP SYN (e.g. no token, disabled at the OS) we have to
21822182
// flush pending data in the outbound buffer later in channelActive().
21832183
final ChannelOutboundBuffer outboundBuffer;
2184-
if (fastOpen && ((outboundBuffer = channel.unsafe().outboundBuffer()) == null ||
2185-
outboundBuffer.totalPendingWriteBytes() > 0)) {
2184+
if (fastOpen && channel.hasPendingBytes()) {
21862185
setState(STATE_NEEDS_FLUSH);
21872186
}
21882187
}
Collapse file

‎handler/src/main/java/io/netty/handler/timeout/IdleStateHandler.java‎

Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/timeout/IdleStateHandler.java
+2-101Lines changed: 2 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ public void operationComplete(ChannelFuture future) throws Exception {
109109
}
110110
};
111111

112-
private final boolean observeOutput;
113112
private final long readerIdleTimeNanos;
114113
private final long writerIdleTimeNanos;
115114
private final long allIdleTimeNanos;
@@ -133,11 +132,6 @@ public void operationComplete(ChannelFuture future) throws Exception {
133132

134133
private boolean reading;
135134

136-
private long lastChangeCheckTimeStamp;
137-
private int lastMessageHashCode;
138-
private long lastPendingWriteBytes;
139-
private long lastFlushProgress;
140-
141135
/**
142136
* Creates a new instance firing {@link IdleStateEvent}s.
143137
*
@@ -163,21 +157,9 @@ public IdleStateHandler(
163157
TimeUnit.SECONDS);
164158
}
165159

166-
/**
167-
* @see #IdleStateHandler(boolean, long, long, long, TimeUnit)
168-
*/
169-
public IdleStateHandler(
170-
long readerIdleTime, long writerIdleTime, long allIdleTime,
171-
TimeUnit unit) {
172-
this(false, readerIdleTime, writerIdleTime, allIdleTime, unit);
173-
}
174-
175160
/**
176161
* Creates a new instance firing {@link IdleStateEvent}s.
177-
*
178-
* @param observeOutput
179-
* whether or not the consumption of {@code bytes} should be taken into
180-
* consideration when assessing write idleness. The default is {@code false}.
162+
181163
* @param readerIdleTime
182164
* an {@link IdleStateEvent} whose state is {@link IdleState#READER_IDLE}
183165
* will be triggered when no read was performed for the specified
@@ -194,13 +176,10 @@ public IdleStateHandler(
194176
* the {@link TimeUnit} of {@code readerIdleTime},
195177
* {@code writeIdleTime}, and {@code allIdleTime}
196178
*/
197-
public IdleStateHandler(boolean observeOutput,
198-
long readerIdleTime, long writerIdleTime, long allIdleTime,
179+
public IdleStateHandler(long readerIdleTime, long writerIdleTime, long allIdleTime,
199180
TimeUnit unit) {
200181
ObjectUtil.checkNotNull(unit, "unit");
201182

202-
this.observeOutput = observeOutput;
203-
204183
if (readerIdleTime <= 0) {
205184
readerIdleTimeNanos = 0;
206185
} else {
@@ -343,7 +322,6 @@ private void initialize(ChannelHandlerContext ctx) {
343322
}
344323

345324
state = ST_INITIALIZED;
346-
initOutputChanged(ctx);
347325

348326
lastReadTime = lastWriteTime = ticker.nanoTime();
349327
if (readerIdleTimeNanos > 0) {
@@ -408,75 +386,6 @@ protected IdleStateEvent newIdleStateEvent(IdleState state, boolean first) {
408386
}
409387
}
410388

411-
/**
412-
* @see #hasOutputChanged(ChannelHandlerContext, boolean)
413-
*/
414-
private void initOutputChanged(ChannelHandlerContext ctx) {
415-
if (observeOutput) {
416-
Channel channel = ctx.channel();
417-
Unsafe unsafe = channel.unsafe();
418-
ChannelOutboundBuffer buf = unsafe.outboundBuffer();
419-
420-
if (buf != null) {
421-
lastMessageHashCode = System.identityHashCode(buf.current());
422-
lastPendingWriteBytes = buf.totalPendingWriteBytes();
423-
lastFlushProgress = buf.currentProgress();
424-
}
425-
}
426-
}
427-
428-
/**
429-
* Returns {@code true} if and only if the {@link IdleStateHandler} was constructed
430-
* with {@link #observeOutput} enabled and there has been an observed change in the
431-
* {@link ChannelOutboundBuffer} between two consecutive calls of this method.
432-
*
433-
* https://github.com/netty/netty/issues/6150
434-
*/
435-
private boolean hasOutputChanged(ChannelHandlerContext ctx, boolean first) {
436-
if (observeOutput) {
437-
438-
// We can take this shortcut if the ChannelPromises that got passed into write()
439-
// appear to complete. It indicates "change" on message level and we simply assume
440-
// that there's change happening on byte level. If the user doesn't observe channel
441-
// writability events then they'll eventually OOME and there's clearly a different
442-
// problem and idleness is least of their concerns.
443-
if (lastChangeCheckTimeStamp != lastWriteTime) {
444-
lastChangeCheckTimeStamp = lastWriteTime;
445-
446-
// But this applies only if it's the non-first call.
447-
if (!first) {
448-
return true;
449-
}
450-
}
451-
452-
Channel channel = ctx.channel();
453-
Unsafe unsafe = channel.unsafe();
454-
ChannelOutboundBuffer buf = unsafe.outboundBuffer();
455-
456-
if (buf != null) {
457-
int messageHashCode = System.identityHashCode(buf.current());
458-
long pendingWriteBytes = buf.totalPendingWriteBytes();
459-
460-
if (messageHashCode != lastMessageHashCode || pendingWriteBytes != lastPendingWriteBytes) {
461-
lastMessageHashCode = messageHashCode;
462-
lastPendingWriteBytes = pendingWriteBytes;
463-
464-
if (!first) {
465-
return true;
466-
}
467-
}
468-
469-
long flushProgress = buf.currentProgress();
470-
if (flushProgress != lastFlushProgress) {
471-
lastFlushProgress = flushProgress;
472-
return !first;
473-
}
474-
}
475-
}
476-
477-
return false;
478-
}
479-
480389
private abstract static class AbstractIdleTask implements Runnable {
481390

482391
private final ChannelHandlerContext ctx;
@@ -549,10 +458,6 @@ protected void run(ChannelHandlerContext ctx) {
549458
firstWriterIdleEvent = false;
550459

551460
try {
552-
if (hasOutputChanged(ctx, first)) {
553-
return;
554-
}
555-
556461
IdleStateEvent event = newIdleStateEvent(IdleState.WRITER_IDLE, first);
557462
channelIdle(ctx, event);
558463
} catch (Throwable t) {
@@ -587,10 +492,6 @@ protected void run(ChannelHandlerContext ctx) {
587492
firstAllIdleEvent = false;
588493

589494
try {
590-
if (hasOutputChanged(ctx, first)) {
591-
return;
592-
}
593-
594495
IdleStateEvent event = newIdleStateEvent(IdleState.ALL_IDLE, first);
595496
channelIdle(ctx, event);
596497
} catch (Throwable t) {
Collapse file

‎handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java‎

Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/traffic/AbstractTrafficShapingHandler.java
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import io.netty.channel.ChannelDuplexHandler;
2424
import io.netty.channel.ChannelConfig;
2525
import io.netty.channel.ChannelHandlerContext;
26-
import io.netty.channel.ChannelOutboundBuffer;
2726
import io.netty.channel.ChannelPromise;
2827
import io.netty.channel.FileRegion;
2928
import io.netty.util.Attribute;
@@ -586,10 +585,11 @@ public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
586585
}
587586

588587
void setUserDefinedWritability(ChannelHandlerContext ctx, boolean writable) {
589-
ChannelOutboundBuffer cob = ctx.channel().unsafe().outboundBuffer();
588+
// TODO: Come up with a way to support this without leaking implementation details.
589+
/*ChannelOutboundBuffer cob = ctx.channel().unsafe().outboundBuffer();
590590
if (cob != null) {
591591
cob.setUserDefinedWritability(userDefinedWritabilityIndex, writable);
592-
}
592+
}*/
593593
}
594594

595595
/**

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.