@JRubyMethod(name = "accept_nonblock") public IRubyObject accept_nonblock(ThreadContext context) { Ruby runtime = context.runtime; RubyTCPSocket socket = new RubyTCPSocket(runtime, runtime.getClass("TCPSocket")); Selector selector = null; synchronized (ssc.blockingLock()) { boolean oldBlocking = ssc.isBlocking(); try { ssc.configureBlocking(false); selector = SelectorFactory.openWithRetryFrom(runtime, SelectorProvider.provider()); boolean ready = context.getThread().select(this, SelectionKey.OP_ACCEPT, 0); if (!ready) { // no connection immediately accepted, let them try again throw runtime.newErrnoEAGAINError("Resource temporarily unavailable"); } else { // otherwise one key has been selected (ours) so we get the channel and hand it off socket.initSocket(context.runtime, new ChannelDescriptor(ssc.accept(), newModeFlags(runtime, ModeFlags.RDWR))); return socket; } } catch(IOException e) { throw SocketUtils.sockerr(context.runtime, "problem when accepting"); } finally { try { if (selector != null) selector.close(); } catch (Exception e) { } try {ssc.configureBlocking(oldBlocking);} catch (IOException ioe) {} } } }
ServerSocketChannel ssc = getServerSocketChannel(); synchronized (ssc.blockingLock()) { boolean oldBlocking = ssc.isBlocking();
ServerSocketChannel ssc = getServerSocketChannel(); synchronized (ssc.blockingLock()) { boolean oldBlocking = ssc.isBlocking();
ServerSocketChannel ssc = getServerSocketChannel(); synchronized (ssc.blockingLock()) { boolean oldBlocking = ssc.isBlocking();