@Override public Socket accept() throws IOException { UnixSocketChannel channel = serverSocketChannel.accept(); return new BlockingUnixSocket(path, channel, endpoint); }
@Override public void bind(SocketAddress endpoint, int backlog) throws IOException { this.endpoint = (InetSocketAddress) endpoint; UnixSocketAddress address = new UnixSocketAddress(path); serverSocketChannel = UnixServerSocketChannel.open(); serverSocketChannel.configureBlocking(true); serverSocketChannel.socket().bind(address); }
socket.delete(); try (UnixServerSocketChannel channel = UnixServerSocketChannel.open()) { channel.configureBlocking(true); channel.socket().bind(new UnixSocketAddress(socket)); final UnixSocketChannel c = channel.accept(); System.out.println("Accepted"); final QueueItem qi = queue.take();
protected void init_unixsock(Ruby runtime, IRubyObject _path, boolean server) { ByteList path = _path.convertToString().getByteList(); String fpath = Helpers.decodeByteList(runtime, path); int maxSize = 103; // Max size from Darwin, lowest common value we know of if (fpath.length() > 103) { throw runtime.newArgumentError("too long unix socket path (max: " + maxSize + "bytes)"); } try { if (server) { UnixServerSocketChannel channel = UnixServerSocketChannel.open(); UnixServerSocket socket = channel.socket(); // TODO: listen backlog socket.bind(new UnixSocketAddress(new File(fpath))); init_sock(runtime, channel, fpath); } else { File fpathFile = new File(fpath); if (!fpathFile.exists()) { throw runtime.newErrnoENOENTError("unix socket"); } UnixSocketChannel channel = UnixSocketChannel.open(); channel.connect(new UnixSocketAddress(fpathFile)); init_sock(runtime, channel); } } catch (IOException ioe) { throw runtime.newIOErrorFromException(ioe); } }
public static void main(String[] args) throws IOException { java.io.File path = new java.io.File("/tmp/fubar.sock"); path.deleteOnExit(); UnixSocketAddress address = new UnixSocketAddress(path); UnixServerSocketChannel channel = UnixServerSocketChannel.open(); try { Selector sel = NativeSelectorProvider.getInstance().openSelector(); channel.configureBlocking(false); channel.socket().bind(address); channel.register(sel, SelectionKey.OP_ACCEPT, new ServerActor(channel, sel)); while (sel.select() > 0) { Set<SelectionKey> keys = sel.selectedKeys(); for (SelectionKey k : keys) { Actor a = (Actor) k.attachment(); if (!a.rxready()) { k.cancel(); } } } } catch (IOException ex) { Logger.getLogger(UnixServerSocket.class.getName()).log(Level.SEVERE, null, ex); } }
UnixServerSocket(UnixServerSocketChannel channel) { this.channel = channel; this.fd = channel.getFD(); }
@Override public void accept(int acceptorID) throws IOException { LOG.debug("Blocking UnixSocket accept used. Might not be able to be interrupted!"); UnixServerSocketChannel serverChannel = _acceptChannel; if (serverChannel != null && serverChannel.isOpen()) { LOG.debug("accept {}",serverChannel); UnixSocketChannel channel = serverChannel.accept(); LOG.debug("accepted {}",channel); accepted(channel); } }
public UnixServerSocket() throws IOException { this.channel = new UnixServerSocketChannel(this); this.fd = channel.getFD(); }
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); }
protected void init_unixsock(Ruby runtime, IRubyObject _path, boolean server) { ByteList path = _path.convertToString().getByteList(); String fpath = Helpers.decodeByteList(runtime, path); int maxSize = 103; // Max size from Darwin, lowest common value we know of if (fpath.length() > 103) { throw runtime.newArgumentError("too long unix socket path (max: " + maxSize + "bytes)"); } try { if (server) { UnixServerSocketChannel channel = UnixServerSocketChannel.open(); UnixServerSocket socket = channel.socket(); // TODO: listen backlog socket.bind(new UnixSocketAddress(new File(fpath))); init_sock(runtime, channel, fpath); } else { File fpathFile = new File(fpath); if (!fpathFile.exists()) { throw runtime.newErrnoENOENTError("unix socket"); } UnixSocketChannel channel = UnixSocketChannel.open(); channel.connect(new UnixSocketAddress(fpathFile)); init_sock(runtime, channel); } } catch (IOException ioe) { throw runtime.newIOErrorFromException(ioe); } }
public String start() throws Exception { authSocket = createLocalSocketAddress(); address = new UnixSocketAddress(new File(authSocket)); channel = UnixServerSocketChannel.open(); channel.configureBlocking(false); socket = channel.socket(); socket.bind(address); selector = NativeSelectorProvider.getInstance().openSelector(); channel.register(selector, SelectionKey.OP_ACCEPT, new SshAgentServerSocketHandler()); POSIXFactory.getPOSIX().chmod(authSocket, 0600); thread = new Thread(new AgentSocketAcceptor(), "SSH Agent socket acceptor " + authSocket); thread.setDaemon(true); thread.start(); return authSocket; }
UnixServerSocket(UnixServerSocketChannel channel) { this.channel = channel; this.fd = channel.getFD(); }
public UnixServerSocket() throws IOException { this.channel = new UnixServerSocketChannel(this); this.fd = channel.getFD(); }
public UnixSocket accept() throws IOException { return new UnixSocket(channel.accept()); }
public void open() throws IOException { if (_acceptChannel == null) { File file = new File(_unixSocket); file.deleteOnExit(); SocketAddress bindAddress = new UnixSocketAddress(file); UnixServerSocketChannel serverChannel = UnixServerSocketChannel.open(); serverChannel.configureBlocking(getAcceptors()>0); try { serverChannel.socket().bind(bindAddress, getAcceptQueueSize()); } catch (IOException e) { LOG.warn("cannot bind {} exists={} writable={}", file, file.exists(), file.canWrite()); throw e; } addBean(serverChannel); if (LOG.isDebugEnabled()) LOG.debug("opened {}",serverChannel); _acceptChannel = serverChannel; } }
return unixFD; } else if (channel instanceof UnixServerSocketChannel) { ReflectiveAccess.FILE_DESCRIPTOR_FD.set(unixFD, ((UnixServerSocketChannel)channel).getFD()); return unixFD;
public UnixSocket accept() throws IOException { return new UnixSocket(channel.accept()); }
return unixFD; } else if (channel instanceof UnixServerSocketChannel) { ReflectiveAccess.FILE_DESCRIPTOR_FD.set(unixFD, ((UnixServerSocketChannel)channel).getFD()); return unixFD;