Top Description Inners Fields Constructors Methods
io.netty.channel.socket.nio

public Class NioSocketChannel

extends AbstractNioByteChannel
implements SocketChannel
Class Inheritance
All Implemented Interfaces
io.netty.channel.socket.SocketChannel, io.netty.channel.socket.DuplexChannel, io.netty.channel.Channel, java.lang.Comparable, io.netty.channel.ChannelOutboundInvoker, io.netty.util.AttributeMap
Imports
io.netty.buffer.ByteBuf, io.netty.channel.Channel, .ChannelException, .ChannelFuture, .ChannelFutureListener, .ChannelOption, .ChannelOutboundBuffer, .ChannelPromise, .EventLoop, .FileRegion, .RecvByteBufAllocator, io.netty.channel.nio.AbstractNioByteChannel, io.netty.channel.socket.DefaultSocketChannelConfig, .InternetProtocolFamily, .ServerSocketChannel, .SocketChannelConfig, io.netty.util.concurrent.GlobalEventExecutor, io.netty.util.internal.PlatformDependent, .SocketUtils, .SuppressJava6Requirement, .UnstableApi, io.netty.util.internal.logging.InternalLogger, .InternalLoggerFactory, java.io.IOException, java.lang.reflect.Method, java.net.InetSocketAddress, .Socket, .SocketAddress, java.nio.ByteBuffer, java.nio.channels.SelectionKey, .SocketChannel, java.nio.channels.spi.SelectorProvider, java.util.Map, java.util.concurrent.Executor

io.netty.channel.socket.SocketChannel which uses NIO selector based implementation.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
private final SocketChannelConfig
private static final SelectorProvider
private static final InternalLogger
private static final Method

Constructor Summary

AccessConstructor and Description
public
NioSocketChannel()

Create a new instance

public
NioSocketChannel(SelectorProvider provider)

Create a new instance using the given SelectorProvider.

public
NioSocketChannel(SelectorProvider provider, InternetProtocolFamily family)

Create a new instance using the given SelectorProvider and protocol family (supported only since JDK 15).

public
NioSocketChannel(SocketChannel socket)

Create a new instance using the given SocketChannel.

public
NioSocketChannel(Channel
the Channel which created this instance or null if it was created by the user
parent
,
SocketChannel
the SocketChannel which will be used
socket
)

Create a new instance

Method Summary

Modifier and TypeMethod and Description
private void
adjustMaxBytesPerGatheringWrite(int attempted, int written, int oldMaxBytesPerGatheringWrite)

public SocketChannelConfig
config()

Implements io.netty.channel.socket.SocketChannel.config, io.netty.channel.Channel.config.

Returns the configuration of this channel.
protected void
doBind(SocketAddress localAddress)

Implements abstract io.netty.channel.AbstractChannel.doBind.

Bind the Channel to the SocketAddress
private void
doBind0(SocketAddress localAddress)

protected void
protected boolean
doConnect(SocketAddress remoteAddress, SocketAddress localAddress)

Implements abstract io.netty.channel.nio.AbstractNioChannel.doConnect.

Connect to the remote peer
protected void
doDisconnect()

Implements abstract io.netty.channel.AbstractChannel.doDisconnect.

Disconnect this Channel from its remote peer
protected void
protected int
doReadBytes(ByteBuf byteBuf)

Implements abstract io.netty.channel.nio.AbstractNioByteChannel.doReadBytes.

Read bytes into the given ByteBuf and return the amount.
protected final void
doShutdownOutput()

Overrides io.netty.channel.AbstractChannel.doShutdownOutput.

Called when conditions justify shutting down the output portion of the channel.
protected void
doWrite(ChannelOutboundBuffer in)

Overrides io.netty.channel.nio.AbstractNioByteChannel.doWrite.

Flush the content of the given buffer to the remote peer.
protected int
doWriteBytes(ByteBuf
the ByteBuf from which the bytes should be written
buf
)

Implements abstract io.netty.channel.nio.AbstractNioByteChannel.doWriteBytes.

