mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/socket/ancdata.c (discard_cmsg_resource): new function to close
file descriptors in control message. (bsock_recvmsg_internal): call discard_cmsg_resource before retrying recvmsg. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
f1a39b9e5c
commit
75ba47e8e8
2 changed files with 31 additions and 0 deletions
|
@ -1,3 +1,10 @@
|
|||
Wed Feb 18 22:47:01 2009 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/socket/ancdata.c (discard_cmsg_resource): new function to close
|
||||
file descriptors in control message.
|
||||
(bsock_recvmsg_internal): call discard_cmsg_resource before retrying
|
||||
recvmsg.
|
||||
|
||||
Wed Feb 18 21:47:37 2009 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/socket/ancdata.c (bsock_recvmsg_internal): prevent misalignment.
|
||||
|
|
|
@ -1099,6 +1099,28 @@ rb_recvmsg(int fd, struct msghdr *msg, int flags)
|
|||
return rb_thread_blocking_region(nogvl_recvmsg_func, &args, RUBY_UBF_IO, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
discard_cmsg_resource(struct msghdr *mh)
|
||||
{
|
||||
#if defined(HAVE_ST_MSG_CONTROL)
|
||||
struct cmsghdr *cmh;
|
||||
|
||||
if (mh->msg_controllen == 0)
|
||||
return;
|
||||
|
||||
for (cmh = CMSG_FIRSTHDR(mh); cmh != NULL; cmh = CMSG_NXTHDR(mh, cmh)) {
|
||||
if (cmh->cmsg_level == SOL_SOCKET && cmh->cmsg_type == SCM_RIGHTS) {
|
||||
int *fdp = (int *)CMSG_DATA(cmh);
|
||||
int *end = (int *)((char *)cmh + cmh->cmsg_len);
|
||||
while (fdp < end) {
|
||||
close(*fdp);
|
||||
fdp++;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static VALUE
|
||||
bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
|
||||
{
|
||||
|
@ -1232,12 +1254,14 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
|
|||
}
|
||||
#endif
|
||||
if (grown) {
|
||||
discard_cmsg_resource(&mh);
|
||||
goto retry;
|
||||
}
|
||||
else {
|
||||
grow_buffer = 0;
|
||||
if (flags != orig_flags) {
|
||||
flags = orig_flags;
|
||||
discard_cmsg_resource(&mh);
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue