public final boolean isBlocking() { return channel.isBlocking(); }
public void acceptJavaServer() { try { if (!_srvrScktChannel.isBlocking()) { _srvrScktChannel.accept(); } } catch (Exception e) { System.out.println("\nJNI acceptJavaServer Exception: " + e.getMessage()); } }
/** * Wrap AsyncServerSocket over given ServerSocketChannel using given event worker thread and selector thread. * * @param channel a {@link java.nio.channels.ServerSocketChannel} object. * @param eventExecutor event executor or null for selector thread * @param t selector thread * @throws java.nio.channels.ClosedChannelException if any. */ public ListenableServerSocketChannel(ServerSocketChannel channel, Executor eventExecutor, AsyncSelector t) throws ClosedChannelException { if (channel.isBlocking()) throw new IllegalArgumentException("channel arg must be in non-blocking mode. (SocketChannel.configureBlocking(false))"); if (t==null) throw new IllegalArgumentException("null arg"); this.executor = eventExecutor; this.channel.set(channel); this.selector = t; t.register(channel, 0, selectListener); }
boolean oldBlocking = ssc.isBlocking();
@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) {} } } }
boolean oldBlocking = ssc.isBlocking();
boolean oldBlocking = ssc.isBlocking();