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 — Transport: Only allow DatagramPacket and ByteBuf to be be written for… · netty/netty@b6942bb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • transport-classes-epoll/src/main/java/io/netty/channel/epoll
    • EpollDatagramChannel.java
  • transport-classes-io_uring/src/main/java/io/netty/channel/uring
    • IoUringDatagramChannel.java
  • transport-classes-kqueue/src/main/java/io/netty/channel/kqueue
    • KQueueDatagramChannel.java
  • transport/src/main/java/io/netty/channel/socket/nio
    • NioDatagramChannel.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollDatagramChannel.java‎

Copy file name to clipboardExpand all lines: transport-classes-epoll/src/main/java/io/netty/channel/epoll/EpollDatagramChannel.java
+11-54Lines changed: 11 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,16 @@
1818
import io.netty.buffer.ByteBuf;
1919
import io.netty.buffer.ByteBufAllocator;
2020
import io.netty.buffer.Unpooled;
21-
import io.netty.channel.AddressedEnvelope;
2221
import io.netty.channel.ChannelFuture;
2322
import io.netty.channel.ChannelMetadata;
2423
import io.netty.channel.ChannelOutboundBuffer;
2524
import io.netty.channel.ChannelPipeline;
2625
import io.netty.channel.ChannelPromise;
27-
import io.netty.channel.DefaultAddressedEnvelope;
2826
import io.netty.channel.EventLoop;
2927
import io.netty.channel.socket.DatagramChannel;
3028
import io.netty.channel.socket.DatagramPacket;
3129
import io.netty.channel.socket.SocketProtocolFamily;
3230
import io.netty.channel.unix.DomainDatagramSocketAddress;
33-
import io.netty.channel.unix.DomainSocketAddress;
3431
import io.netty.channel.unix.Errors;
3532
import io.netty.channel.unix.Errors.NativeIoException;
3633
import io.netty.channel.unix.UnixChannelUtil;
@@ -67,19 +64,8 @@ public final class EpollDatagramChannel extends AbstractEpollChannel implements
6764
private static final ChannelMetadata METADATA = new ChannelMetadata(true, 16);
6865
private static final String EXPECTED_TYPES =
6966
" (expected: " + StringUtil.simpleClassName(DatagramPacket.class) + ", " +
70-
StringUtil.simpleClassName(AddressedEnvelope.class) + '<' +
71-
StringUtil.simpleClassName(ByteBuf.class) + ", " +
72-
StringUtil.simpleClassName(InetSocketAddress.class) + ">, " +
7367
StringUtil.simpleClassName(ByteBuf.class) + ')';
7468

75-
private static final String EXPECTED_TYPES_UNIX =
76-
" (expected: " +
77-
StringUtil.simpleClassName(DatagramPacket.class) + ", " +
78-
StringUtil.simpleClassName(AddressedEnvelope.class) + '<' +
79-
StringUtil.simpleClassName(ByteBuf.class) + ", " +
80-
StringUtil.simpleClassName(DomainSocketAddress.class) + ">, " +
81-
StringUtil.simpleClassName(ByteBuf.class) + ')';
82-
8369
private final EpollDatagramChannelConfig config;
8470
private volatile boolean connected;
8571

