- java.lang.Object
-
- io.netty5.util.DefaultAttributeMap
-
- io.netty5.channel.AbstractChannel<P,SocketAddress,SocketAddress>
-
- io.netty5.channel.epoll.EpollSocketChannel
-
- All Implemented Interfaces:
Channel,ChannelOutboundInvoker,IoHandle,SocketChannel,UnixChannel,AttributeMap,FuturePromiseFactory,Comparable<Channel>
public final class EpollSocketChannel extends AbstractChannel<P,SocketAddress,SocketAddress> implements SocketChannel
SocketChannelimplementation that uses linux EPOLL Edge-Triggered Mode for maximal performance.Available options
In addition to the options provided bySocketChannelandUnixChannel,EpollSocketChannelallows the following options in the option map:
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.netty5.channel.AbstractChannel
AbstractChannel.DefaultAbstractChannelPipeline
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanactiveprotected LinuxSocketsocket
-
Constructor Summary
Constructors Constructor Description EpollSocketChannel(EventLoop eventLoop)EpollSocketChannel(EventLoop eventLoop, int fd, ProtocolFamily family)EpollSocketChannel(EventLoop eventLoop, ProtocolFamily protocolFamily)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidautoReadCleared()Is called onceAbstractChannel.setAutoRead(boolean)is called withfalseandAbstractChannel.isAutoRead()wastruebefore.protected static voidcheckResolvable(InetSocketAddress addr)protected voidclearFlag(int flag)protected voiddoBeginRead()Schedule a read operation.protected voiddoBind(SocketAddress local)Bind theChannelto theSocketAddressprotected voiddoClose()Close theChannelprotected booleandoConnect(SocketAddress remoteAddress, SocketAddress localAddress)Connect to the remote peerprotected booleandoConnect0(SocketAddress remote)protected voiddoDisconnect()Disconnect thisChannelfrom its remote peerprotected booleandoFinishConnect(SocketAddress requestedRemoteAddress)Finish a connect request.protected voiddoReadBytes(Buffer buffer)Read bytes into the givenBufferand return the amount.protected voiddoShutdown(ChannelShutdownDirection direction)Shutdown one direction of theChannel.protected voiddoWrite(ChannelOutboundBuffer in)Flush the content of the given buffer to the remote peer.protected intdoWriteBytes(ChannelOutboundBuffer in, Buffer buf)protected longdoWriteOrSendBytes(Buffer data, SocketAddress remoteAddress, boolean fastOpen)Write bytes to the socket, with or without a remote address.protected voidepollInReady(RecvBufferAllocator.Handle handle, BufferAllocator recvBufferAllocator, boolean receivedRdHup)Called once EPOLLIN event is ready to be processedFileDescriptorfd()Returns theFileDescriptorthat is used by thisChannel.protected booleanfetchLocalAddress()protected ObjectfilterOutboundMessage(Object msg)Invoked when a new message is added to aChannelOutboundBufferof thisAbstractChannel, so that theChannelimplementation converts the message to another.protected <T> TgetExtendedOption(ChannelOption<T> option)Override to add support for moreChannelOptions.booleanisActive()Returntrueif theChannelis active and so connected.protected booleanisExtendedOptionSupported(ChannelOption<?> option)Override to add support for moreChannelOptions.booleanisIpTransparent()booleanisOpen()Returnstrueif theChannelis open and may get active laterbooleanisShutdown(ChannelShutdownDirection direction)protected static booleanisSoErrorZero(Socket fd)protected SocketAddresslocalAddress0()Returns theSocketAddresswhich is bound locally.protected booleanmaybeMoreDataToRead(RecvBufferAllocator.Handle handle)protected BuffernewDirectBuffer(Buffer buf)Returns an off-heap copy of, and then closes, the givenBuffer.protected BuffernewDirectBuffer(Resource<?> holder, Buffer buf)Returns an off-heap copy of the givenBuffer, and then closes theholderunder the assumption that it owned (or was itself) the buffer.protected Future<Executor>prepareToClose()Prepares to close theChannel.protected io.netty5.channel.epoll.EpollRegistrationregistration()protected SocketAddressremoteAddress0()Return theSocketAddresswhich theChannelis connected to.protected <T> voidsetExtendedOption(ChannelOption<T> option, T value)Override to add support for moreChannelOptions.protected voidsetFlag(int flag)protected voidshutdownInput(boolean rdHup)Shutdown the input side of the channel.protected voidwriteFlushed()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, 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, isActive, isOpen, isOptionSupported, isWritable, localAddress, metadata, 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
-
Methods inherited from interface io.netty5.channel.socket.SocketChannel
parent
-
-
-
-
Field Detail
-
socket
protected final LinuxSocket socket
-
active
protected volatile boolean active
-
-
Constructor Detail
-
EpollSocketChannel
public EpollSocketChannel(EventLoop eventLoop)
-
EpollSocketChannel
public EpollSocketChannel(EventLoop eventLoop, ProtocolFamily protocolFamily)
-
EpollSocketChannel
public EpollSocketChannel(EventLoop eventLoop, int fd, ProtocolFamily family)
-
-
Method Detail
-
doWrite
protected void doWrite(ChannelOutboundBuffer in) throws Exception
Description copied from class:AbstractChannelFlush the content of the given buffer to the remote peer.- Specified by:
doWritein classAbstractChannel<EpollServerSocketChannel,SocketAddress,SocketAddress>- Throws:
Exception
-
filterOutboundMessage
protected Object filterOutboundMessage(Object msg)
Description copied from class:AbstractChannelInvoked when a new message is added to aChannelOutboundBufferof thisAbstractChannel, so that theChannelimplementation converts the message to another. (e.g. heap buffer -> direct buffer)- Overrides:
filterOutboundMessagein classAbstractChannel<EpollServerSocketChannel,SocketAddress,SocketAddress>
-
doShutdown
protected void doShutdown(ChannelShutdownDirection direction) throws Exception
Description copied from class:AbstractChannelShutdown one direction of theChannel.- Specified by:
doShutdownin classAbstractChannel<EpollServerSocketChannel,SocketAddress,SocketAddress>- Parameters:
direction- the direction to shutdown.- Throws:
Exception- thrown on error.
-
isShutdown
public boolean isShutdown(ChannelShutdownDirection direction)
Description copied from interface:Channel- Specified by:
isShutdownin interfaceChannel
-
epollInReady
protected void epollInReady(RecvBufferAllocator.Handle handle, BufferAllocator recvBufferAllocator, boolean receivedRdHup)
Called once EPOLLIN event is ready to be processed
-
getExtendedOption
protected <T> T getExtendedOption(ChannelOption<T> option)
Description copied from class:AbstractChannelOverride to add support for moreChannelOptions. 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:AbstractChannelOverride to add support for moreChannelOptions. 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:AbstractChannelOverride to add support for moreChannelOptions. You need to also call {@link super} after handling the extra options.- Parameters:
option- theChannelOption.- Returns:
trueif supported,falseotherwise.
-
isIpTransparent
public boolean isIpTransparent()
-
doConnect0
protected boolean doConnect0(SocketAddress remote) throws Exception
- Throws:
Exception
-
prepareToClose
protected Future<Executor> prepareToClose()
Description copied from class:AbstractChannelPrepares to close theChannel. If this method returns anExecutor, the caller must call theExecutor.execute(Runnable)method with a task that callsAbstractChannel.doClose()on the returnedExecutor. If this method returnsnull,AbstractChannel.doClose()must be called from the caller thread. (i.e.EventLoop)- Overrides:
prepareToClosein classAbstractChannel<EpollServerSocketChannel,SocketAddress,SocketAddress>
-
maybeMoreDataToRead
protected boolean maybeMoreDataToRead(RecvBufferAllocator.Handle handle)
-
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:UnixChannelReturns theFileDescriptorthat is used by thisChannel.- Specified by:
fdin interfaceUnixChannel
-
isActive
public boolean isActive()
Description copied from interface:ChannelReturntrueif theChannelis active and so connected.
-
doClose
protected void doClose() throws ExceptionDescription copied from class:AbstractChannelClose theChannel- Specified by:
doClosein classAbstractChannel<P extends UnixChannel,SocketAddress,SocketAddress>- Throws:
Exception
-
doDisconnect
protected void doDisconnect() throws ExceptionDescription copied from class:AbstractChannelDisconnect thisChannelfrom its remote peer- Specified by:
doDisconnectin classAbstractChannel<P extends UnixChannel,SocketAddress,SocketAddress>- Throws:
Exception
-
isOpen
public final boolean isOpen()
Description copied from interface:ChannelReturnstrueif theChannelis open and may get active later
-
doBeginRead
protected final void doBeginRead() throws ExceptionDescription copied from class:AbstractChannelSchedule a read operation.- Specified by:
doBeginReadin 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 theholderunder 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 givenBufferand 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:AbstractChannelWrite previous flushed messages.- Overrides:
writeFlushedin classAbstractChannel<P extends UnixChannel,SocketAddress,SocketAddress>
-
doFinishConnect
protected boolean doFinishConnect(SocketAddress requestedRemoteAddress) throws Exception
Description copied from class:AbstractChannelFinish a connect request.- Specified by:
doFinishConnectin classAbstractChannel<P extends UnixChannel,SocketAddress,SocketAddress>- Parameters:
requestedRemoteAddress- the remote address of the peer.- Returns:
trueif the connect was completed,falseifAbstractChannel.finishConnect()will be called later again to try finishing the connect.- Throws:
Exception- thrown on error.
-
doBind
protected void doBind(SocketAddress local) throws Exception
Description copied from class:AbstractChannelBind theChannelto theSocketAddress- Specified by:
doBindin classAbstractChannel<P extends UnixChannel,SocketAddress,SocketAddress>- Throws:
Exception
-
doConnect
protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception
Connect to the remote peer- Specified by:
doConnectin classAbstractChannel<P extends UnixChannel,SocketAddress,SocketAddress>- Parameters:
remoteAddress- the address of the remote peer.localAddress- the local address of this channel.- Returns:
trueif the connect was completed,falseifAbstractChannel.finishConnect()will be called later again to try finishing the connect.- Throws:
Exception- thrown on error.
-
localAddress0
protected final SocketAddress localAddress0()
Description copied from class:AbstractChannelReturns theSocketAddresswhich is bound locally.- Specified by:
localAddress0in classAbstractChannel<P extends UnixChannel,SocketAddress,SocketAddress>
-
remoteAddress0
protected final SocketAddress remoteAddress0()
Description copied from class:AbstractChannelReturn theSocketAddresswhich theChannelis connected to.- Specified by:
remoteAddress0in classAbstractChannel<P extends UnixChannel,SocketAddress,SocketAddress>
-
autoReadCleared
protected final void autoReadCleared()
Description copied from class:AbstractChannelIs called onceAbstractChannel.setAutoRead(boolean)is called withfalseandAbstractChannel.isAutoRead()wastruebefore.- Overrides:
autoReadClearedin classAbstractChannel<P extends UnixChannel,SocketAddress,SocketAddress>
-
-