- java.lang.Object
-
- io.netty5.util.DefaultAttributeMap
-
- io.netty5.channel.AbstractChannel<P,SocketAddress,SocketAddress>
-
- io.netty5.channel.epoll.EpollDatagramChannel
-
- All Implemented Interfaces:
Channel
,ChannelOutboundInvoker
,IoHandle
,DatagramChannel
,UnixChannel
,AttributeMap
,FuturePromiseFactory
,Comparable<Channel>
public final class EpollDatagramChannel extends AbstractChannel<P,SocketAddress,SocketAddress> implements DatagramChannel
DatagramChannel
implementation that uses linux EPOLL Edge-Triggered Mode for maximal performance.Available options
In addition to the options provided byDatagramChannel
andUnixChannel
,EpollDatagramChannel
allows the following options in the option map:ChannelOption
INET
INET6
{@code UNIX {@link IntegerUnixChannelOption} X X X {@link RawUnixChannelOption} X X X {@link UnixChannelOption#SO_REUSEPORT} X X X {@link EpollChannelOption#IP_FREEBIND} X X - {@link EpollChannelOption#IP_RECVORIGDSTADDR} X X - {@link EpollChannelOption#MAX_DATAGRAM_PAYLOAD_SIZE} X X - {@link EpollChannelOption#UDP_GRO} X X -
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.netty5.channel.AbstractChannel
AbstractChannel.DefaultAbstractChannelPipeline
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
active
protected LinuxSocket
socket
-
Constructor Summary
Constructors Constructor Description EpollDatagramChannel(EventLoop eventLoop)
Create a new instance which selects theProtocolFamily
to use depending on the Operation Systems default which will be chosen.EpollDatagramChannel(EventLoop eventLoop, int fd, ProtocolFamily family)
Create a new instance which selects theProtocolFamily
to use depending on the Operation Systems default which will be chosen.EpollDatagramChannel(EventLoop eventLoop, ProtocolFamily family)
Create a new instance using the givenProtocolFamily
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
autoReadCleared()
Is called onceAbstractChannel.setAutoRead(boolean)
is called withfalse
andAbstractChannel.isAutoRead()
wastrue
before.Future<Void>
block(InetAddress multicastAddress, InetAddress sourceToBlock)
Block the given sourceToBlock address for the given multicastAddress and notifies theFuture
once the operation completes.Future<Void>
block(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress sourceToBlock)
Block the given sourceToBlock address for the given multicastAddress on the given networkInterface and notifies theFuture
once the operation completes.protected static void
checkResolvable(InetSocketAddress addr)
protected void
clearFlag(int flag)
protected void
doBeginRead()
Schedule a read operation.protected void
doBind(SocketAddress localAddress)
Bind theChannel
to theSocketAddress
protected void
doClose()
Close theChannel
protected boolean
doConnect(SocketAddress remoteAddress, SocketAddress localAddress)
Connect to the remote peerprotected boolean
doConnect0(SocketAddress remote)
protected void
doDisconnect()
Disconnect thisChannel
from its remote peerprotected boolean
doFinishConnect(SocketAddress requestedRemoteAddress)
Finish a connect request.protected void
doReadBytes(Buffer buffer)
Read bytes into the givenBuffer
and return the amount.protected void
doShutdown(ChannelShutdownDirection direction)
Shutdown one direction of theChannel
.protected void
doWrite(ChannelOutboundBuffer in)
Flush the content of the given buffer to the remote peer.protected int
doWriteBytes(ChannelOutboundBuffer in, Buffer buf)
protected long
doWriteOrSendBytes(Buffer data, SocketAddress remoteAddress, boolean fastOpen)
Write bytes to the socket, with or without a remote address.protected void
epollInReady(RecvBufferAllocator.Handle handle, BufferAllocator recvBufferAllocator, boolean receivedRdHup)
Called once EPOLLIN event is ready to be processedFileDescriptor
fd()
Returns theFileDescriptor
that is used by thisChannel
.protected boolean
fetchLocalAddress()
protected Object
filterOutboundMessage(Object msg)
Invoked when a new message is added to aChannelOutboundBuffer
of thisAbstractChannel
, so that theChannel
implementation converts the message to another.protected <T> T
getExtendedOption(ChannelOption<T> option)
Override to add support for moreChannelOption
s.boolean
isActive()
Returntrue
if theChannel
is active and so connected.boolean
isConnected()
Returntrue
if theDatagramChannel
is connected to the remote peer.protected boolean
isExtendedOptionSupported(ChannelOption<?> option)
Override to add support for moreChannelOption
s.boolean
isOpen()
Returnstrue
if theChannel
is open and may get active laterstatic boolean
isSegmentedDatagramPacketSupported()
Returnstrue
ifSegmentedDatagramPacket
is supported natively.boolean
isShutdown(ChannelShutdownDirection direction)
protected static boolean
isSoErrorZero(Socket fd)
Future<Void>
joinGroup(InetAddress multicastAddress)
Joins a multicast group and notifies theFuture
once the operation completes.Future<Void>
joinGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source)
Joins the specified multicast group at the specified interface and notifies theFuture
once the operation completes.Future<Void>
leaveGroup(InetAddress multicastAddress)
Leaves a multicast group and notifies theFuture
once the operation completes.Future<Void>
leaveGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source)
Leave the specified multicast group at the specified interface using the specified source and notifies theFuture
once the operation completes.protected SocketAddress
localAddress0()
Returns theSocketAddress
which is bound locally.protected boolean
maybeMoreDataToRead(RecvBufferAllocator.Handle handle)
protected Buffer
newDirectBuffer(Buffer buf)
Returns an off-heap copy of, and then closes, the givenBuffer
.protected Buffer
newDirectBuffer(Resource<?> holder, Buffer buf)
Returns an off-heap copy of the givenBuffer
, and then closes theholder
under the assumption that it owned (or was itself) the buffer.protected io.netty5.channel.epoll.EpollRegistration
registration()
protected SocketAddress
remoteAddress0()
Return theSocketAddress
which theChannel
is connected to.protected <T> void
setExtendedOption(ChannelOption<T> option, T value)
Override to add support for moreChannelOption
s.protected void
setFlag(int flag)
protected void
shutdownInput(boolean rdHup)
Shutdown the input side of the channel.protected void
writeFlushed()
Write previous flushed messages.-
Methods inherited from class io.netty5.channel.AbstractChannel
annotateConnectException, assertEventLoop, bufferAllocator, cacheAddresses, closeForciblyTransport, closeFuture, closeIfClosed, closeTransport, compareTo, deregisterTransport, ensureOpen, equals, executor, finishConnect, fireChannelActiveIfNotActiveBefore, getMaxMessagesPerWrite, getOption, getWriteSpinCount, handleWriteError, hashCode, id, isAllowHalfClosure, isAutoRead, isConnectPending, isOptionSupported, isRegistered, localAddress, metadata, newChannelPipeline, newSupportedIdentityOptionsSet, outboundBuffer, parent, pipeline, prepareToClose, readIfIsAutoRead, recvBufAllocHandle, remoteAddress, runAfterTransportAction, safeSetFailure, safeSetSuccess, setBufferAllocator, setOption, shutdownTransport, toString, validate, validateEventLoopGroup, validateFileRegion, writableBytes
-
Methods inherited from class io.netty5.util.DefaultAttributeMap
attr, hasAttr
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.netty5.util.AttributeMap
attr, hasAttr
-
Methods inherited from interface io.netty5.channel.Channel
bind, bufferAllocator, close, closeFuture, connect, connect, deregister, disconnect, executor, flush, getOption, id, isOpen, isOptionSupported, isWritable, localAddress, metadata, parent, pipeline, read, register, remoteAddress, sendOutboundEvent, setOption, shutdown, writableBytes, write, writeAndFlush
-
Methods inherited from interface io.netty5.channel.ChannelOutboundInvoker
newFailedFuture, newPromise, newSucceededFuture, newSucceededFuture
-
Methods inherited from interface java.lang.Comparable
compareTo
-
Methods inherited from interface io.netty5.channel.IoHandle
isRegistered
-
-
-
-
Field Detail
-
socket
protected final LinuxSocket socket
-
active
protected volatile boolean active
-
-
Constructor Detail
-
EpollDatagramChannel
public EpollDatagramChannel(EventLoop eventLoop)
Create a new instance which selects theProtocolFamily
to use depending on the Operation Systems default which will be chosen.
-
EpollDatagramChannel
public EpollDatagramChannel(EventLoop eventLoop, ProtocolFamily family)
Create a new instance using the givenProtocolFamily
. Ifnull
is used it will depend on the Operation Systems default which will be chosen.
-
EpollDatagramChannel
public EpollDatagramChannel(EventLoop eventLoop, int fd, ProtocolFamily family)
Create a new instance which selects theProtocolFamily
to use depending on the Operation Systems default which will be chosen.
-
-
Method Detail
-
isSegmentedDatagramPacketSupported
public static boolean isSegmentedDatagramPacketSupported()
Returnstrue
ifSegmentedDatagramPacket
is supported natively.- Returns:
true
if supported,false
otherwise.
-
isActive
public boolean isActive()
Description copied from interface:Channel
Returntrue
if theChannel
is active and so connected.
-
isConnected
public boolean isConnected()
Description copied from interface:DatagramChannel
Returntrue
if theDatagramChannel
is connected to the remote peer.- Specified by:
isConnected
in interfaceDatagramChannel
-
joinGroup
public Future<Void> joinGroup(InetAddress multicastAddress)
Description copied from interface:DatagramChannel
Joins a multicast group and notifies theFuture
once the operation completes.If the underlying implementation does not support this operation it will return a
Future
which is failed with anUnsupportedOperationException
.- Specified by:
joinGroup
in interfaceDatagramChannel
- Parameters:
multicastAddress
- the multicast group address.- Returns:
- a
Future
which is notified once the operation completes.
-
joinGroup
public Future<Void> joinGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source)
Description copied from interface:DatagramChannel
Joins the specified multicast group at the specified interface and notifies theFuture
once the operation completes.If the underlying implementation does not support this operation it will return a
Future
which is failed with anUnsupportedOperationException
.- Specified by:
joinGroup
in interfaceDatagramChannel
- Parameters:
multicastAddress
- the multicast group address.networkInterface
- the interface to use.source
- the source address (might benull
).- Returns:
- a
Future
which is notified once the operation completes.
-
leaveGroup
public Future<Void> leaveGroup(InetAddress multicastAddress)
Description copied from interface:DatagramChannel
Leaves a multicast group and notifies theFuture
once the operation completes.If the underlying implementation does not support this operation it will return a
Future
which is failed with anUnsupportedOperationException
.- Specified by:
leaveGroup
in interfaceDatagramChannel
- Parameters:
multicastAddress
- the multicast group address.- Returns:
- a
Future
which is notified once the operation completes.
-
leaveGroup
public Future<Void> leaveGroup(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress source)
Description copied from interface:DatagramChannel
Leave the specified multicast group at the specified interface using the specified source and notifies theFuture
once the operation completes.If the underlying implementation does not support this operation it will return a
Future
which is failed with anUnsupportedOperationException
.- Specified by:
leaveGroup
in interfaceDatagramChannel
- Parameters:
multicastAddress
- the multicast group address.networkInterface
- the interface to use.source
- the source address (might benull
).- Returns:
- a
Future
which is notified once the operation completes.
-
block
public Future<Void> block(InetAddress multicastAddress, NetworkInterface networkInterface, InetAddress sourceToBlock)
Description copied from interface:DatagramChannel
Block the given sourceToBlock address for the given multicastAddress on the given networkInterface and notifies theFuture
once the operation completes.If the underlying implementation does not support this operation it will return a
Future
which is failed with anUnsupportedOperationException
.- Specified by:
block
in interfaceDatagramChannel
- Parameters:
multicastAddress
- the multicast group address.networkInterface
- the interface to use.sourceToBlock
- the source address.- Returns:
- a
Future
which is notified once the operation completes.
-
block
public Future<Void> block(InetAddress multicastAddress, InetAddress sourceToBlock)
Description copied from interface:DatagramChannel
Block the given sourceToBlock address for the given multicastAddress and notifies theFuture
once the operation completes.If the underlying implementation does not support this operation it will return a
Future
which is failed with anUnsupportedOperationException
.- Specified by:
block
in interfaceDatagramChannel
- Parameters:
multicastAddress
- the multicast group address.sourceToBlock
- the source address.- Returns:
- a
Future
which is notified once the operation completes.
-
doShutdown
protected void doShutdown(ChannelShutdownDirection direction)
Description copied from class:AbstractChannel
Shutdown one direction of theChannel
.- Specified by:
doShutdown
in classAbstractChannel<UnixChannel,SocketAddress,SocketAddress>
- Parameters:
direction
- the direction to shutdown.
-
isShutdown
public boolean isShutdown(ChannelShutdownDirection direction)
Description copied from interface:Channel
- Specified by:
isShutdown
in interfaceChannel
-
doBind
protected void doBind(SocketAddress localAddress) throws Exception
Description copied from class:AbstractChannel
Bind theChannel
to theSocketAddress
- Throws:
Exception
-
doWrite
protected void doWrite(ChannelOutboundBuffer in) throws Exception
Description copied from class:AbstractChannel
Flush the content of the given buffer to the remote peer.- Specified by:
doWrite
in classAbstractChannel<UnixChannel,SocketAddress,SocketAddress>
- Throws:
Exception
-
filterOutboundMessage
protected Object filterOutboundMessage(Object msg)
Description copied from class:AbstractChannel
Invoked when a new message is added to aChannelOutboundBuffer
of thisAbstractChannel
, so that theChannel
implementation converts the message to another. (e.g. heap buffer -> direct buffer)- Overrides:
filterOutboundMessage
in classAbstractChannel<UnixChannel,SocketAddress,SocketAddress>
-
doDisconnect
protected void doDisconnect() throws Exception
Description copied from class:AbstractChannel
Disconnect thisChannel
from its remote peer- Throws:
Exception
-
doConnect
protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception
Connect to the remote peer- Parameters:
remoteAddress
- the address of the remote peer.localAddress
- the local address of this channel.- Returns:
true
if the connect was completed,false
ifAbstractChannel.finishConnect()
will be called later again to try finishing the connect.- Throws:
Exception
- thrown on error.
-
doClose
protected void doClose() throws Exception
Description copied from class:AbstractChannel
Close theChannel
- Throws:
Exception
-
epollInReady
protected void epollInReady(RecvBufferAllocator.Handle handle, BufferAllocator recvBufferAllocator, boolean receivedRdHup)
Called once EPOLLIN event is ready to be processed
-
maybeMoreDataToRead
protected boolean maybeMoreDataToRead(RecvBufferAllocator.Handle handle)
-
getExtendedOption
protected <T> T getExtendedOption(ChannelOption<T> option)
Description copied from class:AbstractChannel
Override to add support for moreChannelOption
s. You need to also call {@link super} after handling the extra options.- Type Parameters:
T
- the value type.- Parameters:
option
- theChannelOption
.- Returns:
- the value for the option
-
setExtendedOption
protected <T> void setExtendedOption(ChannelOption<T> option, T value)
Description copied from class:AbstractChannel
Override to add support for moreChannelOption
s. You need to also call {@link super} after handling the extra options.- Type Parameters:
T
- the value type.- Parameters:
option
- theChannelOption
.
-
isExtendedOptionSupported
protected boolean isExtendedOptionSupported(ChannelOption<?> option)
Description copied from class:AbstractChannel
Override to add support for moreChannelOption
s. You need to also call {@link super} after handling the extra options.- Parameters:
option
- theChannelOption
.- Returns:
true
if supported,false
otherwise.
-
fetchLocalAddress
protected final boolean fetchLocalAddress()
-
isSoErrorZero
protected static boolean isSoErrorZero(Socket fd)
-
setFlag
protected final void setFlag(int flag) throws IOException
- Throws:
IOException
-
clearFlag
protected final void clearFlag(int flag) throws IOException
- Throws:
IOException
-
registration
protected final io.netty5.channel.epoll.EpollRegistration registration()
-
fd
public final FileDescriptor fd()
Description copied from interface:UnixChannel
Returns theFileDescriptor
that is used by thisChannel
.- Specified by:
fd
in interfaceUnixChannel
-
isOpen
public final boolean isOpen()
Description copied from interface:Channel
Returnstrue
if theChannel
is open and may get active later
-
doBeginRead
protected final void doBeginRead() throws Exception
Description copied from class:AbstractChannel
Schedule a read operation.- Specified by:
doBeginRead
in classAbstractChannel<P extends UnixChannel,SocketAddress,SocketAddress>
- Throws:
Exception
-
newDirectBuffer
protected final Buffer newDirectBuffer(Buffer buf)
Returns an off-heap copy of, and then closes, the givenBuffer
.
-
newDirectBuffer
protected final Buffer newDirectBuffer(Resource<?> holder, Buffer buf)
Returns an off-heap copy of the givenBuffer
, and then closes theholder
under the assumption that it owned (or was itself) the buffer.
-
checkResolvable
protected static void checkResolvable(InetSocketAddress addr)
-
doReadBytes
protected final void doReadBytes(Buffer buffer) throws Exception
Read bytes into the givenBuffer
and return the amount.- Throws:
Exception
-
doWriteBytes
protected final int doWriteBytes(ChannelOutboundBuffer in, Buffer buf) throws Exception
- Throws:
Exception
-
doWriteOrSendBytes
protected final long doWriteOrSendBytes(Buffer data, SocketAddress remoteAddress, boolean fastOpen) throws IOException
Write bytes to the socket, with or without a remote address. Used for datagram and TCP client fast open writes.- Throws:
IOException
-
shutdownInput
protected final void shutdownInput(boolean rdHup)
Shutdown the input side of the channel.
-
writeFlushed
protected final void writeFlushed()
Description copied from class:AbstractChannel
Write previous flushed messages.- Overrides:
writeFlushed
in classAbstractChannel<P extends UnixChannel,SocketAddress,SocketAddress>
-
doFinishConnect
protected boolean doFinishConnect(SocketAddress requestedRemoteAddress) throws Exception
Description copied from class:AbstractChannel
Finish a connect request.- Specified by:
doFinishConnect
in classAbstractChannel<P extends UnixChannel,SocketAddress,SocketAddress>
- Parameters:
requestedRemoteAddress
- the remote address of the peer.- Returns:
true
if the connect was completed,false
ifAbstractChannel.finishConnect()
will be called later again to try finishing the connect.- Throws:
Exception
- thrown on error.
-
doConnect0
protected boolean doConnect0(SocketAddress remote) throws Exception
- Throws:
Exception
-
localAddress0
protected final SocketAddress localAddress0()
Description copied from class:AbstractChannel
Returns theSocketAddress
which is bound locally.- Specified by:
localAddress0
in classAbstractChannel<P extends UnixChannel,SocketAddress,SocketAddress>
-
remoteAddress0
protected final SocketAddress remoteAddress0()
Description copied from class:AbstractChannel
Return theSocketAddress
which theChannel
is connected to.- Specified by:
remoteAddress0
in classAbstractChannel<P extends UnixChannel,SocketAddress,SocketAddress>
-
autoReadCleared
protected final void autoReadCleared()
Description copied from class:AbstractChannel
Is called onceAbstractChannel.setAutoRead(boolean)
is called withfalse
andAbstractChannel.isAutoRead()
wastrue
before.- Overrides:
autoReadCleared
in classAbstractChannel<P extends UnixChannel,SocketAddress,SocketAddress>
-
-