Write bytes form the given ByteBuf to the underlying java.nio.channels.Channel.
protected long
doWriteFileRegion(FileRegion
the FileRegion from which the bytes should be written
region
)

Implements abstract io.netty.channel.nio.AbstractNioByteChannel.doWriteFileRegion.

Write a FileRegion
public boolean
isActive()

Implements io.netty.channel.Channel.isActive.

Return true if the Channel is active and so connected.
public boolean
isInputShutdown()

Implements io.netty.channel.socket.DuplexChannel.isInputShutdown.

Returns true if and only if the remote peer shut down its output so that no more data is received from this channel.
protected boolean
public boolean
public boolean
isShutdown()

Implements io.netty.channel.socket.DuplexChannel.isShutdown.

Determine if both the input and output of this channel have been shutdown.
protected SocketChannel
public InetSocketAddress
protected SocketAddress
localAddress0()

Implements abstract io.netty.channel.AbstractChannel.localAddress0.

Returns the SocketAddress which is bound locally.
private static SocketChannel
protected AbstractNioChannel.AbstractNioUnsafe
newUnsafe()

Overrides io.netty.channel.nio.AbstractNioByteChannel.newUnsafe.

Create a new AbstractUnsafe instance which will be used for the life-time of the Channel
public ServerSocketChannel
public InetSocketAddress
protected SocketAddress
remoteAddress0()

Implements abstract io.netty.channel.AbstractChannel.remoteAddress0.

Return the SocketAddress which the Channel is connected to.
public ChannelFuture
shutdown()

Implements io.netty.channel.socket.DuplexChannel.shutdown.

Will shutdown the input and output sides of this channel.
public ChannelFuture
shutdown(final ChannelPromise
will be completed when both shutdown operations complete.
promise
)

Implements io.netty.channel.socket.DuplexChannel.shutdown.

Will shutdown the input and output sides of this channel.
private static void
shutdownDone(ChannelFuture shutdownOutputFuture, ChannelFuture shutdownInputFuture, ChannelPromise promise)

public ChannelFuture
public ChannelFuture
shutdownInput(final ChannelPromise promise)

Implements io.netty.channel.socket.DuplexChannel.shutdownInput.

Will shutdown the input and notify ChannelPromise.
private void
private void
public ChannelFuture
public ChannelFuture
shutdownOutput(final ChannelPromise promise)

Implements io.netty.channel.socket.DuplexChannel.shutdownOutput.

Will shutdown the output and notify ChannelPromise.
private void
shutdownOutputDone(final ChannelFuture shutdownOutputFuture, final ChannelPromise promise)

Inherited from io.netty.channel.nio.AbstractNioByteChannel:
clearOpWritedoWrite0filterOutboundMessageincompleteWritemetadatasetOpWrite

Field Detail

configback to summary
private final SocketChannelConfig config
DEFAULT_SELECTOR_PROVIDERback to summary
private static final SelectorProvider DEFAULT_SELECTOR_PROVIDER
loggerback to summary
private static final InternalLogger logger

Hides io.netty.channel.nio.AbstractNioChannel.logger.

OPEN_SOCKET_CHANNEL_WITH_FAMILYback to summary
private static final Method OPEN_SOCKET_CHANNEL_WITH_FAMILY

Constructor Detail

NioSocketChannelback to summary
public NioSocketChannel()

Create a new instance

NioSocketChannelback to summary
public NioSocketChannel(SelectorProvider provider)

Create a new instance using the given SelectorProvider.

NioSocketChannelback to summary
public NioSocketChannel(SelectorProvider provider, InternetProtocolFamily family)

Create a new instance using the given SelectorProvider and protocol family (supported only since JDK 15).

NioSocketChannelback to summary
public NioSocketChannel(SocketChannel socket)

Create a new instance using the given SocketChannel.

NioSocketChannelback to summary
public NioSocketChannel(Channel parent, SocketChannel socket)

Create a new instance

Parameters
parent:Channel

the Channel which created this instance or null if it was created by the user

socket:SocketChannel

the SocketChannel which will be used

Method Detail

