Search in sources :

Example 1 with DomainDatagramPacket

use of io.netty.channel.unix.DomainDatagramPacket in project netty by netty.

the class EpollDomainDatagramChannel method filterOutboundMessage.

@Override
protected Object filterOutboundMessage(Object msg) {
    if (msg instanceof DomainDatagramPacket) {
        DomainDatagramPacket packet = (DomainDatagramPacket) msg;
        ByteBuf content = packet.content();
        return UnixChannelUtil.isBufferCopyNeededForWrite(content) ? new DomainDatagramPacket(newDirectBuffer(packet, content), packet.recipient()) : msg;
    }
    if (msg instanceof ByteBuf) {
        ByteBuf buf = (ByteBuf) msg;
        return UnixChannelUtil.isBufferCopyNeededForWrite(buf) ? newDirectBuffer(buf) : buf;
    }
    if (msg instanceof AddressedEnvelope) {
        @SuppressWarnings("unchecked") AddressedEnvelope<Object, SocketAddress> e = (AddressedEnvelope<Object, SocketAddress>) msg;
        if (e.content() instanceof ByteBuf && (e.recipient() == null || e.recipient() instanceof DomainSocketAddress)) {
            ByteBuf content = (ByteBuf) e.content();
            return UnixChannelUtil.isBufferCopyNeededForWrite(content) ? new DefaultAddressedEnvelope<ByteBuf, DomainSocketAddress>(newDirectBuffer(e, content), (DomainSocketAddress) e.recipient()) : e;
        }
    }
    throw new UnsupportedOperationException("unsupported message type: " + StringUtil.simpleClassName(msg) + EXPECTED_TYPES);
}
Also used : DefaultAddressedEnvelope(io.netty.channel.DefaultAddressedEnvelope) AddressedEnvelope(io.netty.channel.AddressedEnvelope) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) DomainDatagramPacket(io.netty.channel.unix.DomainDatagramPacket) ByteBuf(io.netty.buffer.ByteBuf) DomainDatagramSocketAddress(io.netty.channel.unix.DomainDatagramSocketAddress) SocketAddress(java.net.SocketAddress) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress)

Example 2 with DomainDatagramPacket

use of io.netty.channel.unix.DomainDatagramPacket in project netty by netty.

the class KQueueDomainDatagramChannel method filterOutboundMessage.

@Override
protected Object filterOutboundMessage(Object msg) {
    if (msg instanceof DomainDatagramPacket) {
        DomainDatagramPacket packet = (DomainDatagramPacket) msg;
        ByteBuf content = packet.content();
        return UnixChannelUtil.isBufferCopyNeededForWrite(content) ? new DomainDatagramPacket(newDirectBuffer(packet, content), packet.recipient()) : msg;
    }
    if (msg instanceof ByteBuf) {
        ByteBuf buf = (ByteBuf) msg;
        return UnixChannelUtil.isBufferCopyNeededForWrite(buf) ? newDirectBuffer(buf) : buf;
    }
    if (msg instanceof AddressedEnvelope) {
        @SuppressWarnings("unchecked") AddressedEnvelope<Object, SocketAddress> e = (AddressedEnvelope<Object, SocketAddress>) msg;
        if (e.content() instanceof ByteBuf && (e.recipient() == null || e.recipient() instanceof DomainSocketAddress)) {
            ByteBuf content = (ByteBuf) e.content();
            return UnixChannelUtil.isBufferCopyNeededForWrite(content) ? new DefaultAddressedEnvelope<ByteBuf, DomainSocketAddress>(newDirectBuffer(e, content), (DomainSocketAddress) e.recipient()) : e;
        }
    }
    throw new UnsupportedOperationException("unsupported message type: " + StringUtil.simpleClassName(msg) + EXPECTED_TYPES);
}
Also used : DefaultAddressedEnvelope(io.netty.channel.DefaultAddressedEnvelope) AddressedEnvelope(io.netty.channel.AddressedEnvelope) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress) DomainDatagramPacket(io.netty.channel.unix.DomainDatagramPacket) ByteBuf(io.netty.buffer.ByteBuf) DomainDatagramSocketAddress(io.netty.channel.unix.DomainDatagramSocketAddress) SocketAddress(java.net.SocketAddress) DomainSocketAddress(io.netty.channel.unix.DomainSocketAddress)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)2 AddressedEnvelope (io.netty.channel.AddressedEnvelope)2 DefaultAddressedEnvelope (io.netty.channel.DefaultAddressedEnvelope)2 DomainDatagramPacket (io.netty.channel.unix.DomainDatagramPacket)2 DomainDatagramSocketAddress (io.netty.channel.unix.DomainDatagramSocketAddress)2 DomainSocketAddress (io.netty.channel.unix.DomainSocketAddress)2 SocketAddress (java.net.SocketAddress)2