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 concreteAFSocketAddressthat 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:
AFSYSTEMSocketChannel,AFTIPCSocketChannel,AFUNIXSocketChannel,AFVSOCKSocketChannel
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
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceA reference to a method that provides anAFSocketinstance. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAFSocketChannel(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 booleanconnect(SocketAddress remote) final voidensureAncillaryReceiveBufferSize(int minSize) Ensures a minimum ancillary receive buffer size.final booleanReturns the correspondingAFSocket.final intReturns the size of the receive buffer for ancillary messages (in bytes).final FileDescriptorReturns the correspondingFileDescriptor.final Afinal AReturns the socket's local socket address, ornullif unavailable or if there was a problem retrieving it.final <T> TgetOption(SocketOption<T> name) final Afinal AReturns the socket's remote socket address, ornullif unavailable/not connected, or if there was a problem retrieving it.protected final voidprotected final voidimplConfigureBlocking(boolean block) final booleanfinal booleanstatic SocketChannelopen(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 intread(ByteBuffer dst) final longread(ByteBuffer[] dsts, int offset, int length) final voidsetAncillaryReceiveBufferSize(int size) Sets the size of the receive buffer for ancillary messages (in bytes).final <T> AFSocketChannel<A> setOption(SocketOption<T> name, T value) voidsetShutdownOnClose(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 StringtoString()final intwrite(ByteBuffer src) final longwrite(ByteBuffer[] srcs, int offset, int length) Methods inherited from class java.nio.channels.spi.AbstractSelectableChannel
blockingLock, configureBlocking, implCloseChannel, isBlocking, isRegistered, keyFor, provider, registerMethods inherited from class java.nio.channels.SelectableChannel
registerMethods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpenMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.newsclub.net.unix.AFSomeSocketChannel
configureBlocking, isBlockingMethods 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 concreteAFSocketAddressthat 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 concreteAFSocketAddressthat 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:
getOptionin interfaceNetworkChannel- Throws:
IOException
-
setOption
- Specified by:
setOptionin interfaceNetworkChannel- Specified by:
setOptionin classSocketChannel- Throws:
IOException
-
supportedOptions
- Specified by:
supportedOptionsin interfaceNetworkChannel
-
bind
- Specified by:
bindin interfaceNetworkChannel- Specified by:
bindin classSocketChannel- Throws:
IOException
-
shutdownInput
- Specified by:
shutdownInputin classSocketChannel- Throws:
IOException
-
shutdownOutput
- Specified by:
shutdownOutputin classSocketChannel- Throws:
IOException
-
socket
- Specified by:
socketin classSocketChannel
-
isConnected
public final boolean isConnected()- Specified by:
isConnectedin classSocketChannel
-
isConnectionPending
public final boolean isConnectionPending()- Specified by:
isConnectionPendingin classSocketChannel
-
connect
- Specified by:
connectin classSocketChannel- Throws:
IOException
-
finishConnect
- Specified by:
finishConnectin classSocketChannel- Throws:
IOException
-
getRemoteAddress
- Specified by:
getRemoteAddressin classSocketChannel- Throws:
IOException
-
getRemoteSocketAddress
Description copied from interface:AFSomeSocketReturns the socket's remote socket address, ornullif unavailable/not connected, or if there was a problem retrieving it.- Specified by:
getRemoteSocketAddressin interfaceAFSomeSocket- Returns:
- The remote socket address, or
null.
-
read
- Specified by:
readin interfaceReadableByteChannel- Specified by:
readin classSocketChannel- Throws:
IOException
-
read
- Specified by:
readin interfaceScatteringByteChannel- Specified by:
readin classSocketChannel- Throws:
IOException
-
write
- Specified by:
writein interfaceGatheringByteChannel- Specified by:
writein classSocketChannel- Throws:
IOException
-
write
- Specified by:
writein interfaceWritableByteChannel- Specified by:
writein classSocketChannel- Throws:
IOException
-
getLocalAddress
- Specified by:
getLocalAddressin interfaceNetworkChannel- Specified by:
getLocalAddressin classSocketChannel- Throws:
IOException
-
getLocalSocketAddress
Description copied from interface:AFSomeSocketThingReturns the socket's local socket address, ornullif unavailable or if there was a problem retrieving it.- Specified by:
getLocalSocketAddressin interfaceAFSomeSocketThing- Returns:
- The local socket address, or
null.
-
implCloseSelectableChannel
- Specified by:
implCloseSelectableChannelin classAbstractSelectableChannel- Throws:
IOException
-
implConfigureBlocking
- Specified by:
implConfigureBlockingin classAbstractSelectableChannel- Throws:
IOException
-
getAncillaryReceiveBufferSize
public final int getAncillaryReceiveBufferSize()Description copied from interface:AFSocketExtensionsReturns the size of the receive buffer for ancillary messages (in bytes).- Specified by:
getAncillaryReceiveBufferSizein interfaceAFSocketExtensions- Returns:
- The size.
-
setAncillaryReceiveBufferSize
public final void setAncillaryReceiveBufferSize(int size) Description copied from interface:AFSocketExtensionsSets the size of the receive buffer for ancillary messages (in bytes). To disable handling ancillary messages, set it to 0 (default).- Specified by:
setAncillaryReceiveBufferSizein interfaceAFSocketExtensions- Parameters:
size- The size.
-
ensureAncillaryReceiveBufferSize
public final void ensureAncillaryReceiveBufferSize(int minSize) Description copied from interface:AFSocketExtensionsEnsures a minimum ancillary receive buffer size.- Specified by:
ensureAncillaryReceiveBufferSizein interfaceAFSocketExtensions- Parameters:
minSize- The minimum size (in bytes).
-
getFileDescriptor
Description copied from interface:FileDescriptorAccessReturns the correspondingFileDescriptor.- Specified by:
getFileDescriptorin interfaceFileDescriptorAccess- Returns:
- The corresponding
FileDescriptor. - Throws:
IOException- on error.
-
toString
-
setShutdownOnClose
public void setShutdownOnClose(boolean enabled) Description copied from interface:AFSomeSocketThingConfigures whether the socket should be shutdown uponCloseable.close(), which is the default.- Specified by:
setShutdownOnClosein interfaceAFSomeSocketThing- Parameters:
enabled-trueif enabled.
-
open
Opens a socket channel. Thefamilyparameter specifies theprotocol familyof the channel's socket.If the
ProtocolFamilyis 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.
-