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,FileDescriptorAccess
- Direct Known Subclasses:
AFUNIXSocketChannel
public abstract class AFSocketChannel<A extends AFSocketAddress>
extends SocketChannel
implements AFSomeSocket, AFSocketExtensions
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 booleanprotected 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) 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.SocketChannel
open, open, open, read, validOps, writeMethods 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, isOpen
-
Constructor Details
-
AFSocketChannel
Creates a new socket channel for the given socket, using the givenSelectorProvider.- Parameters:
socket- The socket.sp- TheSelectorProvider.
-
-
Method Details
-
getAFSocket
Returns the correspondingAFSocket.- Returns:
- The corresponding socket.
-
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:AFSomeSocketReturns the socket's local socket address, ornullif unavailable or if there was a problem retrieving it.- Specified by:
getLocalSocketAddressin interfaceAFSomeSocket- 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
-