adjustMaxBytesPerGatheringWriteback to summary
private void adjustMaxBytesPerGatheringWrite(int attempted, int written, int oldMaxBytesPerGatheringWrite)
configback to summary
public SocketChannelConfig config()

Implements io.netty.channel.socket.SocketChannel.config, io.netty.channel.Channel.config.

Doc from io.netty.channel.Channel.config.

Returns the configuration of this channel.

Annotations
@Override
doBindback to summary
protected void doBind(SocketAddress localAddress) throws Exception

Implements abstract io.netty.channel.AbstractChannel.doBind.

Doc from io.netty.channel.AbstractChannel.doBind.

Bind the Channel to the SocketAddress

Annotations
@Override
doBind0back to summary
private void doBind0(SocketAddress localAddress) throws Exception
doCloseback to summary
protected void doClose() throws Exception

Overrides io.netty.channel.nio.AbstractNioChannel.doClose.

Doc from io.netty.channel.AbstractChannel.doClose.

Close the Channel

Annotations
@Override
doConnectback to summary
protected boolean doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception

Implements abstract io.netty.channel.nio.AbstractNioChannel.doConnect.

Doc from io.netty.channel.nio.AbstractNioChannel.doConnect.

Connect to the remote peer

Annotations
@Override
doDisconnectback to summary
protected void doDisconnect() throws Exception

Implements abstract io.netty.channel.AbstractChannel.doDisconnect.

Doc from io.netty.channel.AbstractChannel.doDisconnect.

Disconnect this Channel from its remote peer

Annotations
@Override
doFinishConnectback to summary
protected void doFinishConnect() throws Exception

Implements abstract io.netty.channel.nio.AbstractNioChannel.doFinishConnect.

Doc from io.netty.channel.nio.AbstractNioChannel.doFinishConnect.

Finish the connect

Annotations
@Override
doReadBytesback to summary
protected int doReadBytes(ByteBuf byteBuf) throws Exception

Implements abstract io.netty.channel.nio.AbstractNioByteChannel.doReadBytes.

Doc from io.netty.channel.nio.AbstractNioByteChannel.doReadBytes.

Read bytes into the given ByteBuf and return the amount.

Annotations
@Override
doShutdownOutputback to summary
protected final void doShutdownOutput() throws Exception

Overrides io.netty.channel.AbstractChannel.doShutdownOutput.

Doc from io.netty.channel.AbstractChannel.doShutdownOutput.

Called when conditions justify shutting down the output portion of the channel. This may happen if a write operation throws an exception.

Annotations
@SuppressJava6Requirement
reason:Usage guarded by java version check
@UnstableApi
@Override
doWriteback to summary
protected void doWrite(ChannelOutboundBuffer in) throws Exception

Overrides io.netty.channel.nio.AbstractNioByteChannel.doWrite.

Doc from io.netty.channel.AbstractChannel.doWrite.

Flush the content of the given buffer to the remote peer.

Annotations
@Override
doWriteBytesback to summary
protected int doWriteBytes(ByteBuf buf) throws Exception

Implements abstract io.netty.channel.nio.AbstractNioByteChannel.doWriteBytes.

Doc from io.netty.channel.nio.AbstractNioByteChannel.doWriteBytes.

Write bytes form the given ByteBuf to the underlying java.nio.channels.Channel.

Parameters
buf:ByteBuf

the ByteBuf from which the bytes should be written

Returns:int

amount the amount of written bytes

Annotations
@Override
doWriteFileRegionback to summary
protected long doWriteFileRegion(FileRegion region) throws Exception

Implements abstract io.netty.channel.nio.AbstractNioByteChannel.doWriteFileRegion.

Doc from io.netty.channel.nio.AbstractNioByteChannel.doWriteFileRegion.

Write a FileRegion

Parameters
region:FileRegion

the FileRegion from which the bytes should be written

Returns:long

amount the amount of written bytes

Annotations
@Override
isActiveback to summary
public boolean isActive()

Implements io.netty.channel.Channel.isActive.

Doc from io.netty.channel.Channel.isActive.

Return true if the Channel is active and so connected.