@@ -461,12 +447,10 @@ protected void doWrite(ChannelOutboundBuffer in) throws Exception {
461447
private boolean doWriteMessage(Object msg) throws Exception {
462448
final ByteBuf data;
463449
final SocketAddress remoteAddress;
464-
if (msg instanceof AddressedEnvelope) {
465-
@SuppressWarnings("unchecked")
466-
AddressedEnvelope<ByteBuf, SocketAddress> envelope =
467-
(AddressedEnvelope<ByteBuf, SocketAddress>) msg;
468-
data = envelope.content();
469-
remoteAddress = envelope.recipient();
450+
if (msg instanceof DatagramPacket) {
451+
DatagramPacket packet = (DatagramPacket) msg;
452+
data = packet.content();
453+
remoteAddress = packet.recipient();
470454
} else {
471455
data = (ByteBuf) msg;
472456
remoteAddress = null;
@@ -480,25 +464,10 @@ private boolean doWriteMessage(Object msg) throws Exception {
480464
return doWriteOrSendBytes(data, remoteAddress, false) > 0;
481465
}
482466

483-
private void checkEnvelope(AddressedEnvelope<?, ?> envelope) {
484-
if (envelope == null) {
485-
return;
486-
}
487-
488-
if (socket.protocolFamily() == SocketProtocolFamily.UNIX) {
489-
if (!(envelope.content() instanceof ByteBuf) || !(envelope.recipient() instanceof DomainSocketAddress)) {
490-
throw new UnsupportedOperationException(
491-
"unsupported message type: " + StringUtil.simpleClassName(envelope) + EXPECTED_TYPES_UNIX);
492-
}
493-
} else {
494-
if (envelope.content() instanceof ByteBuf && envelope.recipient() instanceof InetSocketAddress) {
495-
if (((InetSocketAddress) envelope.recipient()).isUnresolved()) {
496-
throw new UnresolvedAddressException();
497-
}
498-
} else {
499-
throw new UnsupportedOperationException(
500-
"unsupported message type: " + StringUtil.simpleClassName(envelope) + EXPECTED_TYPES);
501-
}
467+
private static void checkUnresolved(SocketAddress address) {
468+
if (address instanceof InetSocketAddress
469+
&& (((InetSocketAddress) address).isUnresolved())) {
470+
throw new UnresolvedAddressException();
502471
}
503472
}
504473

@@ -510,15 +479,15 @@ protected Object filterOutboundMessage(Object msg) {
510479
"unsupported message type: " + StringUtil.simpleClassName(msg) + EXPECTED_TYPES);
511480
}
512481
io.netty.channel.unix.SegmentedDatagramPacket packet = (io.netty.channel.unix.SegmentedDatagramPacket) msg;
513-
checkEnvelope(packet);
482+
checkUnresolved(packet.recipient());
514483

515484
ByteBuf content = packet.content();
516485
return UnixChannelUtil.isBufferCopyNeededForWrite(content) ?
517486
packet.replace(newDirectBuffer(packet, content)) : msg;
518487
}
519488
if (msg instanceof DatagramPacket) {
520489
DatagramPacket packet = (DatagramPacket) msg;
521-
checkEnvelope(packet);
490+
checkUnresolved(packet.recipient());
522491
ByteBuf content = packet.content();
523492
return UnixChannelUtil.isBufferCopyNeededForWrite(content) ?
524493
new DatagramPacket(newDirectBuffer(packet, content), packet.recipient()) : msg;
@@ -528,20 +497,8 @@ protected Object filterOutboundMessage(Object msg) {
528497
ByteBuf buf = (ByteBuf) msg;
529498
return UnixChannelUtil.isBufferCopyNeededForWrite(buf)? newDirectBuffer(buf) : buf;
530499
}
531-
532-
if (msg instanceof AddressedEnvelope) {
533-
@SuppressWarnings("unchecked")
534-
AddressedEnvelope<Object, SocketAddress> e = (AddressedEnvelope<Object, SocketAddress>) msg;
535-
checkEnvelope(e);
536-
537-
ByteBuf content = (ByteBuf) e.content();
538-
return UnixChannelUtil.isBufferCopyNeededForWrite(content)?
539-
new DefaultAddressedEnvelope<ByteBuf, InetSocketAddress>(
540-
newDirectBuffer(e, content), (InetSocketAddress) e.recipient()) : e;
541-
}
542500
throw new UnsupportedOperationException(
543-
"unsupported message type: " + StringUtil.simpleClassName(msg) +
544-
(socket.protocolFamily() == SocketProtocolFamily.UNIX ? EXPECTED_TYPES_UNIX : EXPECTED_TYPES));
501+
"unsupported message type: " + StringUtil.simpleClassName(msg) + EXPECTED_TYPES);
545502
}
546503

547504
@Override
Collapse file

‎transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringDatagramChannel.java‎

Copy file name to clipboardExpand all lines: transport-classes-io_uring/src/main/java/io/netty/channel/uring/IoUringDatagramChannel.java
+8-28Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
package io.netty.channel.uring;
1717

1818
import io.netty.buffer.ByteBuf;
19-
import io.netty.channel.AddressedEnvelope;
2019
import io.netty.channel.ChannelFuture;
2120
import io.netty.channel.ChannelMetadata;
2221
import io.netty.channel.ChannelOutboundBuffer;
2322
import io.netty.channel.ChannelPipeline;
2423
import io.netty.channel.ChannelPromise;
25-
import io.netty.channel.DefaultAddressedEnvelope;
2624
import io.netty.channel.EventLoop;
2725
import io.netty.channel.IoRegistration;
2826
import io.netty.channel.socket.DatagramChannel;
@@ -58,9 +56,6 @@ public final class IoUringDatagramChannel extends AbstractIoUringChannel impleme
5856
private static final ChannelMetadata METADATA = new ChannelMetadata(true, 16);
5957
private static final String EXPECTED_TYPES =
6058
" (expected: " + StringUtil.simpleClassName(DatagramPacket.class) + ", " +
61-
StringUtil.simpleClassName(AddressedEnvelope.class) + '<' +
62-
StringUtil.simpleClassName(ByteBuf.class) + ", " +
63-
StringUtil.simpleClassName(InetSocketAddress.class) + ">, " +
6459
StringUtil.simpleClassName(ByteBuf.class) + ')';
6560

6661
private final IoUringDatagramChannelConfig config;
@@ -311,9 +306,9 @@ protected void doBind(SocketAddress localAddress, ChannelPromise promise) {
311306
}));
312307
}
313308

