Method: Socket::Option#int

Defined in:
option.c

#intInteger

Returns the data in sockopt as an int.

The size and endian is dependent on the platform.

sockopt = Socket::Option.int(:INET, :SOCKET, :KEEPALIVE, 1)
p sockopt.int => 1

Returns:

  • (Integer)


257
258
259
260
261
262
263
264
265
266
# File 'option.c', line 257

static VALUE
sockopt_int(VALUE self)
{
    int i;
    VALUE data = sockopt_data(self);
    StringValue(data);
    check_size(RSTRING_LEN(data), sizeof(int));
    memcpy((char*)&i, RSTRING_PTR(data), sizeof(int));
    return INT2NUM(i);
}