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)); }
@JRubyMethod(meta = true) public static IRubyObject getaddress(ThreadContext context, IRubyObject self, IRubyObject hostname) { return SocketUtils.getaddress(context, hostname); }
@JRubyMethod(required = 2, optional = 5, meta = true) public static IRubyObject getaddrinfo(ThreadContext context, IRubyObject recv, IRubyObject[] args) { return SocketUtils.getaddrinfo(context, args); }
AddressFamily addressFamily = family.isNil() ? null : addressFamilyFromArg(family); Sock sock = socktype.isNil() ? SOCK_STREAM : sockFromArg(socktype); port = getservbyname(context, new IRubyObject[]{port}); throw sockerr(runtime, "getaddrinfo: name or service not known");
int port = SocketUtils.getPortFrom(context, _port); throw SocketUtils.sockerr(runtime, "initialize: name or service not known"); throw runtime.newErrnoEACCESError("bind(2)"); } else { throw SocketUtils.sockerr(runtime, "initialize: name or service not known"); throw SocketUtils.sockerr(runtime, "initialize: name or service not known"); throw SocketUtils.sockerr(runtime, iae.getMessage());
private void initializeCommon(Ruby runtime, IRubyObject sockaddr, IRubyObject family, IRubyObject sock, IRubyObject port) { try { inetAddress = SocketUtils.getRubyInetAddress(sockaddr.convertToString().getByteList()); this.socketType = SocketType.SOCKET; } else { this.pfamily = SocketUtils.protocolFamilyFromArg(family); this.afamily = SocketUtils.addressFamilyFromArg(family); this.sock = Sock.SOCK_STREAM; } else { this.sock = SocketUtils.sockFromArg(sock);
AddressFamily af = SocketUtils.addressFamilyFromArg(family); ProtocolFamily pf = af != null ? null : SocketUtils.protocolFamilyFromArg(family); _port = SocketUtils.portToInt(port); } else { _port = 0;
port = getservbyname(context, new IRubyObject[]{port}); c[0] = runtime.newString(is_ipv6 ? "AF_INET6" : "AF_INET"); c[1] = port; c[2] = runtime.newString(getHostAddress(context, addrs[i])); c[3] = runtime.newString(addrs[i].getHostAddress()); c[4] = runtime.newFixnum(is_ipv6 ? PF_INET6 : PF_INET); c[0] = runtime.newString(is_ipv6 ? "AF_INET6" : "AF_INET"); c[1] = port; c[2] = runtime.newString(getHostAddress(context, addrs[i])); c[3] = runtime.newString(addrs[i].getHostAddress()); c[4] = runtime.newFixnum(is_ipv6 ? PF_INET6 : PF_INET); throw sockerr(runtime, "getaddrinfo: name or service not known");
@JRubyMethod(name = {"socketpair", "pair"}, meta = true) public static IRubyObject socketpair(ThreadContext context, IRubyObject recv, IRubyObject domain, IRubyObject type) { AddressFamily af = SocketUtils.addressFamilyFromArg(domain); if (af == null) af = AddressFamily.AF_UNIX; Sock s = SocketUtils.sockFromArg(type); if (s == null) s = Sock.SOCK_STREAM; if (af != AddressFamily.AF_UNIX || s != Sock.SOCK_STREAM) { throw context.runtime.newErrnoEOPNOTSUPPError("Socket.socketpair only supports streaming UNIX sockets"); } final Ruby runtime = context.runtime; // TODO: type and protocol UnixSocketChannel[] sp; try { sp = UnixSocketChannel.pair(); final RubyClass socketClass = runtime.getClass("Socket"); RubySocket sock0 = new RubySocket(runtime, socketClass); ChannelFD fd0 = newChannelFD(runtime, sp[0]); sock0.initFieldsFromDescriptor(runtime, fd0); sock0.initSocket(fd0); RubySocket sock1 = new RubySocket(runtime, socketClass); ChannelFD fd1 = newChannelFD(runtime, sp[1]); sock1.initFieldsFromDescriptor(runtime, fd1); sock1.initSocket(fd1); return runtime.newArray(sock0, sock1); } catch (IOException ioe) { throw runtime.newIOErrorFromException(ioe); } }
@JRubyMethod(required = 1, rest = true, meta = true) public static IRubyObject gethostbyaddr(ThreadContext context, IRubyObject recv, IRubyObject[] args) { return SocketUtils.gethostbyaddr(context, args); }
@JRubyMethod(required = 1, optional = 1, meta = true) public static IRubyObject getnameinfo(ThreadContext context, IRubyObject recv, IRubyObject[] args) { return SocketUtils.getnameinfo(context, args); }
@JRubyMethod(meta = true) public static IRubyObject gethostname(ThreadContext context, IRubyObject recv) { return SocketUtils.gethostname(context); }
@JRubyMethod(meta = true) public static IRubyObject ip_address_list(ThreadContext context, IRubyObject self) { return SocketUtils.ip_address_list(context); }
@JRubyMethod(required = 1, optional = 1, meta = true) public static IRubyObject getservbyname(ThreadContext context, IRubyObject recv, IRubyObject[] args) { return SocketUtils.getservbyname(context, args); }
@JRubyMethod(meta = true) public static IRubyObject gethostbyname(ThreadContext context, IRubyObject recv, IRubyObject hostname) { return SocketUtils.gethostbyname(context, hostname); }
@JRubyMethod(visibility = Visibility.PRIVATE) public IRubyObject initialize(ThreadContext context, IRubyObject _family) { AddressFamily family = SocketUtils.addressFamilyFromArg(_family); if (family == AddressFamily.AF_INET) { explicitFamily = Inet4Address.class; return initialize(context, StandardProtocolFamily.INET); } else if (family == AddressFamily.AF_INET6) { explicitFamily = Inet6Address.class; return initialize(context, StandardProtocolFamily.INET6); } throw context.runtime.newErrnoEAFNOSUPPORTError("invalid family for UDPSocket: " + _family); }
AddressFamily addressFamily = family.isNil() ? null : addressFamilyFromArg(family); Sock sock = socktype.isNil() ? SOCK_STREAM : sockFromArg(socktype); port = getservbyname(context, new IRubyObject[]{port}); throw sockerr(runtime, "getaddrinfo: name or service not known");
int port = SocketUtils.getPortFrom(context, _port); throw SocketUtils.sockerr(runtime, "initialize: name or service not known"); throw runtime.newErrnoEACCESError("bind(2)"); } else { throw SocketUtils.sockerr(runtime, "initialize: name or service not known"); throw SocketUtils.sockerr(runtime, "initialize: name or service not known"); throw SocketUtils.sockerr(runtime, iae.getMessage());
private void initializeCommon(Ruby runtime, IRubyObject sockaddr, IRubyObject family, IRubyObject sock, IRubyObject port) { try { inetAddress = SocketUtils.getRubyInetAddress(sockaddr.convertToString().getByteList()); this.socketType = SocketType.SOCKET; } else { this.pfamily = SocketUtils.protocolFamilyFromArg(family); this.afamily = SocketUtils.addressFamilyFromArg(family); this.sock = Sock.SOCK_STREAM; } else { this.sock = SocketUtils.sockFromArg(sock);
AddressFamily af = SocketUtils.addressFamilyFromArg(family); ProtocolFamily pf = af != null ? null : SocketUtils.protocolFamilyFromArg(family); _port = SocketUtils.portToInt(port); } else { _port = 0;