static RuntimeException sockerr(final Ruby runtime, final String msg, final Exception cause) { RuntimeException ex = SocketUtils.sockerr(runtime, msg); if ( cause != null ) ex.initCause(cause); return ex; }
private void setType(Ruby runtime, IRubyObject type) { Sock sockType = SocketUtils.sockFromArg(type); if (sockType == null) { throw SocketUtils.sockerr(runtime, "unknown socket type " + type); } soType = sockType; }
private void setType(Ruby runtime, IRubyObject type) { Sock sockType = SocketUtils.sockFromArg(type); if (sockType == null) { throw SocketUtils.sockerr(runtime, "unknown socket type " + type); } soType = sockType; }
static RuntimeException sockerr(final Ruby runtime, final String msg, final Exception cause) { RuntimeException ex = SocketUtils.sockerr(runtime, msg); if ( cause != null ) ex.initCause(cause); return ex; }
public static IRubyObject gethostname(ThreadContext context) { Ruby runtime = context.runtime; try { return RubyString.newInternalFromJavaExternal(context.runtime, InetAddress.getLocalHost().getHostName()); } catch(UnknownHostException e) { try { return RubyString.newInternalFromJavaExternal(context.runtime, InetAddress.getByAddress(new byte[]{0, 0, 0, 0}).getHostName()); } catch(UnknownHostException e2) { throw sockerr(runtime, "gethostname: name or service not known"); } } }
public static IRubyObject gethostname(ThreadContext context) { Ruby runtime = context.runtime; try { return RubyString.newInternalFromJavaExternal(context.runtime, InetAddress.getLocalHost().getHostName()); } catch(UnknownHostException e) { try { return RubyString.newInternalFromJavaExternal(context.runtime, InetAddress.getByAddress(new byte[]{0, 0, 0, 0}).getHostName()); } catch(UnknownHostException e2) { throw sockerr(runtime, "gethostname: name or service not known"); } } }
private void setDomain(Ruby runtime, IRubyObject domain) { AddressFamily family = SocketUtils.addressFamilyFromArg(domain); if (family == null) { throw SocketUtils.sockerr(runtime, "unknown socket domain " + domain); } soDomain = family; String name = soDomain.name(); if (name.startsWith("pseudo_")) name = name.substring(7); soProtocolFamily = ProtocolFamily.valueOf("PF" + name.substring(2)); }
private void setDomain(Ruby runtime, IRubyObject domain) { AddressFamily family = SocketUtils.addressFamilyFromArg(domain); if (family == null) { throw SocketUtils.sockerr(runtime, "unknown socket domain " + domain); } soDomain = family; String name = soDomain.name(); if (name.startsWith("pseudo_")) name = name.substring(7); soProtocolFamily = ProtocolFamily.valueOf("PF" + name.substring(2)); }
public static IRubyObject getaddress(ThreadContext context, IRubyObject hostname) { try { return RubyString.newInternalFromJavaExternal(context.runtime, InetAddress.getByName(hostname.convertToString().toString()).getHostAddress()); } catch(UnknownHostException e) { throw sockerr(context.runtime, "getaddress: name or service not known"); } }
public static IRubyObject getaddress(ThreadContext context, IRubyObject hostname) { try { return context.runtime.newString(InetAddress.getByName(hostname.convertToString().toString()).getHostAddress()); } catch(UnknownHostException e) { throw sockerr(context.runtime, "getaddress: name or service not known"); } }
public static IRubyObject getaddress(ThreadContext context, IRubyObject hostname) { try { return context.runtime.newString(InetAddress.getByName(hostname.convertToString().toString()).getHostAddress()); } catch(UnknownHostException e) { throw sockerr(context.runtime, "getaddress: name or service not known"); } }
/** * Overrides BasicSocket#recv */ @Override public IRubyObject recv(ThreadContext context, IRubyObject _length) { Ruby runtime = context.runtime; try { return doReceive(runtime, RubyNumeric.fix2int(_length)); } catch (IOException e) { throw SocketUtils.sockerr(runtime, "recv: name or service not known"); } }
@JRubyMethod(notImplemented = true) public IRubyObject ip_port(ThreadContext context) { if (getAddressFamily() != AF_INET && getAddressFamily() != AF_INET6) { throw SocketUtils.sockerr(context.runtime, "need IPv4 or IPv6 address"); } return context.runtime.newFixnum(((InetSocketAddress) socketAddress).getPort()); }
@JRubyMethod(notImplemented = true) public IRubyObject ip_port(ThreadContext context) { if (getAddressFamily() != AF_INET && getAddressFamily() != AF_INET6) { throw SocketUtils.sockerr(context.runtime, "need IPv4 or IPv6 address"); } return context.runtime.newFixnum(((InetSocketAddress) socketAddress).getPort()); }
@JRubyMethod public IRubyObject ip_address(ThreadContext context) { if (getAddressFamily() != AF_INET && getAddressFamily() != AF_INET6) { throw SocketUtils.sockerr(context.runtime, "need IPv4 or IPv6 address"); } // TODO: (gf) for IPv6 link-local address this appends a numeric interface index (like MS-Windows), should append interface name on Linux String fullHost = ((InetSocketAddress) socketAddress).getAddress().getHostAddress(); String host = (getAddressFamily() == AF_INET6) ? ipv6_ip() : fullHost; return context.runtime.newString(host); }
@JRubyMethod public IRubyObject ip_address(ThreadContext context) { if (getAddressFamily() != AF_INET && getAddressFamily() != AF_INET6) { throw SocketUtils.sockerr(context.runtime, "need IPv4 or IPv6 address"); } // TODO: (gf) for IPv6 link-local address this appends a numeric interface index (like MS-Windows), should append interface name on Linux String fullHost = ((InetSocketAddress) socketAddress).getAddress().getHostAddress(); String host = (getAddressFamily() == AF_INET6) ? ipv6_ip() : fullHost; return context.runtime.newString(host); }
@JRubyMethod(meta = true) public static IRubyObject ip(ThreadContext context, IRubyObject recv, IRubyObject arg) { String host = arg.convertToString().toString(); try { InetAddress addy = InetAddress.getByName(host); Addrinfo addrinfo = new Addrinfo(context.runtime, (RubyClass) recv, addy); addrinfo.protocol = Protocol.getProtocolByName("ip"); return addrinfo; } catch (UnknownHostException uhe) { throw SocketUtils.sockerr(context.runtime, "host not found"); } }
@JRubyMethod(meta = true) public static IRubyObject ip(ThreadContext context, IRubyObject recv, IRubyObject arg) { String host = arg.convertToString().toString(); try { InetAddress addy = InetAddress.getByName(host); Addrinfo addrinfo = new Addrinfo(context.runtime, (RubyClass) recv, addy); addrinfo.protocol = Protocol.getProtocolByName("ip"); return addrinfo; } catch (UnknownHostException uhe) { throw SocketUtils.sockerr(context.runtime, "host not found"); } }
@JRubyMethod public IRubyObject unix_path(ThreadContext context) { if (getAddressFamily() != AF_UNIX) { throw SocketUtils.sockerr(context.runtime, "need AF_UNIX address"); } return context.runtime.newString(getUnixSocketAddress().path()); }
@JRubyMethod public IRubyObject unix_path(ThreadContext context) { if (getAddressFamily() != AF_UNIX) { throw SocketUtils.sockerr(context.runtime, "need AF_UNIX address"); } return context.runtime.newString(getUnixSocketAddress().path()); }