mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-socket/socket.c: implement Socket::Option#initialize in C
This commit is contained in:
@@ -576,13 +576,6 @@ end
|
||||
|
||||
class Socket
|
||||
class Option
|
||||
def initialize(family, level, optname, data)
|
||||
@family = family
|
||||
@level = level
|
||||
@optname = optname
|
||||
@data = data
|
||||
end
|
||||
|
||||
def self.bool(family, level, optname, bool)
|
||||
self.new(family, level, optname, [(bool ? 1 : 0)].pack('i'))
|
||||
end
|
||||
|
||||
@@ -333,6 +333,20 @@ socket_option_class(mrb_state *mrb)
|
||||
return mrb_class_get_under_id(mrb, mrb_class_get_id(mrb, MRB_SYM(Socket)), MRB_SYM(Option));
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
socket_option_init(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
mrb_value family, level, optname, data;
|
||||
|
||||
mrb_get_args(mrb, "oooo", &family, &level, &optname, &data);
|
||||
mrb_iv_set(mrb, self, MRB_IVSYM(family), family);
|
||||
mrb_iv_set(mrb, self, MRB_IVSYM(level), level);
|
||||
mrb_iv_set(mrb, self, MRB_IVSYM(optname), optname);
|
||||
mrb_iv_set(mrb, self, MRB_IVSYM(data), data);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static mrb_value
|
||||
mrb_basicsocket_getsockopt(mrb_state *mrb, mrb_value self)
|
||||
{
|
||||
@@ -859,7 +873,7 @@ void
|
||||
mrb_mruby_socket_gem_init(mrb_state* mrb)
|
||||
{
|
||||
struct RClass *io, *ai, *sock, *bsock, *ipsock, *tcpsock;
|
||||
struct RClass *constants;
|
||||
struct RClass *constants, *option;
|
||||
|
||||
#ifdef _WIN32
|
||||
WSADATA wsaData;
|
||||
@@ -943,6 +957,9 @@ mrb_mruby_socket_gem_init(mrb_state* mrb)
|
||||
mrb_define_method(mrb, bsock, "write", mrb_win32_basicsocket_syswrite, MRB_ARGS_REQ(1));
|
||||
#endif
|
||||
|
||||
option = mrb_define_class_under(mrb, sock, "Option", mrb->object_class);
|
||||
mrb_define_method(mrb, option, "initialize", socket_option_init, MRB_ARGS_REQ(4));
|
||||
|
||||
constants = mrb_define_module_under(mrb, sock, "Constants");
|
||||
|
||||
#define define_const(SYM) \
|
||||
|
||||
Reference in New Issue
Block a user