From 2624da2e5ed0e1edbbb902c717031dd2ffa9a36a Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 22 May 2006 22:12:57 +0000 Subject: avoid useless fcntl in rb_io_set_nonblock. git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@10180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index 228149df8..8fc095758 100644 --- a/io.c +++ b/io.c @@ -1196,9 +1196,11 @@ void rb_io_set_nonblock(OpenFile *fptr) #else flags = 0; #endif - flags |= O_NONBLOCK; - if (fcntl(fileno(fptr->f), F_SETFL, flags) == -1) { - rb_sys_fail(fptr->path); + if ((flags & O_NONBLOCK) == 0) { + flags |= O_NONBLOCK; + if (fcntl(fileno(fptr->f), F_SETFL, flags) == -1) { + rb_sys_fail(fptr->path); + } } if (fptr->f2) { #ifdef F_GETFL @@ -1209,9 +1211,11 @@ void rb_io_set_nonblock(OpenFile *fptr) #else flags = 0; #endif - flags |= O_NONBLOCK; - if (fcntl(fileno(fptr->f2), F_SETFL, flags) == -1) { - rb_sys_fail(fptr->path); + if ((flags & O_NONBLOCK) == 0) { + flags |= O_NONBLOCK; + if (fcntl(fileno(fptr->f2), F_SETFL, flags) == -1) { + rb_sys_fail(fptr->path); + } } } } -- cgit