public final String toString() { return description(); } public static SocketLevel valueOf(long value) {
public static int setsockopt(int s, SocketLevel level, SocketOption optname, boolean optval) { ByteBuffer buf = ByteBuffer.allocate(4); buf.order(ByteOrder.BIG_ENDIAN); buf.putInt(optval ? 1 : 0).flip(); return libsocket().setsockopt(s, level.intValue(), optname.intValue(), buf, buf.remaining()); } }
buf .append(" level:") .append(level.longValue()) .append(' ') .append(noPrefix(option)); buf .append(" level:") .append(level.description()) .append(' ') .append(noPrefix(option));
@JRubyMethod public IRubyObject level(ThreadContext context) { return context.runtime.newFixnum(level.longValue()); }
@JRubyMethod public IRubyObject inspect(ThreadContext context) { StringBuffer buf = new StringBuffer("#<"); buf .append(metaClass.getRealClass().getName()) .append(" ") .append(noPrefix(family)); if (level == SocketLevel.SOL_SOCKET) { buf .append(" SOCKET ") .append(noPrefix(option)); } else if (family == ProtocolFamily.PF_UNIX) { buf .append(" level:") .append(level.longValue()) .append(" ") .append(noPrefix(option)); } else { buf .append(" level:") .append(level.description()) .append(" ") .append(noPrefix(option)); } buf .append(" ") .append(optionValue()) .append(">"); return context.runtime.newString(buf.toString()); }
@JRubyMethod public IRubyObject level(ThreadContext context) { return context.runtime.newFixnum(level.longValue()); }
buf .append(" level:") .append(level.longValue()) .append(' ') .append(noPrefix(option)); buf .append(" level:") .append(level.description()) .append(' ') .append(noPrefix(option));
public final String toString() { return description(); } public static SocketLevel valueOf(long value) {
public static int setsockopt(int s, SocketLevel level, SocketOption optname, int optval) { if (optname == SocketOption.SO_RCVTIMEO || optname == SocketOption.SO_SNDTIMEO) { DefaultNativeTimeval t = new DefaultNativeTimeval(Runtime.getSystemRuntime()); t.setTime(new long [] {optval / 1000, ((long)optval % 1000) * 1000}); return libsocket().setsockopt(s, level.intValue(), optname.intValue(), t, DefaultNativeTimeval.size(t)); } else { ByteBuffer buf = ByteBuffer.allocate(4); buf.order(ByteOrder.nativeOrder()); buf.putInt(optval).flip(); return libsocket().setsockopt(s, level.intValue(), optname.intValue(), buf, buf.remaining()); } }
@JRubyMethod public IRubyObject level(ThreadContext context) { return context.runtime.newFixnum(level.longValue()); }
@JRubyMethod public IRubyObject inspect(ThreadContext context) { StringBuffer buf = new StringBuffer("#<"); buf .append(metaClass.getRealClass().getName()) .append(" ") .append(noPrefix(family)); if (level == SocketLevel.SOL_SOCKET) { buf .append(" SOCKET ") .append(noPrefix(option)); } else if (family == ProtocolFamily.PF_UNIX) { buf .append(" level:") .append(level.longValue()) .append(" ") .append(noPrefix(option)); } else { buf .append(" level:") .append(level.description()) .append(" ") .append(noPrefix(option)); } buf .append(" ") .append(optionValue()) .append(">"); return context.runtime.newString(buf.toString()); }
public final String toString() { return description(); } public static SocketLevel valueOf(long value) {
public final boolean getKeepAlive() { ByteBuffer buf = ByteBuffer.allocate(4); buf.order(ByteOrder.BIG_ENDIAN); IntByReference ref = new IntByReference(4); Native.libsocket().getsockopt(channel.getFD(), SocketLevel.SOL_SOCKET.intValue(), SocketOption.SO_KEEPALIVE.intValue(), buf, ref); return buf.getInt(0) != 0; } }
static SocketLevel levelFromArg(IRubyObject level) { IRubyObject maybeString = TypeConverter.checkStringType(level.getRuntime(), level); if (!maybeString.isNil()) { level = maybeString; } try { if (level instanceof RubyString || level instanceof RubySymbol) { String levelString = level.toString(); if(levelString.startsWith("SOL_")) return SocketLevel.valueOf(levelString); return SocketLevel.valueOf("SOL_" + levelString); } return SocketLevel.valueOf(RubyNumeric.fix2int(level)); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(level.getRuntime(), "invalid socket level: " + level); } }
@JRubyMethod public IRubyObject level(ThreadContext context) { return context.runtime.newFixnum(level.longValue()); }
public static int getsockopt (int s, SocketLevel level, int optname) { IntByReference ref; if (optname == SocketOption.SO_RCVTIMEO.intValue() || optname == SocketOption.SO_SNDTIMEO.intValue()) { DefaultNativeTimeval t = new DefaultNativeTimeval(Runtime.getSystemRuntime()); ref = new IntByReference(DefaultNativeTimeval.size(t)); Native.libsocket().getsockopt(s, level.intValue(), optname, t, ref); return (t.tv_sec.intValue() * 1000 + t.tv_usec.intValue() / 1000); } else { ByteBuffer buf = ByteBuffer.allocate(4); buf.order(ByteOrder.nativeOrder()); ref = new IntByReference(4); Native.libsocket().getsockopt(s, level.intValue(), optname, buf, ref); return buf.getInt(); } }
static SocketLevel levelFromArg(IRubyObject level) { IRubyObject maybeString = TypeConverter.checkStringType(level.getRuntime(), level); if (!maybeString.isNil()) { level = maybeString; } try { if (level instanceof RubyString || level instanceof RubySymbol) { String levelString = level.toString(); if(levelString.startsWith("SOL_")) return SocketLevel.valueOf(levelString); return SocketLevel.valueOf("SOL_" + levelString); } return SocketLevel.valueOf(RubyNumeric.fix2int(level)); } catch (IllegalArgumentException iae) { throw SocketUtils.sockerr(level.getRuntime(), "invalid socket level: " + level); } }
public static int getsockopt(int s, SocketLevel level, SocketOption optname, Struct data) { Pointer struct_ptr = Struct.getMemory(data); IntByReference ref = new IntByReference(Struct.size(data)); ByteBuffer buf = ByteBuffer.wrap((byte[])struct_ptr.array()); return Native.libsocket().getsockopt(s, level.intValue(), optname.intValue(), buf, ref); }