/** * Create a UnixSocketChannel to wrap an existing file descriptor * (presumably itself a UNIX socket). * * @param fd * the file descriptor to wrap * @return the new UnixSocketChannel instance */ public static final UnixSocketChannel fromFD(int fd) { return new UnixSocketChannel(fd); }
public static final UnixSocketChannel create() throws IOException { return new UnixSocketChannel(); }
public static final UnixSocketChannel open() throws IOException { return new UnixSocketChannel(); }
public static final UnixSocketChannel open() throws IOException { return new UnixSocketChannel(); }
public static final UnixSocketChannel[] pair() throws IOException { int[] sockets = { -1, -1 }; Native.socketpair(ProtocolFamily.PF_UNIX, Sock.SOCK_STREAM, 0, sockets); return new UnixSocketChannel[] { new UnixSocketChannel(sockets[0], State.CONNECTED, true), new UnixSocketChannel(sockets[1], State.CONNECTED, true) }; }
public static final UnixSocketChannel[] pair() throws IOException { int[] sockets = { -1, -1 }; Native.socketpair(ProtocolFamily.PF_UNIX, Sock.SOCK_STREAM, 0, sockets); return new UnixSocketChannel[] { new UnixSocketChannel(sockets[0], SelectionKey.OP_READ | SelectionKey.OP_WRITE), new UnixSocketChannel(sockets[1], SelectionKey.OP_READ | SelectionKey.OP_WRITE) }; }
public static final UnixSocketChannel open(UnixSocketAddress remote) throws IOException { UnixSocketChannel channel = new UnixSocketChannel(); channel.connect(remote); return channel; }
public static final UnixSocketChannel open(UnixSocketAddress remote) throws IOException { UnixSocketChannel channel = new UnixSocketChannel(); try { channel.connect(remote); } catch (IOException e) { channel.close(); throw e; } return channel; }
public UnixSocketChannel accept() throws IOException { UnixSocketAddress remote = new UnixSocketAddress(); SockAddrUnix addr = remote.getStruct(); IntByReference len = new IntByReference(addr.getMaximumLength()); int clientfd = Native.accept(getFD(), addr, len); if (clientfd < 0) { throw new IOException("accept failed: " + Native.getLastErrorString()); } // Always force the socket back to blocking mode Native.setBlocking(clientfd, true); return new UnixSocketChannel(clientfd, remote); }
public UnixSocketChannel accept() throws IOException { UnixSocketAddress remote = new UnixSocketAddress(); SockAddrUnix addr = remote.getStruct(); int maxLength = addr.getMaximumLength(); IntByReference len = new IntByReference(maxLength); int clientfd = Native.accept(getFD(), addr, len); if (clientfd < 0) { if (isBlocking()) { throw new IOException("accept failed: " + Native.getLastErrorString()); } return null; } // Handle unnamed sockets and sockets in Linux' abstract namespace addr.updatePath(len.getValue()); // Always force the socket back to blocking mode Native.setBlocking(clientfd, true); return new UnixSocketChannel(clientfd); }