static VALUE t_set_sock_opt (VALUE self, VALUE signature, VALUE lev, VALUE optname, VALUE optval) { int fd = evma_get_file_descriptor (NUM2ULONG (signature)); int level = NUM2INT(lev), option = NUM2INT(optname); int i; const void *v; socklen_t len; switch (TYPE(optval)) { case T_FIXNUM: i = FIX2INT(optval); goto numval; case T_FALSE: i = 0; goto numval; case T_TRUE: i = 1; numval: v = (void*)&i; len = sizeof(i); break; default: StringValue(optval); v = RSTRING_PTR(optval); len = RSTRING_LENINT(optval); break; } if (setsockopt(fd, level, option, (char *)v, len) < 0) rb_sys_fail("setsockopt"); return INT2FIX(0); }
static VALUE t_get_sock_opt (VALUE self, VALUE signature, VALUE lev, VALUE optname) { int fd = evma_get_file_descriptor (NUM2ULONG (signature)); int level = NUM2INT(lev), option = NUM2INT(optname); socklen_t len = 128; char buf[128]; if (getsockopt(fd, level, option, buf, &len) < 0) rb_sys_fail("getsockopt"); return rb_str_new(buf, len); }
/********************* t_get_file_descriptor *********************/ static VALUE t_get_file_descriptor (VALUE self, VALUE signature) { return INT2NUM(evma_get_file_descriptor (NUM2ULONG (signature))); }
/********************* t_get_file_descriptor *********************/ static VALUE t_get_file_descriptor (VALUE self UNUSED, VALUE signature) { return INT2NUM(evma_get_file_descriptor (NUM2BSIG (signature))); }