314-
private static void checkUnresolved(AddressedEnvelope<?, ?> envelope) {
315-
if (envelope.recipient() instanceof InetSocketAddress
316-
&& (((InetSocketAddress) envelope.recipient()).isUnresolved())) {
309+
private static void checkUnresolved(SocketAddress address) {
310+
if (address instanceof InetSocketAddress
311+
&& (((InetSocketAddress) address).isUnresolved())) {
317312
throw new UnresolvedAddressException();
318313
}
319314
}
@@ -322,7 +317,7 @@ private static void checkUnresolved(AddressedEnvelope<?, ?> envelope) {
322317
protected Object filterOutboundMessage(Object msg) {
323318
if (msg instanceof DatagramPacket) {
324319
DatagramPacket packet = (DatagramPacket) msg;
325-
checkUnresolved(packet);
320+
checkUnresolved(packet.recipient());
326321
ByteBuf content = packet.content();
327322
return !content.hasMemoryAddress() ?
328323
packet.replace(newDirectBuffer(packet, content)) : msg;
@@ -333,20 +328,6 @@ protected Object filterOutboundMessage(Object msg) {
333328
return !buf.hasMemoryAddress()? newDirectBuffer(buf) : buf;
334329
}
335330

336-
if (msg instanceof AddressedEnvelope) {
337-
@SuppressWarnings("unchecked")
338-
AddressedEnvelope<Object, SocketAddress> e = (AddressedEnvelope<Object, SocketAddress>) msg;
339-
checkUnresolved(e);
340-
if (e.content() instanceof ByteBuf &&
341-
(e.recipient() == null || e.recipient() instanceof InetSocketAddress)) {
342-
343-
ByteBuf content = (ByteBuf) e.content();
344-
return !content.hasMemoryAddress()?
345-
new DefaultAddressedEnvelope<>(
346-
newDirectBuffer(e, content), (InetSocketAddress) e.recipient()) : e;
347-
}
348-
}
349-
350331
throw new UnsupportedOperationException(
351332
"unsupported message type: " + StringUtil.simpleClassName(msg) + EXPECTED_TYPES);
352333
}
@@ -597,12 +578,11 @@ private boolean scheduleWrite(Object msg, boolean first) {
597578
final ByteBuf data;
598579
final InetSocketAddress remoteAddress;
599580
final int segmentSize;
600-
if (msg instanceof AddressedEnvelope) {
581+
if (msg instanceof DatagramPacket) {
601582
@SuppressWarnings("unchecked")
602-
AddressedEnvelope<ByteBuf, InetSocketAddress> envelope =
603-
(AddressedEnvelope<ByteBuf, InetSocketAddress>) msg;
604-
data = envelope.content();
605-
remoteAddress = envelope.recipient();
583+
DatagramPacket packet = (DatagramPacket) msg;
584+
data = packet.content();
585+
remoteAddress = (InetSocketAddress) packet.recipient();
606586
if (msg instanceof SegmentedDatagramPacket) {
607587
segmentSize = ((SegmentedDatagramPacket) msg).segmentSize();
608588
} else {
Collapse file

‎transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDatagramChannel.java‎

Copy file name to clipboardExpand all lines: transport-classes-kqueue/src/main/java/io/netty/channel/kqueue/KQueueDatagramChannel.java
+10-51Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717

1818
import io.netty.buffer.ByteBuf;
1919
import io.netty.buffer.ByteBufAllocator;
20-
import io.netty.channel.AddressedEnvelope;
2120
import io.netty.channel.ChannelFuture;
2221
import io.netty.channel.ChannelMetadata;
2322
import io.netty.channel.ChannelOutboundBuffer;
2423
import io.netty.channel.ChannelPipeline;
2524
import io.netty.channel.ChannelPromise;
26-
import io.netty.channel.DefaultAddressedEnvelope;
2725
import io.netty.channel.EventLoop;
2826
import io.netty.channel.socket.DatagramChannel;
2927
import io.netty.channel.socket.DatagramChannelConfig;
@@ -56,17 +54,6 @@
5654
public final class KQueueDatagramChannel extends AbstractKQueueChannel implements DatagramChannel {
5755
private static final String EXPECTED_TYPES =
5856
" (expected: " + StringUtil.simpleClassName(DatagramPacket.class) + ", " +
59-
StringUtil.simpleClassName(AddressedEnvelope.class) + '<' +
60-
StringUtil.simpleClassName(ByteBuf.class) + ", " +
61-
StringUtil.simpleClassName(InetSocketAddress.class) + ">, " +
62-
StringUtil.simpleClassName(ByteBuf.class) + ')';
63-
64-
private static final String EXPECTED_TYPES_UNIX =
65-
" (expected: " +
66-
StringUtil.simpleClassName(DatagramPacket.class) + ", " +
67-
StringUtil.simpleClassName(AddressedEnvelope.class) + '<' +
68-
StringUtil.simpleClassName(ByteBuf.class) + ", " +
69-
StringUtil.simpleClassName(DomainSocketAddress.class) + ">, " +
7057
StringUtil.simpleClassName(ByteBuf.class) + ')';
7158

7259
private static final ChannelMetadata METADATA = new ChannelMetadata(true, 16);
@@ -345,12 +332,10 @@ public ChannelFuture block(
345332
private boolean doWriteMessage(Object msg) throws Exception {
346333
final ByteBuf data;
347334
SocketAddress remoteAddress;
348-
if (msg instanceof AddressedEnvelope) {
349-
@SuppressWarnings("unchecked")
350-
AddressedEnvelope<ByteBuf, SocketAddress> envelope =
351-
(AddressedEnvelope<ByteBuf, SocketAddress>) msg;
352-
data = envelope.content();
353-
remoteAddress = envelope.recipient();
335+
if (msg instanceof DatagramPacket) {
336+
DatagramPacket packet = (DatagramPacket) msg;
337+
data = packet.content();
338+
remoteAddress = packet.recipient();
354339
} else {
355340
data = (ByteBuf) msg;
356341
remoteAddress = null;
@@ -416,33 +401,18 @@ private boolean doWriteMessage(Object msg) throws Exception {
416401
return writtenBytes > 0;
417402
}
418403

419-
private void checkEnvelope(AddressedEnvelope<?, ?> envelope) {
420-
if (envelope == null) {
421-
return;
422-
}
423-
424-
if (socket.protocolFamily() == SocketProtocolFamily.UNIX) {
425-
if (!(envelope.content() instanceof ByteBuf) || !(envelope.recipient() instanceof DomainSocketAddress)) {
426-
throw new UnsupportedOperationException(
427-
"unsupported message type: " + StringUtil.simpleClassName(envelope) + EXPECTED_TYPES_UNIX);
428-
}
429-
} else {
430-
if (envelope.content() instanceof ByteBuf && envelope.recipient() instanceof InetSocketAddress) {
431-
if (((InetSocketAddress) envelope.recipient()).isUnresolved()) {
432-
throw new UnresolvedAddressException();
433-
}
434-
} else {
435-
throw new UnsupportedOperationException(
436-
"unsupported message type: " + StringUtil.simpleClassName(envelope) + EXPECTED_TYPES);
437-
}
404+
private static void checkUnresolved(SocketAddress address) {
405+
if (address instanceof InetSocketAddress
406+
&& (((InetSocketAddress) address).isUnresolved())) {
407+
throw new UnresolvedAddressException();
438408
}
439409
}
440410

441411
@Override
442412
protected Object filterOutboundMessage(Object msg) {
443413
if (msg instanceof DatagramPacket) {
444414
DatagramPacket packet = (DatagramPacket) msg;
445-
checkEnvelope(packet);
415+
checkUnresolved(packet.recipient());
446416
ByteBuf content = packet.content();
447417
return UnixChannelUtil.isBufferCopyNeededForWrite(content) ?
448418
new DatagramPacket(newDirectBuffer(packet, content), packet.recipient()) : msg;
@@ -452,19 +422,8 @@ protected Object filterOutboundMessage(Object msg) {
452422
ByteBuf buf = (ByteBuf) msg;
453423
return UnixChannelUtil.isBufferCopyNeededForWrite(buf) ? newDirectBuffer(buf) : buf;
454424
}
455-
456-
if (msg instanceof AddressedEnvelope) {
457-
@SuppressWarnings("unchecked")
458-
AddressedEnvelope<Object, SocketAddress> e = (AddressedEnvelope<Object, SocketAddress>) msg;
459-
checkEnvelope(e);
460-
ByteBuf content = (ByteBuf) e.content();
461-
return UnixChannelUtil.isBufferCopyNeededForWrite(content) ?
462-
new DefaultAddressedEnvelope<>(
463-
newDirectBuffer(e, content), e.recipient()) : e;
464-
}
465425
throw new UnsupportedOperationException(
466-
"unsupported message type: " + StringUtil.simpleClassName(msg) +
467-
(socket.protocolFamily() == SocketProtocolFamily.UNIX ? EXPECTED_TYPES_UNIX : EXPECTED_TYPES));
426+
"unsupported message type: " + StringUtil.simpleClassName(msg) + EXPECTED_TYPES);
468427
}
469428

470429
@Override

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.