From 78ea7afe97241b7a8a8176f680865430779e7d68 Mon Sep 17 00:00:00 2001 From: kosaki Date: Mon, 4 Apr 2011 13:11:14 +0000 Subject: * ext/io/nonblock/nonblock.c (io_nonblock_set): Avoid F_SETFL if we're not changing the O_NONBLOCK bit. F_SETFL is an expensive operation since it needs to affect all processes with the same file object. The patch is written by Eric Wong. [ruby-core:35556] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/io/nonblock/nonblock.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'ext/io') diff --git a/ext/io/nonblock/nonblock.c b/ext/io/nonblock/nonblock.c index d7e1ac8e01..1d866ceb0f 100644 --- a/ext/io/nonblock/nonblock.c +++ b/ext/io/nonblock/nonblock.c @@ -47,10 +47,16 @@ rb_io_nonblock_p(VALUE io) static void io_nonblock_set(int fd, int f, int nb) { - if (nb) + if (nb) { + if ((f & O_NONBLOCK) != 0) + return; f |= O_NONBLOCK; - else + } + else { + if ((f & O_NONBLOCK) == 0) + return; f &= ~O_NONBLOCK; + } if (fcntl(fd, F_SETFL, f) == -1) rb_sys_fail(0); } -- cgit v1.2.3