@JRubyMethod(name = "accept") public IRubyObject accept(ThreadContext context) { Ruby runtime = context.runtime; RubyTCPSocket socket = new RubyTCPSocket(runtime, runtime.getClass("TCPSocket")); try { RubyThread thread = context.getThread(); while (true) { boolean ready = thread.select(this, SelectionKey.OP_ACCEPT); if (!ready) { // we were woken up without being selected...poll for thread events and go back to sleep context.pollThreadEvents(); } else { SocketChannel connected = getServerSocketChannel().accept(); if (connected == null) continue; connected.finishConnect(); // Force the client socket to be blocking synchronized (connected.blockingLock()) { connected.configureBlocking(false); connected.configureBlocking(true); } // otherwise one key has been selected (ours) so we get the channel and hand it off socket.initSocket(newChannelFD(runtime, connected)); return socket; } } } catch(IOException e) { throw runtime.newIOErrorFromException(e); } }
@JRubyMethod(name = "accept") public IRubyObject accept(ThreadContext context) { Ruby runtime = context.runtime; RubyTCPSocket socket = new RubyTCPSocket(runtime, runtime.getClass("TCPSocket")); try { RubyThread thread = context.getThread(); while (true) { boolean ready = thread.select(this, SelectionKey.OP_ACCEPT); if (!ready) { // we were woken up without being selected...poll for thread events and go back to sleep context.pollThreadEvents(); } else { SocketChannel connected = getServerSocketChannel().accept(); if (connected == null) continue; connected.finishConnect(); // Force the client socket to be blocking synchronized (connected.blockingLock()) { connected.configureBlocking(false); connected.configureBlocking(true); } // otherwise one key has been selected (ours) so we get the channel and hand it off socket.initSocket(newChannelFD(runtime, connected)); return socket; } } } catch(IOException e) { throw runtime.newIOErrorFromException(e); } }
@JRubyMethod(name = "accept") public IRubyObject accept(ThreadContext context) { Ruby runtime = context.runtime; RubyTCPSocket socket = new RubyTCPSocket(runtime, runtime.getClass("TCPSocket")); try { RubyThread thread = context.getThread(); while (true) { boolean ready = thread.select(this, SelectionKey.OP_ACCEPT); if (!ready) { // we were woken up without being selected...poll for thread events and go back to sleep context.pollThreadEvents(); } else { SocketChannel connected = ssc.accept(); if (connected == null) continue; connected.finishConnect(); // Force the client socket to be blocking synchronized (connected.blockingLock()) { connected.configureBlocking(false); connected.configureBlocking(true); } // otherwise one key has been selected (ours) so we get the channel and hand it off socket.initSocket(runtime, new ChannelDescriptor(connected, newModeFlags(runtime, ModeFlags.RDWR))); return socket; } } } catch(IOException e) { throw SocketUtils.sockerr(runtime, "problem when accepting"); } }
initSocket(runtime, new ChannelDescriptor(channel, newModeFlags(runtime, ModeFlags.RDWR))); success = true; } catch(BindException e) {
initSocket(runtime, new ChannelDescriptor(channel, newModeFlags(runtime, ModeFlags.RDWR))); success = true; } catch(BindException e) {
@JRubyMethod(name = "accept") public IRubyObject accept(ThreadContext context) { Ruby runtime = context.runtime; RubyTCPSocket socket = new RubyTCPSocket(runtime, runtime.getClass("TCPSocket")); try { RubyThread thread = context.getThread(); while (true) { boolean ready = thread.select(this, SelectionKey.OP_ACCEPT); if (!ready) { // we were woken up without being selected...poll for thread events and go back to sleep context.pollThreadEvents(); } else { SocketChannel connected = getServerSocketChannel().accept(); if (connected == null) continue; connected.finishConnect(); // Force the client socket to be blocking synchronized (connected.blockingLock()) { connected.configureBlocking(false); connected.configureBlocking(true); } // otherwise one key has been selected (ours) so we get the channel and hand it off socket.initSocket(runtime, new ChannelDescriptor(connected, newModeFlags(runtime, ModeFlags.RDWR))); return socket; } } } catch(IOException e) { throw SocketUtils.sockerr(runtime, "problem when accepting"); } }
initSocket(newChannelFD(runtime, channel)); success = true;
@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) {} } } }
socket.initSocket(newChannelFD(runtime, ssc.accept()));
socket.initSocket(newChannelFD(runtime, ssc.accept()));
initSocket(newChannelFD(runtime, channel)); success = true;
socket.initSocket(context.runtime, new ChannelDescriptor(ssc.accept(), newModeFlags(runtime, ModeFlags.RDWR)));