mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
ext/socket/ancdata.c (bsock_recvmsg_internal): reduce stack use
Using 8K stack is probably too much. As reference, ALLOCV falls back to heap allocation at a mere 1K. Since bsock_recvmsg_internal is a function which will always allocate and can trigger GC, it is in our best interest to minimize stack usage to avoid scanning 8K of stack on GC. [ruby-core:69595] [Feature #11263] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c23a7b0db8
commit
d9d1b20d39
2 changed files with 18 additions and 25 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Wed Jun 24 08:28:15 2015 Eric Wong <e@80x24.org>
|
||||||
|
|
||||||
|
* ext/socket/ancdata.c (bsock_recvmsg_internal): reduce stack use
|
||||||
|
[ruby-core:69595] [Feature #11263]
|
||||||
|
|
||||||
Tue Jun 23 14:32:42 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Jun 23 14:32:42 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* error.c (name_err_receiver): raise ArgumentError if no receiver
|
* error.c (name_err_receiver): raise ArgumentError if no receiver
|
||||||
|
|
|
@ -1498,7 +1498,7 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
|
||||||
struct msghdr mh;
|
struct msghdr mh;
|
||||||
struct iovec iov;
|
struct iovec iov;
|
||||||
union_sockaddr namebuf;
|
union_sockaddr namebuf;
|
||||||
char datbuf0[4096], *datbuf;
|
char *datbuf;
|
||||||
VALUE dat_str = Qnil;
|
VALUE dat_str = Qnil;
|
||||||
VALUE ret;
|
VALUE ret;
|
||||||
ssize_t ss;
|
ssize_t ss;
|
||||||
|
@ -1506,10 +1506,6 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
|
||||||
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
|
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
|
||||||
struct cmsghdr *cmh;
|
struct cmsghdr *cmh;
|
||||||
size_t maxctllen;
|
size_t maxctllen;
|
||||||
union {
|
|
||||||
char bytes[4096];
|
|
||||||
struct cmsghdr align;
|
|
||||||
} ctlbuf0;
|
|
||||||
char *ctlbuf;
|
char *ctlbuf;
|
||||||
VALUE ctl_str = Qnil;
|
VALUE ctl_str = Qnil;
|
||||||
int family;
|
int family;
|
||||||
|
@ -1519,9 +1515,9 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "03:", &vmaxdatlen, &vflags, &vmaxctllen, &vopts);
|
rb_scan_args(argc, argv, "03:", &vmaxdatlen, &vflags, &vmaxctllen, &vopts);
|
||||||
|
|
||||||
maxdatlen = NIL_P(vmaxdatlen) ? sizeof(datbuf0) : NUM2SIZET(vmaxdatlen);
|
maxdatlen = NIL_P(vmaxdatlen) ? 4096 : NUM2SIZET(vmaxdatlen);
|
||||||
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
|
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
|
||||||
maxctllen = NIL_P(vmaxctllen) ? sizeof(ctlbuf0) : NUM2SIZET(vmaxctllen);
|
maxctllen = NIL_P(vmaxctllen) ? 4096 : NUM2SIZET(vmaxctllen);
|
||||||
#else
|
#else
|
||||||
if (!NIL_P(vmaxctllen))
|
if (!NIL_P(vmaxctllen))
|
||||||
rb_raise(rb_eArgError, "control message not supported");
|
rb_raise(rb_eArgError, "control message not supported");
|
||||||
|
@ -1561,26 +1557,18 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
retry:
|
retry:
|
||||||
if (maxdatlen <= sizeof(datbuf0))
|
if (NIL_P(dat_str))
|
||||||
datbuf = datbuf0;
|
dat_str = rb_str_tmp_new(maxdatlen);
|
||||||
else {
|
else
|
||||||
if (NIL_P(dat_str))
|
rb_str_resize(dat_str, maxdatlen);
|
||||||
dat_str = rb_str_tmp_new(maxdatlen);
|
datbuf = RSTRING_PTR(dat_str);
|
||||||
else
|
|
||||||
rb_str_resize(dat_str, maxdatlen);
|
|
||||||
datbuf = RSTRING_PTR(dat_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
|
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
|
||||||
if (maxctllen <= sizeof(ctlbuf0))
|
if (NIL_P(ctl_str))
|
||||||
ctlbuf = ctlbuf0.bytes;
|
ctl_str = rb_str_tmp_new(maxctllen);
|
||||||
else {
|
else
|
||||||
if (NIL_P(ctl_str))
|
rb_str_resize(ctl_str, maxctllen);
|
||||||
ctl_str = rb_str_tmp_new(maxctllen);
|
ctlbuf = RSTRING_PTR(ctl_str);
|
||||||
else
|
|
||||||
rb_str_resize(ctl_str, maxctllen);
|
|
||||||
ctlbuf = RSTRING_PTR(ctl_str);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
memset(&mh, 0, sizeof(mh));
|
memset(&mh, 0, sizeof(mh));
|
||||||
|
|
Loading…
Reference in a new issue