public IRubyObject allocate(Ruby runtime, RubyClass klass) { return new RubyTCPSocket(runtime, klass); } };
@Deprecated public static IRubyObject gethostbyname(IRubyObject recv, IRubyObject hostname) { return gethostbyname(recv.getRuntime().getCurrentContext(), recv, hostname); } }
@Deprecated public static IRubyObject open(IRubyObject recv, IRubyObject[] args, Block block) { return open(recv.getRuntime().getCurrentContext(), recv, args, block); }
@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(newChannelFD(runtime, channel)); success = true; throw sockerr(runtime, e.getMessage(), e);
initSocket(runtime, new ChannelDescriptor(channel, newModeFlags(runtime, ModeFlags.RDWR))); success = true; } catch(BindException e) {
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(meta = true) public static IRubyObject gethostbyname(ThreadContext context, IRubyObject recv, IRubyObject hostname) { Ruby runtime = context.runtime; IRubyObject[] ret = new IRubyObject[4]; String hostString = hostname.convertToString().toString(); try { InetAddress addr = InetAddress.getByName(hostString); ret[0] = runtime.newString(do_not_reverse_lookup(context, recv).isTrue() ? addr.getHostAddress() : addr.getCanonicalHostName()); ret[1] = runtime.newArray(); if (addr instanceof Inet4Address) { ret[2] = runtime.newFixnum(AF_INET); } else if (addr instanceof Inet6Address) { ret[2] = runtime.newFixnum(AF_INET6); } ret[3] = runtime.newString(addr.getHostAddress()); return runtime.newArrayNoCopy(ret); } catch(UnknownHostException e) { throw SocketUtils.sockerr(runtime, "gethostbyname: name or service not known"); } }
@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(newChannelFD(runtime, channel)); success = true; throw sockerr(runtime, e.getMessage(), e);
initSocket(runtime, new ChannelDescriptor(channel, newModeFlags(runtime, ModeFlags.RDWR))); success = true; } catch(BindException e) {
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(meta = true) public static IRubyObject gethostbyname(ThreadContext context, IRubyObject recv, IRubyObject hostname) { Ruby runtime = context.runtime; IRubyObject ret0, ret1, ret2, ret3; String hostString = hostname.convertToString().toString(); try { InetAddress addr = InetAddress.getByName(hostString); ret0 = runtime.newString(do_not_reverse_lookup(context, recv).isTrue() ? addr.getHostAddress() : addr.getCanonicalHostName()); ret1 = runtime.newArray(); if (addr instanceof Inet4Address) { ret2 = runtime.newFixnum(AF_INET); } else { // if (addr instanceof Inet6Address) { ret2 = runtime.newFixnum(AF_INET6); } ret3 = runtime.newString(addr.getHostAddress()); return RubyArray.newArray(runtime, ret0, ret1, ret2, ret3); } catch(UnknownHostException e) { throw SocketUtils.sockerr(runtime, "gethostbyname: name or service not known"); } }
@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); } }
@Deprecated public static IRubyObject gethostbyname(IRubyObject recv, IRubyObject hostname) { return gethostbyname(recv.getRuntime().getCurrentContext(), recv, hostname); } }
public IRubyObject allocate(Ruby runtime, RubyClass klass) { return new RubyTCPSocket(runtime, klass); } };
@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); if (runtime.is1_9()) { Addrinfo.createAddrinfo(runtime); Option.createOption(runtime); } } }
@JRubyMethod(meta = true) public static IRubyObject gethostbyname(ThreadContext context, IRubyObject recv, IRubyObject hostname) { Ruby runtime = context.runtime; IRubyObject ret0, ret1, ret2, ret3; String hostString = hostname.convertToString().toString(); try { InetAddress addr = InetAddress.getByName(hostString); ret0 = runtime.newString(do_not_reverse_lookup(context, recv).isTrue() ? addr.getHostAddress() : addr.getCanonicalHostName()); ret1 = runtime.newArray(); if (addr instanceof Inet4Address) { ret2 = runtime.newFixnum(AF_INET); } else { // if (addr instanceof Inet6Address) { ret2 = runtime.newFixnum(AF_INET6); } ret3 = runtime.newString(addr.getHostAddress()); return RubyArray.newArray(runtime, ret0, ret1, ret2, ret3); } catch(UnknownHostException e) { throw SocketUtils.sockerr(runtime, "gethostbyname: name or service not known"); } }
@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"); } }