Annotations
@Override
isInputShutdownback to summary
public boolean isInputShutdown()

Implements io.netty.channel.socket.DuplexChannel.isInputShutdown.

Doc from io.netty.channel.socket.DuplexChannel.isInputShutdown.

Returns true if and only if the remote peer shut down its output so that no more data is received from this channel. Note that the semantic of this method is different from that of Socket#shutdownInput() and Socket#isInputShutdown().

Annotations
@Override
isInputShutdown0back to summary
protected boolean isInputShutdown0()

Overrides io.netty.channel.nio.AbstractNioByteChannel.isInputShutdown0.

Annotations
@Override
isOutputShutdownback to summary
public boolean isOutputShutdown()

Implements io.netty.channel.socket.DuplexChannel.isOutputShutdown.

Annotations
@Override
isShutdownback to summary
public boolean isShutdown()

Implements io.netty.channel.socket.DuplexChannel.isShutdown.

Doc from io.netty.channel.socket.DuplexChannel.isShutdown.

Determine if both the input and output of this channel have been shutdown.

Annotations
@Override
javaChannelback to summary
protected SocketChannel javaChannel()

Overrides io.netty.channel.nio.AbstractNioChannel.javaChannel.

Annotations
@Override
localAddressback to summary
public InetSocketAddress localAddress()

Overrides io.netty.channel.AbstractChannel.localAddress.

Implements io.netty.channel.socket.SocketChannel.localAddress, io.netty.channel.Channel.localAddress.

Doc from io.netty.channel.Channel.localAddress.

Returns the local address where this channel is bound to. The returned SocketAddress is supposed to be down-cast into more concrete type such as InetSocketAddress to retrieve the detailed information.

Returns:InetSocketAddress

the local address of this channel. null if this channel is not bound.

Annotations
@Override
localAddress0back to summary
protected SocketAddress localAddress0()

Implements abstract io.netty.channel.AbstractChannel.localAddress0.

Doc from io.netty.channel.AbstractChannel.localAddress0.

Returns the SocketAddress which is bound locally.

Annotations
@Override
newChannelback to summary
private static SocketChannel newChannel(SelectorProvider provider, InternetProtocolFamily family)
newUnsafeback to summary
protected AbstractNioChannel.AbstractNioUnsafe newUnsafe()

Overrides io.netty.channel.nio.AbstractNioByteChannel.newUnsafe.

Doc from io.netty.channel.AbstractChannel.newUnsafe.

Create a new AbstractUnsafe instance which will be used for the life-time of the Channel

Annotations
@Override
parentback to summary
public ServerSocketChannel parent()

Overrides io.netty.channel.AbstractChannel.parent.

Implements io.netty.channel.socket.SocketChannel.parent, io.netty.channel.Channel.parent.

Doc from io.netty.channel.Channel.parent.

Returns the parent of this channel.

Returns:ServerSocketChannel

the parent channel. null if this channel does not have a parent channel.

Annotations
@Override
remoteAddressback to summary
public InetSocketAddress remoteAddress()

Overrides io.netty.channel.AbstractChannel.remoteAddress.

Implements io.netty.channel.socket.SocketChannel.remoteAddress, io.netty.channel.Channel.remoteAddress.

Doc from io.netty.channel.Channel.remoteAddress.

Returns the remote address where this channel is connected to. The returned SocketAddress is supposed to be down-cast into more concrete type such as InetSocketAddress to retrieve the detailed information.

Returns:InetSocketAddress

