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
|
|
@ -71,8 +71,8 @@ static VALUE
|
|||
ancillary_initialize(VALUE self, VALUE vfamily, VALUE vlevel, VALUE vtype, VALUE data)
|
||||
{
|
||||
int family = family_arg(vfamily);
|
||||
int level = level_arg(vlevel);
|
||||
int type = cmsg_type_arg(level, vtype);
|
||||
int level = level_arg(family, vlevel);
|
||||
int type = cmsg_type_arg(family, level, vtype);
|
||||
StringValue(data);
|
||||
rb_ivar_set(self, rb_intern("family"), INT2NUM(family));
|
||||
rb_ivar_set(self, rb_intern("level"), INT2NUM(level));
|
||||
|
|
@ -190,8 +190,8 @@ static VALUE
|
|||
ancillary_s_int(VALUE klass, VALUE vfamily, VALUE vlevel, VALUE vtype, VALUE integer)
|
||||
{
|
||||
int family = family_arg(vfamily);
|
||||
int level = level_arg(vlevel);
|
||||
int type = cmsg_type_arg(level, vtype);
|
||||
int level = level_arg(family, vlevel);
|
||||
int type = cmsg_type_arg(family, level, vtype);
|
||||
int i = NUM2INT(integer);
|
||||
return ancdata_new(family, level, type, rb_str_new((char*)&i, sizeof(i)));
|
||||
}
|
||||
|
|
@ -686,8 +686,9 @@ ancillary_inspect(VALUE self)
|
|||
static VALUE
|
||||
ancillary_cmsg_is_p(VALUE self, VALUE vlevel, VALUE vtype)
|
||||
{
|
||||
int level = level_arg(vlevel);
|
||||
int type = cmsg_type_arg(level, vtype);
|
||||
int family = ancillary_family(self);
|
||||
int level = level_arg(family, vlevel);
|
||||
int type = cmsg_type_arg(family, level, vtype);
|
||||
|
||||
if (ancillary_level(self) == level &&
|
||||
ancillary_type(self) == type)
|
||||
|
|
@ -736,8 +737,11 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
|
|||
#endif
|
||||
int flags;
|
||||
ssize_t ss;
|
||||
int family;
|
||||
|
||||
rb_secure(4);
|
||||
GetOpenFile(sock, fptr);
|
||||
family = rb_sock_getfamily(fptr->fd);
|
||||
|
||||
data = vflags = dest_sockaddr = Qnil;
|
||||
controls_ptr = NULL;
|
||||
|
|
@ -779,8 +783,8 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
|
|||
vtype = rb_funcall(elt, rb_intern("type"), 0);
|
||||
cdata = rb_funcall(elt, rb_intern("data"), 0);
|
||||
}
|
||||
level = level_arg(vlevel);
|
||||
type = cmsg_type_arg(level, vtype);
|
||||
level = level_arg(family, vlevel);
|
||||
type = cmsg_type_arg(family, level, vtype);
|
||||
StringValue(cdata);
|
||||
oldlen = RSTRING_LEN(controls_str);
|
||||
cspace = CMSG_SPACE(RSTRING_LEN(cdata));
|
||||
|
|
@ -810,7 +814,7 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
|
|||
if (!NIL_P(dest_sockaddr))
|
||||
SockAddrStringValue(dest_sockaddr);
|
||||
|
||||
GetOpenFile(sock, fptr);
|
||||
rb_io_check_closed(fptr);
|
||||
|
||||
retry:
|
||||
memset(&mh, 0, sizeof(mh));
|
||||
|
|
@ -1093,15 +1097,13 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
|
|||
for (cmh = CMSG_FIRSTHDR(&mh); cmh != NULL; cmh = CMSG_NXTHDR(&mh, cmh)) {
|
||||
VALUE ctl;
|
||||
size_t clen;
|
||||
struct sockaddr_storage ss;
|
||||
socklen_t sslen = sizeof(ss);
|
||||
int family;
|
||||
if (cmh->cmsg_len == 0) {
|
||||
rb_raise(rb_eIOError, "invalid control message (cmsg_len == 0)");
|
||||
}
|
||||
ss.ss_family = AF_UNSPEC;
|
||||
getsockname(fptr->fd, (struct sockaddr*)&ss, &sslen);
|
||||
family = rb_sock_getfamily(fptr->fd);
|
||||
clen = (char*)cmh + cmh->cmsg_len - (char*)CMSG_DATA(cmh);
|
||||
ctl = ancdata_new(ss.ss_family, cmh->cmsg_level, cmh->cmsg_type, rb_tainted_str_new((char*)CMSG_DATA(cmh), clen));
|
||||
ctl = ancdata_new(family, cmh->cmsg_level, cmh->cmsg_type, rb_tainted_str_new((char*)CMSG_DATA(cmh), clen));
|
||||
rb_ary_push(ret, ctl);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue