Class AFUNIXSocketChannel
- All Implemented Interfaces:
Closeable, AutoCloseable, ByteChannel, Channel, GatheringByteChannel, InterruptibleChannel, NetworkChannel, ReadableByteChannel, ScatteringByteChannel, WritableByteChannel, AFSocketExtensions, AFSomeSocket, AFSomeSocketChannel, AFSomeSocketThing, AFUNIXSocketExtensions, FileDescriptorAccess
public final class AFUNIXSocketChannel
extends AFSocketChannel<AFUNIXSocketAddress>
implements AFUNIXSocketExtensions
A selectable channel for stream-oriented connecting sockets.
- Author:
- Christian Kohlschütter
-
Nested Class Summary
Nested classes/interfaces inherited from class AFSocketChannel
AFSocketChannel.AFSocketSupplier<A>Modifier and TypeClassDescriptionprotected static interfaceA reference to a method that provides anAFSocketinstance. -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the queue of incomingFileDescriptors that were sent as ancillary messages.Retrieves the "peer credentials" for this connection.Retrieves an array of incomingFileDescriptors that were sent as ancillary messages, along with a call toInputStream.read(), etc.booleanReturnstrueif there are pending file descriptors to be sent as part of an ancillary message.static AFUNIXSocketChannelopen()Opens a socket channel.static AFUNIXSocketChannelopen(SocketAddress remote) Opens a socket channel, connecting to the given socket address.voidsetOutboundFileDescriptors(FileDescriptor... fdescs) Sets a list ofFileDescriptors that should be sent as an ancillary message along with the next write.Methods inherited from class AFSocketChannel
bind, connect, ensureAncillaryReceiveBufferSize, finishConnect, getAFSocket, getAncillaryReceiveBufferSize, getFileDescriptor, getLocalAddress, getLocalSocketAddress, getOption, getRemoteAddress, getRemoteSocketAddress, implCloseSelectableChannel, implConfigureBlocking, isConnected, isConnectionPending, open, open, open, read, read, setAncillaryReceiveBufferSize, setOption, setShutdownOnClose, shutdownInput, shutdownOutput, socket, supportedOptions, toString, write, writeModifier and TypeMethodDescriptionbind(SocketAddress local) final booleanconnect(SocketAddress remote) final voidensureAncillaryReceiveBufferSize(int minSize) Ensures a minimum ancillary receive buffer size.final booleanprotected final AFSocket<AFUNIXSocketAddress> Returns the correspondingAFSocket.final intReturns the size of the receive buffer for ancillary messages (in bytes).final FileDescriptorReturns the correspondingFileDescriptor.final AFUNIXSocketAddressfinal AFUNIXSocketAddressReturns the socket's local socket address, ornullif unavailable or if there was a problem retrieving it.final <T> TgetOption(SocketOption<T> name) final AFUNIXSocketAddressfinal AFUNIXSocketAddressReturns 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<AFUNIXSocketAddress> setOption(SocketOption<T> name, T value) voidsetShutdownOnClose(boolean enabled) Configures whether the socket should be shutdown uponCloseable.close(), which is the default.final AFSocket<AFUNIXSocketAddress> socket()final Set<SocketOption<?>> final StringtoString()final intwrite(ByteBuffer src) final longwrite(ByteBuffer[] srcs, int offset, int length) Methods inherited from class SocketChannel
read, validOps, writeMethods inherited from class AbstractSelectableChannel
blockingLock, configureBlocking, implCloseChannel, isBlocking, isRegistered, keyFor, provider, registerMethods inherited from class SelectableChannel
registerMethods inherited from class AbstractInterruptibleChannel
begin, close, end, isOpenMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface AFSomeSocketChannel
configureBlocking, isBlockingModifier and TypeMethodDescriptionconfigureBlocking(boolean block) Adjusts this channel's blocking mode.booleanChecks if the channel is configured blocking.
-
Method Details
-
open
Opens a socket channel.- Returns:
- The new channel
- Throws:
IOException- on error.
-
open
Opens a socket channel, connecting to the given socket address.- Parameters:
remote- The socket address to connect to.- Returns:
- The new channel
- Throws:
IOException- on error.
-
getReceivedFileDescriptors
Description copied from interface:AFUNIXSocketExtensionsRetrieves an array of incomingFileDescriptors that were sent as ancillary messages, along with a call toInputStream.read(), etc. NOTE: Another call to this method will not return the same file descriptors again (most likely, an empty array will be returned).- Specified by:
getReceivedFileDescriptorsin interfaceAFUNIXSocketExtensions- Returns:
- The file descriptors, or an empty array if none were available.
- Throws:
IOException- if the operation fails.
-
clearReceivedFileDescriptors
public void clearReceivedFileDescriptors()Description copied from interface:AFUNIXSocketExtensionsClears the queue of incomingFileDescriptors that were sent as ancillary messages.- Specified by:
clearReceivedFileDescriptorsin interfaceAFUNIXSocketExtensions
-
setOutboundFileDescriptors
Description copied from interface:AFUNIXSocketExtensionsSets a list ofFileDescriptors that should be sent as an ancillary message along with the next write. Important: There can only be one set of file descriptors active until the write completes. The socket also needs to be connected for this operation to succeed. It is also important to know that there may be an upper limit imposed by the operation system as to how many file descriptors can be sent at once. Linux, for example, may support up to 253. If the number of file descriptors exceeds the limit, an exception may be thrown when sending data along with the ancillary message containing the file descriptors.- Specified by:
setOutboundFileDescriptorsin interfaceAFUNIXSocketExtensions- Parameters:
fdescs- The file descriptors, ornullif none.- Throws:
IOException- if the operation fails.
-
hasOutboundFileDescriptors
public boolean hasOutboundFileDescriptors()Description copied from interface:AFUNIXSocketExtensionsReturnstrueif there are pending file descriptors to be sent as part of an ancillary message.- Specified by:
hasOutboundFileDescriptorsin interfaceAFUNIXSocketExtensions- Returns:
trueif there are file descriptors pending.
-
getPeerCredentials
Description copied from interface:AFUNIXSocketExtensionsRetrieves the "peer credentials" for this connection. These credentials may be useful to authenticate the other end of the socket (client or server). Depending on the socket/connection/environment, you may not receive any or all credentials. For example, on Linux,AFUNIXDatagramSocketandAFUNIXDatagramChannelmay not be able to retrieve credentials at all.- Specified by:
getPeerCredentialsin interfaceAFUNIXSocketExtensions- Returns:
- The peer's credentials, or
nullif they couldn't be retrieved. - Throws:
IOException- If there was an error returning these credentials.
-