|
18 | 18 | import io.netty.buffer.ByteBuf; |
19 | 19 | import io.netty.buffer.ByteBufAllocator; |
20 | 20 | import io.netty.buffer.Unpooled; |
21 | | -import io.netty.channel.AddressedEnvelope; |
22 | 21 | import io.netty.channel.ChannelFuture; |
23 | 22 | import io.netty.channel.ChannelMetadata; |
24 | 23 | import io.netty.channel.ChannelOutboundBuffer; |
25 | 24 | import io.netty.channel.ChannelPipeline; |
26 | 25 | import io.netty.channel.ChannelPromise; |
27 | | -import io.netty.channel.DefaultAddressedEnvelope; |
28 | 26 | import io.netty.channel.EventLoop; |
29 | 27 | import io.netty.channel.socket.DatagramChannel; |
30 | 28 | import io.netty.channel.socket.DatagramPacket; |
31 | 29 | import io.netty.channel.socket.SocketProtocolFamily; |
32 | 30 | import io.netty.channel.unix.DomainDatagramSocketAddress; |
33 | | -import io.netty.channel.unix.DomainSocketAddress; |
34 | 31 | import io.netty.channel.unix.Errors; |
35 | 32 | import io.netty.channel.unix.Errors.NativeIoException; |
36 | 33 | import io.netty.channel.unix.UnixChannelUtil; |
@@ -67,19 +64,8 @@ public final class EpollDatagramChannel extends AbstractEpollChannel implements |
67 | 64 | private static final ChannelMetadata METADATA = new ChannelMetadata(true, 16); |
68 | 65 | private static final String EXPECTED_TYPES = |
69 | 66 | " (expected: " + StringUtil.simpleClassName(DatagramPacket.class) + ", " + |
70 | | - StringUtil.simpleClassName(AddressedEnvelope.class) + '<' + |
71 | | - StringUtil.simpleClassName(ByteBuf.class) + ", " + |
72 | | - StringUtil.simpleClassName(InetSocketAddress.class) + ">, " + |
73 | 67 | StringUtil.simpleClassName(ByteBuf.class) + ')'; |
74 | 68 |
|
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 | | - |
83 | 69 | private final EpollDatagramChannelConfig config; |
84 | 70 | private volatile boolean connected; |
85 | 71 |
|
@@ -461,12 +447,10 @@ protected void doWrite(ChannelOutboundBuffer in) throws Exception { |
461 | 447 | private boolean doWriteMessage(Object msg) throws Exception { |
462 | 448 | final ByteBuf data; |
463 | 449 | 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(); |
470 | 454 | } else { |
471 | 455 | data = (ByteBuf) msg; |
472 | 456 | remoteAddress = null; |
@@ -480,25 +464,10 @@ private boolean doWriteMessage(Object msg) throws Exception { |
480 | 464 | return doWriteOrSendBytes(data, remoteAddress, false) > 0; |
481 | 465 | } |
482 | 466 |
|
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(); |
502 | 471 | } |
503 | 472 | } |
504 | 473 |
|
@@ -510,15 +479,15 @@ protected Object filterOutboundMessage(Object msg) { |
510 | 479 | "unsupported message type: " + StringUtil.simpleClassName(msg) + EXPECTED_TYPES); |
511 | 480 | } |
512 | 481 | io.netty.channel.unix.SegmentedDatagramPacket packet = (io.netty.channel.unix.SegmentedDatagramPacket) msg; |
513 | | - checkEnvelope(packet); |
| 482 | + checkUnresolved(packet.recipient()); |
514 | 483 |
|
515 | 484 | ByteBuf content = packet.content(); |
516 | 485 | return UnixChannelUtil.isBufferCopyNeededForWrite(content) ? |
517 | 486 | packet.replace(newDirectBuffer(packet, content)) : msg; |
518 | 487 | } |
519 | 488 | if (msg instanceof DatagramPacket) { |
520 | 489 | DatagramPacket packet = (DatagramPacket) msg; |
521 | | - checkEnvelope(packet); |
| 490 | + checkUnresolved(packet.recipient()); |
522 | 491 | ByteBuf content = packet.content(); |
523 | 492 | return UnixChannelUtil.isBufferCopyNeededForWrite(content) ? |
524 | 493 | new DatagramPacket(newDirectBuffer(packet, content), packet.recipient()) : msg; |
@@ -528,20 +497,8 @@ protected Object filterOutboundMessage(Object msg) { |
528 | 497 | ByteBuf buf = (ByteBuf) msg; |
529 | 498 | return UnixChannelUtil.isBufferCopyNeededForWrite(buf)? newDirectBuffer(buf) : buf; |
530 | 499 | } |
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 | | - } |
542 | 500 | 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); |
545 | 502 | } |
546 | 503 |
|
547 | 504 | @Override |
|