From ad2f293d4fb1df2b78649e649feb41ed48913998 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 21 Feb 2009 16:49:44 +0000 Subject: [PATCH] * ext/socket/ancdata.c (bsock_recvmsg_internal): gc when SCM_RIGHTS hit the file descriptor limit. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22487 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/socket/ancdata.c | 26 ++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index e20c73f3d2..481394ee82 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Feb 22 01:48:51 2009 Tanaka Akira + + * ext/socket/ancdata.c (bsock_recvmsg_internal): gc when SCM_RIGHTS + hit the file descriptor limit. + Sun Feb 22 00:51:58 2009 Tanaka Akira * io.c (io_getpartial): error message describes what should be diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c index f7763e90a0..5afd3d66e2 100644 --- a/ext/socket/ancdata.c +++ b/ext/socket/ancdata.c @@ -1202,6 +1202,7 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock) char *ctlbuf; VALUE ctl_str = Qnil; int family; + int gc_done = 0; #endif rb_secure(4); @@ -1296,6 +1297,16 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock) if (ss == -1) { if (nonblock && errno == EWOULDBLOCK) rb_sys_fail("recvmsg(2) WANT_READ"); +#if defined(HAVE_ST_MSG_CONTROL) + if (errno == EMFILE && !gc_done) { + /* SCM_RIGHTS hit the file descriptors limit, maybe. */ + gc_and_retry: + discard_cmsg_resource(&mh); + rb_gc(); + gc_done = 1; + goto retry; + } +#endif rb_sys_fail("recvmsg(2)"); } @@ -1307,8 +1318,19 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock) grown = 1; } if (NIL_P(vmaxctllen) && (mh.msg_flags & MSG_CTRUNC)) { - maxctllen *= 2; - grown = 1; +#define BIG_ENOUGH_SPACE 65536 + if (BIG_ENOUGH_SPACE < maxctllen && + mh.msg_controllen < maxctllen - BIG_ENOUGH_SPACE) { + /* there are big space bug truncated. + * file descriptors limit? */ + if (!gc_done) + goto gc_and_retry; + } + else { + maxctllen *= 2; + grown = 1; + } +#undef BIG_ENOUGH_SPACE } #else if (NIL_P(vmaxdatlen) && ss != -1 && ss == iov.iov_len) {