* [PATCH 1/3] lib/webrick/utils.rb: simplify by avoiding fcntl
@ 2015-05-11 20:17 Eric Wong
2015-05-11 20:17 ` [PATCH 2/3] lib/drb/*.rb: avoid redundant fcntl call Eric Wong
2015-05-11 20:17 ` [PATCH 3/3] lib/webrick/server.rb: " Eric Wong
0 siblings, 2 replies; 3+ messages in thread
From: Eric Wong @ 2015-05-11 20:17 UTC (permalink / raw)
To: spew
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/3] lib/drb/*.rb: avoid redundant fcntl call
2015-05-11 20:17 [PATCH 1/3] lib/webrick/utils.rb: simplify by avoiding fcntl Eric Wong
@ 2015-05-11 20:17 ` Eric Wong
2015-05-11 20:17 ` [PATCH 3/3] lib/webrick/server.rb: " Eric Wong
1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2015-05-11 20:17 UTC (permalink / raw)
To: spew
Sockets are close-on-exec by default since Ruby 2.0, so it
is redundant to set it again.
---
lib/drb/drb.rb | 2 --
lib/drb/unix.rb | 2 +-
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/lib/drb/drb.rb b/lib/drb/drb.rb
index 32e5bfb..456d0fb 100644
--- a/lib/drb/drb.rb
+++ b/lib/drb/drb.rb
@@ -47,7 +47,6 @@
require 'socket'
require 'thread'
-require 'fcntl'
require 'io/wait'
require 'drb/eq'
@@ -1013,7 +1012,6 @@ module DRb
def set_sockopt(soc) # :nodoc:
soc.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
- soc.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
end
end
diff --git a/lib/drb/unix.rb b/lib/drb/unix.rb
index 3fb8d0e..637ea7c 100644
--- a/lib/drb/unix.rb
+++ b/lib/drb/unix.rb
@@ -108,7 +108,7 @@ module DRb
end
def set_sockopt(soc)
- soc.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) if defined? Fcntl::FD_CLOEXEC
+ # no-op for now
end
end
--
EW
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 3/3] lib/webrick/server.rb: avoid redundant fcntl call
2015-05-11 20:17 [PATCH 1/3] lib/webrick/utils.rb: simplify by avoiding fcntl Eric Wong
2015-05-11 20:17 ` [PATCH 2/3] lib/drb/*.rb: avoid redundant fcntl call Eric Wong
@ 2015-05-11 20:17 ` Eric Wong
1 sibling, 0 replies; 3+ messages in thread
From: Eric Wong @ 2015-05-11 20:17 UTC (permalink / raw)
To: spew
Sockets are close-on-exec by default since Ruby 2.0, so it
is redundant to set it again.
---
lib/webrick/server.rb | 1 -
1 file changed, 1 deletion(-)
diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb
index 815375f..5ada88a 100644
--- a/lib/webrick/server.rb
+++ b/lib/webrick/server.rb
@@ -263,7 +263,6 @@ module WEBrick
sock = svr.accept
sock.sync = true
Utils::set_non_blocking(sock)
- Utils::set_close_on_exec(sock)
rescue Errno::ECONNRESET, Errno::ECONNABORTED,
Errno::EPROTO, Errno::EINVAL
rescue StandardError => ex
--
EW
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-05-11 20:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-11 20:17 [PATCH 1/3] lib/webrick/utils.rb: simplify by avoiding fcntl Eric Wong
2015-05-11 20:17 ` [PATCH 2/3] lib/drb/*.rb: avoid redundant fcntl call Eric Wong
2015-05-11 20:17 ` [PATCH 3/3] lib/webrick/server.rb: " Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).