the remote address of this channel. null if this channel is not connected. If this channel is not connected but it can receive messages from arbitrary remote addresses (e.g. DatagramChannel, use DatagramPacket#recipient() to determine the origination of the received message as this method will return null.

Annotations
@Override
remoteAddress0back to summary
protected SocketAddress remoteAddress0()

Implements abstract io.netty.channel.AbstractChannel.remoteAddress0.

Doc from io.netty.channel.AbstractChannel.remoteAddress0.

Return the SocketAddress which the Channel is connected to.

Annotations
@Override
shutdownback to summary
public ChannelFuture shutdown()

Implements io.netty.channel.socket.DuplexChannel.shutdown.

Doc from io.netty.channel.socket.DuplexChannel.shutdown.

Will shutdown the input and output sides of this channel.

Returns:ChannelFuture

will be completed when both shutdown operations complete.

Annotations
@Override
shutdownback to summary
public ChannelFuture shutdown(final ChannelPromise promise)

Implements io.netty.channel.socket.DuplexChannel.shutdown.

Doc from io.netty.channel.socket.DuplexChannel.shutdown.

Will shutdown the input and output sides of this channel.

Parameters
promise:ChannelPromise

will be completed when both shutdown operations complete.

Returns:ChannelFuture

will be completed when both shutdown operations complete.

Annotations
@Override
shutdownDoneback to summary
private static void shutdownDone(ChannelFuture shutdownOutputFuture, ChannelFuture shutdownInputFuture, ChannelPromise promise)
shutdownInputback to summary
public ChannelFuture shutdownInput()

Implements abstract io.netty.channel.nio.AbstractNioByteChannel.shutdownInput.

Implements io.netty.channel.socket.DuplexChannel.shutdownInput.

Doc from io.netty.channel.nio.AbstractNioByteChannel.shutdownInput.

Shutdown the input side of the channel.

Annotations
@Override
shutdownInputback to summary
public ChannelFuture shutdownInput(final ChannelPromise promise)

Implements io.netty.channel.socket.DuplexChannel.shutdownInput.

Doc from io.netty.channel.socket.DuplexChannel.shutdownInput.

Will shutdown the input and notify ChannelPromise.

Annotations
@Override
shutdownInput0back to summary
private void shutdownInput0(final ChannelPromise promise)
shutdownInput0back to summary
private void shutdownInput0() throws Exception
Annotations
@SuppressJava6Requirement
reason:Usage guarded by java version check
shutdownOutputback to summary
public ChannelFuture shutdownOutput()

Implements io.netty.channel.socket.DuplexChannel.shutdownOutput.

Annotations
@Override
shutdownOutputback to summary
public ChannelFuture shutdownOutput(final ChannelPromise promise)

Implements io.netty.channel.socket.DuplexChannel.shutdownOutput.

Doc from io.netty.channel.socket.DuplexChannel.shutdownOutput.

Will shutdown the output and notify ChannelPromise.

Annotations
@Override
shutdownOutputDoneback to summary
private void shutdownOutputDone(final ChannelFuture shutdownOutputFuture, final ChannelPromise promise)
io.netty.channel.socket.nio back to summary

private final Class NioSocketChannel.NioSocketChannelConfig

extends DefaultSocketChannelConfig
Class Inheritance

Field Summary

Modifier and TypeField and Description
private volatile int
Inherited from io.netty.channel.socket.DefaultSocketChannelConfig:
javaSocket

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected void
autoReadCleared()

Overrides io.netty.channel.DefaultChannelConfig.autoReadCleared.

Is called once setAutoRead(boolean) is called with false and isAutoRead() was true before.
private void
pack-priv int
public <T> T
public Map<ChannelOption<?>, Object>
private SocketChannel
pack-priv void
setMaxBytesPerGatheringWrite(int maxBytesPerGatheringWrite)

public <T> boolean
setOption(ChannelOption<T> option, T value)

Overrides io.netty.channel.socket.DefaultSocketChannelConfig.setOption.

Implements io.netty.channel.ChannelConfig.setOption.

Sets a configuration property with the specified name and value.
public NioSocketChannel.NioSocketChannelConfig
Inherited from io.netty.channel.socket.DefaultSocketChannelConfig:
getReceiveBufferSizegetSendBufferSizegetSoLingergetTrafficClassisAllowHalfClosureisKeepAliveisReuseAddressisTcpNoDelaysetAllocatorsetAllowHalfClosuresetAutoClosesetAutoReadsetConnectTimeoutMillissetKeepAlivesetMaxMessagesPerReadsetMessageSizeEstimatorsetPerformancePreferencessetReceiveBufferSizesetRecvByteBufAllocatorsetReuseAddresssetSoLingersetTcpNoDelaysetTrafficClasssetWriteBufferHighWaterMarksetWriteBufferLowWaterMarksetWriteBufferWaterMarksetWriteSpinCount

Field Detail

maxBytesPerGatheringWriteback to summary
private volatile int maxBytesPerGatheringWrite

Constructor Detail

NioSocketChannelConfigback to summary
private NioSocketChannelConfig(NioSocketChannel channel, Socket javaSocket)

Method Detail

autoReadClearedback to summary
protected void autoReadCleared()

Overrides io.netty.channel.DefaultChannelConfig.autoReadCleared.

Doc from io.netty.channel.DefaultChannelConfig.autoReadCleared.

Is called once setAutoRead(boolean) is called with false and isAutoRead() was true before.

Annotations
@Override
calculateMaxBytesPerGatheringWriteback to summary
private void calculateMaxBytesPerGatheringWrite()
getMaxBytesPerGatheringWriteback to summary
pack-priv int getMaxBytesPerGatheringWrite()
getOptionback to summary
public <T> T getOption(ChannelOption<T> option)

Overrides io.netty.channel.socket.DefaultSocketChannelConfig.getOption.

Implements io.netty.channel.ChannelConfig.getOption.

Doc from io.netty.channel.ChannelConfig.getOption.

Return the value of the given ChannelOption

Annotations
@Override
getOptionsback to summary
public Map<ChannelOption<?>, Object> getOptions()

Overrides io.netty.channel.socket.DefaultSocketChannelConfig.getOptions.

Implements io.netty.channel.ChannelConfig.getOptions.

Doc from io.netty.channel.ChannelConfig.getOptions.

Return all set ChannelOption's.

Annotations
@Override
jdkChannelback to summary
private SocketChannel jdkChannel()
setMaxBytesPerGatheringWriteback to summary
pack-priv void setMaxBytesPerGatheringWrite(int maxBytesPerGatheringWrite)
setOptionback to summary
public <T> boolean setOption(ChannelOption<T> option, T value)

Overrides io.netty.channel.socket.DefaultSocketChannelConfig.setOption.

Implements io.netty.channel.ChannelConfig.setOption.

Doc from io.netty.channel.ChannelConfig.setOption.

Sets a configuration property with the specified name and value. To override this method properly, you must call the super class:

public boolean setOption(ChannelOption<T> option, T value) {
    if (super.setOption(option, value)) {
        return true;
    }

    if (option.equals(additionalOption)) {
        ....
        return true;
    }

    return false;
}
Returns:boolean

true if and only if the property has been set

Annotations
@Override
setSendBufferSizeback to summary
public NioSocketChannel.NioSocketChannelConfig setSendBufferSize(int sendBufferSize)

Overrides io.netty.channel.socket.DefaultSocketChannelConfig.setSendBufferSize.

Implements io.netty.channel.socket.SocketChannelConfig.setSendBufferSize.

Doc from io.netty.channel.socket.SocketChannelConfig.setSendBufferSize.

Sets the StandardSocketOptions#SO_SNDBUF option.

Annotations
@Override
io.netty.channel.socket.nio back to summary

private final Class NioSocketChannel.NioSocketChannelUnsafe

extends NioByteUnsafe
Class Inheritance

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
protected Executor
Inherited from io.netty.channel.nio.AbstractNioByteChannel.NioByteUnsafe:
read

Constructor Detail

NioSocketChannelUnsafeback to summary
private NioSocketChannelUnsafe()

Method Detail

prepareToCloseback to summary
protected Executor prepareToClose()

Overrides io.netty.channel.AbstractChannel.AbstractUnsafe.prepareToClose.

Doc from io.netty.channel.AbstractChannel.AbstractUnsafe.prepareToClose.

Prepares to close the Channel. If this method returns an Executor, the caller must call the Executor#execute(Runnable) method with a task that calls doClose() on the returned Executor. If this method returns null, doClose() must be called from the caller thread. (i.e. EventLoop)

Annotations
@Override