Project

General

Profile

Actions

Feature #11136

closed

[PATCH] webrick: avoid fcntl module

Added by normalperson (Eric Wong) almost 9 years ago. Updated almost 9 years ago.

Status:
Closed
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) almost 9 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) almost 9 years ago

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) almost 9 years ago

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

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.

Actions #4

Updated by Anonymous almost 9 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]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0