Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method
Socket::Option#linger
sockopt.linger => [bool, seconds]
ext/socket/option.c
View on GitHub ↗
static VALUE
sockopt_linger(VALUE self)
{
int level = sockopt_level(self);
int optname = sockopt_optname(self);
VALUE data = sockopt_data(self);
struct linger l;
VALUE vonoff, vsecs;
if (level != SOL_SOCKET || optname != SO_LINGER)
rb_raise(rb_eTypeError, "linger socket option expected");
check_size(RSTRING_LEN(data), sizeof(struct linger));
memcpy((char*)&l, RSTRING_PTR(data), sizeof(struct linger));
switch (l.l_onoff) {
case 0: vonoff = Qfalse; break;
case 1: vonoff = Qtrue; break;
default: vonoff = INT2NUM(l.l_onoff); break;
}
vsecs = INT2NUM(l.l_linger);
return rb_assoc_new(vonoff, vsecs);
}
Returns the linger data in sockopt as a pair of boolean and integer.
Example
sockopt = Socket::Option.linger(true, 10) p sockopt.linger => [true, 10]