From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS46457 204.124.83.0/24 X-Spam-Status: No, score=-1.0 required=3.0 tests=AWL,BAYES_00, RCVD_IN_BRBL_LASTEXT,RCVD_IN_XBL shortcircuit=no autolearn=no version=3.3.2 X-Original-To: spew@80x24.org Received: from 80x24.org (tor-exit0.conformal.com [204.124.83.130]) by dcvr.yhbt.net (Postfix) with ESMTP id 798751FA7B for ; Mon, 11 May 2015 20:17:39 +0000 (UTC) From: Eric Wong To: spew@80x24.org Subject: [PATCH 1/3] lib/webrick/utils.rb: simplify by avoiding fcntl Date: Mon, 11 May 2015 20:17:30 +0000 Message-Id: <1431375452-6061-1-git-send-email-e@80x24.org> List-Id: IO#nonblock= and IO#close_on_exec= methods are simpler-to-use and potentially more portable to for future OSes. IO#nonblock= and IO#close_on_exec= are also smart enough to avoid redundantly setting flags so a syscall may be avoided. These methods could probably be removed entirely and inlined, but it's unclear if there is 3rd-party code which relies on them. * lib/webrick/utils.rb (set_non_blocking): use IO#nonblock= * (set_close_on_exec): use IO#close_on_exec= --- lib/webrick/utils.rb | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb index 5be4db8..bde3d01 100644 --- a/lib/webrick/utils.rb +++ b/lib/webrick/utils.rb @@ -9,7 +9,7 @@ # $IPR: utils.rb,v 1.10 2003/02/16 22:22:54 gotoyuzo Exp $ require 'socket' -require 'fcntl' +require 'io/nonblock' require 'etc' module WEBrick @@ -17,20 +17,14 @@ module WEBrick ## # Sets IO operations on +io+ to be non-blocking def set_non_blocking(io) - flag = File::NONBLOCK - if defined?(Fcntl::F_GETFL) - flag |= io.fcntl(Fcntl::F_GETFL) - end - io.fcntl(Fcntl::F_SETFL, flag) + io.nonblock = true if io.respond_to?(:nonblock=) end module_function :set_non_blocking ## # Sets the close on exec flag for +io+ def set_close_on_exec(io) - if defined?(Fcntl::FD_CLOEXEC) - io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) - end + io.close_on_exec = true if io.respond_to?(:close_on_exec=) end module_function :set_close_on_exec -- EW