public IRubyObject allocate(Ruby runtime, RubyClass klass) { return new RubyTCPServer(runtime, klass); } };
@Deprecated public IRubyObject accept() { return accept(getRuntime().getCurrentContext()); }
@Deprecated public IRubyObject listen(IRubyObject backlog) { return listen(getRuntime().getCurrentContext(), backlog); }
@JRubyMethod(name = "accept_nonblock") public IRubyObject accept_nonblock(ThreadContext context, IRubyObject opts) { return accept_nonblock(context, context.runtime, extractExceptionArg(context, opts)); }
@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); } }
initSocket(runtime, new ChannelDescriptor(ssc, newModeFlags(runtime, ModeFlags.RDWR)));
initSocket(newChannelFD(runtime, ssc));
@Deprecated public static IRubyObject open(IRubyObject recv, IRubyObject[] args, Block block) { return open(recv.getRuntime().getCurrentContext(), recv, args, block); } }
public void load(final Ruby runtime, boolean wrap) throws IOException { runtime.defineClass("SocketError", runtime.getStandardError(), runtime.getStandardError().getAllocator()); RubyBasicSocket.createBasicSocket(runtime); RubySocket.createSocket(runtime); RubyServerSocket.createServerSocket(runtime); if (runtime.getInstanceConfig().isNativeEnabled() && !Platform.IS_WINDOWS) { RubyUNIXSocket.createUNIXSocket(runtime); RubyUNIXServer.createUNIXServer(runtime); } RubyIPSocket.createIPSocket(runtime); RubyTCPSocket.createTCPSocket(runtime); RubyTCPServer.createTCPServer(runtime); RubyUDPSocket.createUDPSocket(runtime); Addrinfo.createAddrinfo(runtime); Option.createOption(runtime); Ifaddr.createIfaddr(runtime); } }
@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"); } }
public ServerSocketChannel getServerSocketChannel() { return (ServerSocketChannel)getChannel(); }
@JRubyMethod(name = "sysaccept") public IRubyObject sysaccept(ThreadContext context) { Ruby runtime = context.runtime; 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(); return runtime.newFixnum(FilenoUtil.filenoFrom(connected)); } } } catch(IOException e) { throw runtime.newIOErrorFromException(e); } }
@JRubyMethod(name = "accept_nonblock") public IRubyObject accept_nonblock(ThreadContext context) { return accept_nonblock(context, context.runtime, true); }
@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); } }
initSocket(runtime, new ChannelDescriptor(ssc, newModeFlags(runtime, ModeFlags.RDWR)));
initSocket(newChannelFD(runtime, ssc));
@Deprecated public static IRubyObject open(IRubyObject recv, IRubyObject[] args, Block block) { return open(recv.getRuntime().getCurrentContext(), recv, args, block); } }
public void load(final Ruby runtime, boolean wrap) throws IOException { runtime.defineClass("SocketError", runtime.getStandardError(), runtime.getStandardError().getAllocator()); RubyBasicSocket.createBasicSocket(runtime); RubySocket.createSocket(runtime); RubyServerSocket.createServerSocket(runtime); if (runtime.getInstanceConfig().isNativeEnabled() && !Platform.IS_WINDOWS) { RubyUNIXSocket.createUNIXSocket(runtime); RubyUNIXServer.createUNIXServer(runtime); } RubyIPSocket.createIPSocket(runtime); RubyTCPSocket.createTCPSocket(runtime); RubyTCPServer.createTCPServer(runtime); RubyUDPSocket.createUDPSocket(runtime); Addrinfo.createAddrinfo(runtime); Option.createOption(runtime); Ifaddr.createIfaddr(runtime); } }
RubyTCPSocket socket = new RubyTCPSocket(runtime, runtime.getClass("TCPSocket")); Selector selector = null; ServerSocketChannel ssc = getServerSocketChannel(); socket.initSocket(context.runtime, new ChannelDescriptor(ssc.accept(), newModeFlags(runtime, ModeFlags.RDWR)));
@JRubyMethod(name = "accept_nonblock") public IRubyObject accept_nonblock(ThreadContext context, IRubyObject opts) { return accept_nonblock(context, context.runtime, extractExceptionArg(context, opts)); }