Package jnr.unixsocket
Class UnixSocketChannel
- java.lang.Object
-
- java.nio.channels.spi.AbstractInterruptibleChannel
-
- java.nio.channels.SelectableChannel
-
- java.nio.channels.spi.AbstractSelectableChannel
-
- java.nio.channels.SocketChannel
-
- jnr.enxio.channels.AbstractNativeSocketChannel
-
- jnr.unixsocket.UnixSocketChannel
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,java.nio.channels.ByteChannel
,java.nio.channels.Channel
,java.nio.channels.GatheringByteChannel
,java.nio.channels.InterruptibleChannel
,java.nio.channels.NetworkChannel
,java.nio.channels.ReadableByteChannel
,java.nio.channels.ScatteringByteChannel
,java.nio.channels.WritableByteChannel
,jnr.enxio.channels.NativeSelectableChannel
public class UnixSocketChannel extends jnr.enxio.channels.AbstractNativeSocketChannel
AChannel
implementation that uses a native unix socket
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
UnixSocketChannel.DefaultOptionsHolder
(package private) static class
UnixSocketChannel.State
-
Field Summary
Fields Modifier and Type Field Description private BindHandler
bindHandler
private UnixSocketAddress
localAddress
private UnixSocketAddress
remoteAddress
private UnixSocketChannel.State
state
private java.util.concurrent.locks.ReadWriteLock
stateLock
-
Constructor Summary
Constructors Constructor Description UnixSocketChannel()
UnixSocketChannel(int fd)
UnixSocketChannel(int fd, UnixSocketChannel.State initialState, boolean initialBoundState)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description UnixSocketChannel
bind(java.net.SocketAddress local)
boolean
connect(java.net.SocketAddress remote)
boolean
connect(UnixSocketAddress remote)
static UnixSocketChannel
create()
private boolean
doConnect(SockAddrUnix remote)
boolean
finishConnect()
static UnixSocketChannel
fromFD(int fd)
Create a UnixSocketChannel to wrap an existing file descriptor (presumably itself a UNIX socket).java.net.SocketAddress
getLocalAddress()
UnixSocketAddress
getLocalSocketAddress()
<T> T
getOption(java.net.SocketOption<T> name)
java.net.SocketAddress
getRemoteAddress()
UnixSocketAddress
getRemoteSocketAddress()
(package private) boolean
isBound()
boolean
isConnected()
boolean
isConnectionPending()
private boolean
isIdle()
static UnixSocketChannel
open()
static UnixSocketChannel
open(UnixSocketAddress remote)
static UnixSocketChannel[]
pair()
int
read(java.nio.ByteBuffer dst)
<T> java.nio.channels.SocketChannel
setOption(java.net.SocketOption<T> name, T value)
UnixSocket
socket()
java.util.Set<java.net.SocketOption<?>>
supportedOptions()
int
write(java.nio.ByteBuffer src)
long
write(java.nio.ByteBuffer[] srcs, int offset, int length)
-
Methods inherited from class jnr.enxio.channels.AbstractNativeSocketChannel
getFD, implCloseSelectableChannel, implConfigureBlocking, read, setFD, shutdownInput, shutdownOutput
-
Methods inherited from class java.nio.channels.spi.AbstractSelectableChannel
blockingLock, configureBlocking, implCloseChannel, isBlocking, isRegistered, keyFor, provider, register
-
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpen
-
-
-
-
Field Detail
-
state
private UnixSocketChannel.State state
-
remoteAddress
private UnixSocketAddress remoteAddress
-
localAddress
private UnixSocketAddress localAddress
-
stateLock
private final java.util.concurrent.locks.ReadWriteLock stateLock
-
bindHandler
private final BindHandler bindHandler
-
-
Constructor Detail
-
UnixSocketChannel
UnixSocketChannel() throws java.io.IOException
- Throws:
java.io.IOException
-
UnixSocketChannel
UnixSocketChannel(int fd)
-
UnixSocketChannel
UnixSocketChannel(int fd, UnixSocketChannel.State initialState, boolean initialBoundState)
-
-
Method Detail
-
open
public static final UnixSocketChannel open() throws java.io.IOException
- Throws:
java.io.IOException
-
open
public static final UnixSocketChannel open(UnixSocketAddress remote) throws java.io.IOException
- Throws:
java.io.IOException
-
create
public static final UnixSocketChannel create() throws java.io.IOException
- Throws:
java.io.IOException
-
pair
public static final UnixSocketChannel[] pair() throws java.io.IOException
- Throws:
java.io.IOException
-
fromFD
public static final UnixSocketChannel fromFD(int fd)
Create a UnixSocketChannel to wrap an existing file descriptor (presumably itself a UNIX socket).- Parameters:
fd
- the file descriptor to wrap- Returns:
- the new UnixSocketChannel instance
-
doConnect
private boolean doConnect(SockAddrUnix remote) throws java.io.IOException
- Throws:
java.io.IOException
-
connect
public boolean connect(UnixSocketAddress remote) throws java.io.IOException
- Throws:
java.io.IOException
-
isBound
boolean isBound()
-
isConnected
public boolean isConnected()
- Specified by:
isConnected
in classjava.nio.channels.SocketChannel
-
isIdle
private boolean isIdle()
-
isConnectionPending
public boolean isConnectionPending()
- Specified by:
isConnectionPending
in classjava.nio.channels.SocketChannel
-
finishConnect
public boolean finishConnect() throws java.io.IOException
- Specified by:
finishConnect
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
getRemoteSocketAddress
public final UnixSocketAddress getRemoteSocketAddress()
-
getLocalSocketAddress
public final UnixSocketAddress getLocalSocketAddress()
-
connect
public boolean connect(java.net.SocketAddress remote) throws java.io.IOException
- Specified by:
connect
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
socket
public UnixSocket socket()
- Specified by:
socket
in classjava.nio.channels.SocketChannel
-
write
public long write(java.nio.ByteBuffer[] srcs, int offset, int length) throws java.io.IOException
- Specified by:
write
in interfacejava.nio.channels.GatheringByteChannel
- Overrides:
write
in classjnr.enxio.channels.AbstractNativeSocketChannel
- Throws:
java.io.IOException
-
read
public int read(java.nio.ByteBuffer dst) throws java.io.IOException
- Specified by:
read
in interfacejava.nio.channels.ReadableByteChannel
- Overrides:
read
in classjnr.enxio.channels.AbstractNativeSocketChannel
- Throws:
java.io.IOException
-
write
public int write(java.nio.ByteBuffer src) throws java.io.IOException
- Specified by:
write
in interfacejava.nio.channels.WritableByteChannel
- Overrides:
write
in classjnr.enxio.channels.AbstractNativeSocketChannel
- Throws:
java.io.IOException
-
getRemoteAddress
public java.net.SocketAddress getRemoteAddress() throws java.io.IOException
- Specified by:
getRemoteAddress
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
getLocalAddress
public java.net.SocketAddress getLocalAddress() throws java.io.IOException
- Specified by:
getLocalAddress
in interfacejava.nio.channels.NetworkChannel
- Specified by:
getLocalAddress
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
supportedOptions
public final java.util.Set<java.net.SocketOption<?>> supportedOptions()
-
getOption
public <T> T getOption(java.net.SocketOption<T> name) throws java.io.IOException
- Throws:
java.io.IOException
-
setOption
public <T> java.nio.channels.SocketChannel setOption(java.net.SocketOption<T> name, T value) throws java.io.IOException
- Specified by:
setOption
in interfacejava.nio.channels.NetworkChannel
- Specified by:
setOption
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
bind
public UnixSocketChannel bind(java.net.SocketAddress local) throws java.io.IOException
- Specified by:
bind
in interfacejava.nio.channels.NetworkChannel
- Specified by:
bind
in classjava.nio.channels.SocketChannel
- Throws:
java.io.IOException
-
-