Module org.newsclub.net.unix
Package org.newsclub.net.unix
Class AFSocketChannel<A extends AFSocketAddress>
java.lang.Object
java.nio.channels.spi.AbstractInterruptibleChannel
java.nio.channels.SelectableChannel
java.nio.channels.spi.AbstractSelectableChannel
java.nio.channels.SocketChannel
org.newsclub.net.unix.AFSocketChannel<A>
- Type Parameters:
A
- The concreteAFSocketAddress
that is supported by this type.
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ByteChannel
,Channel
,GatheringByteChannel
,InterruptibleChannel
,NetworkChannel
,ReadableByteChannel
,ScatteringByteChannel
,WritableByteChannel
,AFSocketExtensions
,AFSomeSocket
,AFSomeSocketChannel
,AFSomeSocketThing
,FileDescriptorAccess
- Direct Known Subclasses:
AFUNIXSocketChannel
public abstract class AFSocketChannel<A extends AFSocketAddress>
extends SocketChannel
implements AFSomeSocket, AFSocketExtensions, AFSomeSocketChannel
A selectable channel for stream-oriented connecting sockets.
- Author:
- Christian Kohlschütter
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static interface
A reference to a method that provides anAFSocket
instance. -
Constructor Summary
ModifierConstructorDescriptionprotected
AFSocketChannel
(AFSocket<A> socket, AFSelectorProvider<A> sp) Creates a new socket channel for the given socket, using the givenSelectorProvider
. -
Method Summary
Modifier and TypeMethodDescriptionfinal AFSocketChannel
<A> bind
(SocketAddress local) final boolean
connect
(SocketAddress remote) final void
ensureAncillaryReceiveBufferSize
(int minSize) Ensures a minimum ancillary receive buffer size.final boolean
Returns the correspondingAFSocket
.final int
Returns the size of the receive buffer for ancillary messages (in bytes).final FileDescriptor
Returns the correspondingFileDescriptor
.final A
final A
Returns the socket's local socket address, ornull
if unavailable or if there was a problem retrieving it.final <T> T
getOption
(SocketOption<T> name) final A
final A
Returns the socket's remote socket address, ornull
if unavailable/not connected, or if there was a problem retrieving it.protected final void
protected final void
implConfigureBlocking
(boolean block) final boolean
final boolean
static SocketChannel
open
(ProtocolFamily family) Opens a socket channel.protected static final <A extends AFSocketAddress>
AFSocketChannel<A> open
(AFSocketChannel.AFSocketSupplier<A> supplier) Opens a socket channel.protected static final <A extends AFSocketAddress>
AFSocketChannel<A> open
(AFSocketChannel.AFSocketSupplier<A> supplier, SocketAddress remote) Opens a socket channel, connecting to the given socket address.final int
read
(ByteBuffer dst) final long
read
(ByteBuffer[] dsts, int offset, int length) final void
setAncillaryReceiveBufferSize
(int size) Sets the size of the receive buffer for ancillary messages (in bytes).final <T> AFSocketChannel
<A> setOption
(SocketOption<T> name, T value) void
setShutdownOnClose
(boolean enabled) Configures whether the socket should be shutdown uponCloseable.close()
, which is the default.final AFSocketChannel
<A> final AFSocketChannel
<A> socket()
final Set
<SocketOption<?>> final String
toString()
final int
write
(ByteBuffer src) final long
write
(ByteBuffer[] srcs, int offset, int length) Methods inherited from class java.nio.channels.spi.AbstractSelectableChannel
blockingLock, configureBlocking, implCloseChannel, isBlocking, isRegistered, keyFor, provider, register
Methods inherited from class java.nio.channels.SelectableChannel
register
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpen
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.newsclub.net.unix.AFSomeSocketChannel
configureBlocking, isBlocking
Methods inherited from interface java.nio.channels.InterruptibleChannel
close
-
Constructor Details
-
AFSocketChannel
Creates a new socket channel for the given socket, using the givenSelectorProvider
.- Parameters:
socket
- The socket.sp
- TheSelectorProvider
.
-
-
Method Details
-
getAFSocket
-
open
protected static final <A extends AFSocketAddress> AFSocketChannel<A> open(AFSocketChannel.AFSocketSupplier<A> supplier) throws IOException Opens a socket channel.- Type Parameters:
A
- The concreteAFSocketAddress
that is supported by this type.- Parameters:
supplier
- The AFSocketChannel constructor.- Returns:
- The new channel
- Throws:
IOException
- on error.
-
open
protected static final <A extends AFSocketAddress> AFSocketChannel<A> open(AFSocketChannel.AFSocketSupplier<A> supplier, SocketAddress remote) throws IOException Opens a socket channel, connecting to the given socket address.- Type Parameters:
A
- The concreteAFSocketAddress
that is supported by this type.- Parameters:
supplier
- The AFSocketChannel constructor.remote
- The socket address to connect to.- Returns:
- The new channel
- Throws:
IOException
- on error.
-
getOption
- Specified by:
getOption
in interfaceNetworkChannel
- Throws:
IOException
-
setOption
- Specified by:
setOption
in interfaceNetworkChannel
- Specified by:
setOption
in classSocketChannel
- Throws:
IOException
-
supportedOptions
- Specified by:
supportedOptions
in interfaceNetworkChannel
-
bind
- Specified by:
bind
in interfaceNetworkChannel
- Specified by:
bind
in classSocketChannel
- Throws:
IOException
-
shutdownInput
- Specified by:
shutdownInput
in classSocketChannel
- Throws:
IOException
-
shutdownOutput
- Specified by:
shutdownOutput
in classSocketChannel
- Throws:
IOException
-
socket
- Specified by:
socket
in classSocketChannel
-
isConnected
public final boolean isConnected()- Specified by:
isConnected
in classSocketChannel
-
isConnectionPending
public final boolean isConnectionPending()- Specified by:
isConnectionPending
in classSocketChannel
-
connect
- Specified by:
connect
in classSocketChannel
- Throws:
IOException
-
finishConnect
- Specified by:
finishConnect
in classSocketChannel
- Throws:
IOException
-
getRemoteAddress
- Specified by:
getRemoteAddress
in classSocketChannel
- Throws:
IOException
-
getRemoteSocketAddress
Description copied from interface:AFSomeSocket
Returns the socket's remote socket address, ornull
if unavailable/not connected, or if there was a problem retrieving it.- Specified by:
getRemoteSocketAddress
in interfaceAFSomeSocket
- Returns:
- The remote socket address, or
null
.
-
read
- Specified by:
read
in interfaceReadableByteChannel
- Specified by:
read
in classSocketChannel
- Throws:
IOException
-
read
- Specified by:
read
in interfaceScatteringByteChannel
- Specified by:
read
in classSocketChannel
- Throws:
IOException
-
write
- Specified by:
write
in interfaceGatheringByteChannel
- Specified by:
write
in classSocketChannel
- Throws:
IOException
-
write
- Specified by:
write
in interfaceWritableByteChannel
- Specified by:
write
in classSocketChannel
- Throws:
IOException
-
getLocalAddress
- Specified by:
getLocalAddress
in interfaceNetworkChannel
- Specified by:
getLocalAddress
in classSocketChannel
- Throws:
IOException
-
getLocalSocketAddress
Description copied from interface:AFSomeSocketThing
Returns the socket's local socket address, ornull
if unavailable or if there was a problem retrieving it.- Specified by:
getLocalSocketAddress
in interfaceAFSomeSocketThing
- Returns:
- The local socket address, or
null
.
-
implCloseSelectableChannel
- Specified by:
implCloseSelectableChannel
in classAbstractSelectableChannel
- Throws:
IOException
-
implConfigureBlocking
- Specified by:
implConfigureBlocking
in classAbstractSelectableChannel
- Throws:
IOException
-
getAncillaryReceiveBufferSize
public final int getAncillaryReceiveBufferSize()Description copied from interface:AFSocketExtensions
Returns the size of the receive buffer for ancillary messages (in bytes).- Specified by:
getAncillaryReceiveBufferSize
in interfaceAFSocketExtensions
- Returns:
- The size.
-
setAncillaryReceiveBufferSize
public final void setAncillaryReceiveBufferSize(int size) Description copied from interface:AFSocketExtensions
Sets the size of the receive buffer for ancillary messages (in bytes). To disable handling ancillary messages, set it to 0 (default).- Specified by:
setAncillaryReceiveBufferSize
in interfaceAFSocketExtensions
- Parameters:
size
- The size.
-
ensureAncillaryReceiveBufferSize
public final void ensureAncillaryReceiveBufferSize(int minSize) Description copied from interface:AFSocketExtensions
Ensures a minimum ancillary receive buffer size.- Specified by:
ensureAncillaryReceiveBufferSize
in interfaceAFSocketExtensions
- Parameters:
minSize
- The minimum size (in bytes).
-
getFileDescriptor
Description copied from interface:FileDescriptorAccess
Returns the correspondingFileDescriptor
.- Specified by:
getFileDescriptor
in interfaceFileDescriptorAccess
- Returns:
- The corresponding
FileDescriptor
. - Throws:
IOException
- on error.
-
toString
-
setShutdownOnClose
public void setShutdownOnClose(boolean enabled) Description copied from interface:AFSomeSocketThing
Configures whether the socket should be shutdown uponCloseable.close()
, which is the default.- Specified by:
setShutdownOnClose
in interfaceAFSomeSocketThing
- Parameters:
enabled
-true
if enabled.
-
open
Opens a socket channel. Thefamily
parameter specifies theprotocol family
of the channel's socket.If the
ProtocolFamily
is of anAFProtocolFamily
, orUNIX
, the corresponding junixsocket implementation is used. In all other cases, the call is delegated toSocketChannel.open()
.- Parameters:
family
- The protocol family.- Returns:
- The new
SocketChannel
. - Throws:
IOException
- on error.
-