@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); }
public void bind(SocketAddress endpoint) throws IOException { bind(endpoint, 128); }
public void bind(SocketAddress endpoint) throws java.io.IOException { bind(endpoint, 128); }
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); } }
channel.socket().bind(new UnixSocketAddress(socket));
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; }
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; } }
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); } }
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); } }
UnixServerSocket socket = channel.socket(); socket.bind(new UnixSocketAddress(new File(fpath)));
UnixServerSocket socket = channel.socket(); socket.bind(new UnixSocketAddress(new File(fpath)));