Project

General

Profile

Feature #11136

[PATCH] webrick: avoid fcntl module

Added by normalperson (Eric Wong) about 5 years ago. Updated about 5 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:69126]

Description

lib/webrick/utils.rb: simplify by avoiding fcntl

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=

Note: next commit will remove the set_close_on_exec call.


Files

Updated by nobu (Nobuyoshi Nakada) about 5 years ago

After requiring 'io/nonblock', no needs to see if nonblock= method is available.
And IO#close_on_exec= is older than IO#nonblock=.

Updated by normalperson (Eric Wong) about 5 years ago

nobu@ruby-lang.org wrote:

After requiring 'io/nonblock', no needs to see if nonblock= method is available.

Doesn't that raise NotImplementedError on some platforms?

I see this in ext/io/nonblock/nonblock.c:

#define rb_io_nonblock_set rb_f_notimplement

I'm not sure which platforms, though, maybe Windows?

And IO#close_on_exec= is older than IO#nonblock=.

I remember using IO#nonblock= in 1.8 (was pure Ruby, then), but not
IO#close_on_exec=

Updated by nobu (Nobuyoshi Nakada) about 5 years ago

On 2015/05/12 12:57, Eric Wong wrote:

nobu@ruby-lang.org wrote:

After requiring 'io/nonblock', no needs to see if nonblock= method is available.

Doesn't that raise NotImplementedError on some platforms?

I see this in ext/io/nonblock/nonblock.c:

#define rb_io_nonblock_set rb_f_notimplement

Indeed. I've forgotten it, sorry.

I'm not sure which platforms, though, maybe Windows?

Non-blocking flag works on Windows.

#4

Updated by Anonymous about 5 years ago

  • Status changed from Open to Closed

Applied in changeset r50523.


lib/webrick/utils.rb: simplify by avoiding fcntl

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= [Feature #11136]

Also available in: Atom PDF