@JRubyMethod public IRubyObject afamily(ThreadContext context) { return context.runtime.newFixnum(pfamily.intValue()); }
@JRubyMethod public IRubyObject pfamily(ThreadContext context) { return context.runtime.newFixnum(pfamily.intValue()); }
/** * Sets the protocol family of this unix socket address. * * @param family The protocol family, usually {@link ProtocolFamily#PF_UNIX} */ final void setFamily(ProtocolFamily family) { getFamilyField().set(family.intValue()); }
@JRubyMethod public IRubyObject afamily(ThreadContext context) { return context.runtime.newFixnum(pfamily.intValue()); }
@JRubyMethod public IRubyObject pfamily(ThreadContext context) { return context.runtime.newFixnum(pfamily.intValue()); }
static int socketpair(ProtocolFamily domain, Sock type, int protocol, int[] sv) throws IOException { if (libsocket().socketpair(domain.intValue(), type.intValue(), protocol, sv) < 0) { throw new IOException("socketpair(2) failed " + Native.getLastErrorString()); } return 0; }
static int socket(ProtocolFamily domain, Sock type, int protocol) throws IOException { int fd = libsocket().socket(domain.intValue(), type.intValue(), protocol); if (fd < 0) { throw new IOException(getLastErrorString()); } return fd; }
static int socketpair(ProtocolFamily domain, Sock type, int protocol, int[] sv) throws IOException { if (libsocket().socketpair(domain.intValue(), type.intValue(), protocol, sv) < 0) { throw new IOException("socketpair(2) failed " + Native.getLastErrorString()); } return 0; }
static int socket(ProtocolFamily domain, Sock type, int protocol) throws IOException { int fd = libsocket().socket(domain.intValue(), type.intValue(), protocol); if (fd < 0) { throw new IOException(getLastErrorString()); } return fd; }
@JRubyMethod(meta = true) public static IRubyObject tcp(ThreadContext context, IRubyObject recv, IRubyObject host, IRubyObject port) { Ruby runtime = context.runtime; Addrinfo addrinfo = new Addrinfo(runtime, (RubyClass) recv); addrinfo.initializeCommon(context, host, runtime.newFixnum(PF_UNSPEC.intValue()), runtime.newFixnum(Sock.SOCK_STREAM.intValue()), port); return addrinfo; }
@JRubyMethod(meta = true) public static IRubyObject tcp(ThreadContext context, IRubyObject recv, IRubyObject host, IRubyObject port) { Ruby runtime = context.runtime; Addrinfo addrinfo = new Addrinfo(runtime, (RubyClass) recv); addrinfo.initializeCommon(context, host, runtime.newFixnum(PF_UNSPEC.intValue()), runtime.newFixnum(Sock.SOCK_STREAM.intValue()), port); return addrinfo; }
@JRubyMethod(meta = true) public static IRubyObject udp(ThreadContext context, IRubyObject recv, IRubyObject host, IRubyObject port) { Ruby runtime = context.runtime; Addrinfo addrinfo = new Addrinfo(runtime, (RubyClass) recv); addrinfo.initializeCommon(context, host, runtime.newFixnum(PF_UNSPEC.intValue()), runtime.newFixnum(Sock.SOCK_DGRAM.intValue()), port); return addrinfo; }
@JRubyMethod(meta = true) public static IRubyObject udp(ThreadContext context, IRubyObject recv, IRubyObject host, IRubyObject port) { Ruby runtime = context.runtime; Addrinfo addrinfo = new Addrinfo(runtime, (RubyClass) recv); addrinfo.initializeCommon(context, host, runtime.newFixnum(PF_UNSPEC.intValue()), runtime.newFixnum(Sock.SOCK_DGRAM.intValue()), port); return addrinfo; }
static AddressFamily addressFamilyFromArg(IRubyObject domain) { IRubyObject maybeString = TypeConverter.checkStringType(domain.getRuntime(), domain); if (!maybeString.isNil()) { domain = maybeString; } try { if (domain instanceof RubyString || domain instanceof RubySymbol) { String domainString = domain.toString(); if (domainString.startsWith("AF_")) return AddressFamily.valueOf(domainString); if (domainString.startsWith("PF_")) return AddressFamily.valueOf(ProtocolFamily.valueOf(domainString).intValue()); return AddressFamily.valueOf("AF_" + domainString); } int domainInt = RubyNumeric.fix2int(domain); return AddressFamily.valueOf(domainInt); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(domain.getRuntime(), "invalid address family: " + domain); } }
static AddressFamily addressFamilyFromArg(IRubyObject domain) { IRubyObject maybeString = TypeConverter.checkStringType(domain.getRuntime(), domain); if (!maybeString.isNil()) { domain = maybeString; } try { if (domain instanceof RubyString || domain instanceof RubySymbol) { String domainString = domain.toString(); if (domainString.startsWith("AF_")) return AddressFamily.valueOf(domainString); if (domainString.startsWith("PF_")) return AddressFamily.valueOf(ProtocolFamily.valueOf(domainString).intValue()); return AddressFamily.valueOf("AF_" + domainString); } int domainInt = RubyNumeric.fix2int(domain); return AddressFamily.valueOf(domainInt); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(domain.getRuntime(), "invalid address family: " + domain); } }