Method: Socket::Option.byte

Defined in:
option.c

.Socket::Option.byte(family, level, optname, integer) ⇒ Object

Creates a new Socket::Option object which contains a byte as data.

The size and endian is dependent on the platform.

p Socket::Option.byte(:INET, :SOCKET, :KEEPALIVE, 1)
#=> #<Socket::Option: INET SOCKET KEEPALIVE 1>


156
157
158
159
160
161
162
163
164
# File 'option.c', line 156

static VALUE
sockopt_s_byte(VALUE klass, VALUE vfamily, VALUE vlevel, VALUE voptname, VALUE vint)
{
    int family = rsock_family_arg(vfamily);
    int level = rsock_level_arg(family, vlevel);
    int optname = rsock_optname_arg(family, level, voptname);
    unsigned char i = (unsigned char)NUM2CHR(vint);
    return rsock_sockopt_new(family, level, optname, rb_str_new((char*)&i, sizeof(i)));
}