mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/socket/rubysocket.h (level_arg): add family argument.
(optname_arg): ditto. (cmsg_type_arg): ditto. (rb_sock_getfamily): declared. * ext/socket/constants.c (level_arg): add family argument. (optname_arg): ditto. (cmsg_type_arg): ditto. * ext/socket/init.c (rb_sock_getfamily): defined. * ext/socket/option.c (sockopt_initialize): give family for level_arg and optname_arg. (sockopt_s_int): ditto. * ext/socket/basicsocket.c (bsock_setsockopt): ditto. (bsock_getsockopt): ditto. * ext/socket/ancdata.c (ancillary_initialize): ditto. (ancillary_s_int): ditto. (ancillary_cmsg_is_p): ditto. (bsock_sendmsg_internal): ditto. (bsock_recvmsg_internal): use rb_sock_getfamily. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22184 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2092fbcc3a
commit
f5da7031b9
7 changed files with 85 additions and 44 deletions
|
@ -195,7 +195,7 @@ static VALUE
|
|||
bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
|
||||
{
|
||||
VALUE lev, optname, val;
|
||||
int level, option;
|
||||
int family, level, option;
|
||||
rb_io_t *fptr;
|
||||
int i;
|
||||
char *v;
|
||||
|
@ -211,8 +211,10 @@ bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
|
|||
}
|
||||
|
||||
rb_secure(2);
|
||||
level = level_arg(lev);
|
||||
option = optname_arg(level, optname);
|
||||
GetOpenFile(sock, fptr);
|
||||
family = rb_sock_getfamily(fptr->fd);
|
||||
level = level_arg(family, lev);
|
||||
option = optname_arg(family, level, optname);
|
||||
|
||||
switch (TYPE(val)) {
|
||||
case T_FIXNUM:
|
||||
|
@ -235,7 +237,7 @@ bsock_setsockopt(int argc, VALUE *argv, VALUE sock)
|
|||
|
||||
#define rb_sys_fail_path(path) rb_sys_fail(NIL_P(path) ? 0 : RSTRING_PTR(path))
|
||||
|
||||
GetOpenFile(sock, fptr);
|
||||
rb_io_check_closed(fptr);
|
||||
if (setsockopt(fptr->fd, level, option, v, vlen) < 0)
|
||||
rb_sys_fail_path(fptr->pathv);
|
||||
|
||||
|
@ -290,24 +292,21 @@ bsock_getsockopt(VALUE sock, VALUE lev, VALUE optname)
|
|||
socklen_t len;
|
||||
char *buf;
|
||||
rb_io_t *fptr;
|
||||
struct sockaddr_storage ss;
|
||||
socklen_t sslen = sizeof(ss);
|
||||
int family;
|
||||
|
||||
level = level_arg(lev);
|
||||
option = optname_arg(level, optname);
|
||||
GetOpenFile(sock, fptr);
|
||||
family = rb_sock_getfamily(fptr->fd);
|
||||
level = level_arg(family, lev);
|
||||
option = optname_arg(family, level, optname);
|
||||
len = 256;
|
||||
buf = ALLOCA_N(char,len);
|
||||
|
||||
GetOpenFile(sock, fptr);
|
||||
|
||||
ss.ss_family = AF_UNSPEC;
|
||||
if (getsockname(fptr->fd, (struct sockaddr*)&ss, &sslen) < 0)
|
||||
rb_sys_fail("getsockname(2)");
|
||||
rb_io_check_closed(fptr);
|
||||
|
||||
if (getsockopt(fptr->fd, level, option, buf, &len) < 0)
|
||||
rb_sys_fail_path(fptr->pathv);
|
||||
|
||||
return sockopt_new(ss.ss_family, level, option, rb_str_new(buf, len));
|
||||
return sockopt_new(family, level, option, rb_str_new(buf, len));
|
||||
#else
|
||||
rb_notimplement();
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue