From 47e1ee2d90161abf92ce14562bf508398fdfa6c9 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 25 Aug 2010 13:58:11 -0700 Subject: split out accept() callers to acceptor module Trying to avoid adding singleton methods since it's too easily accessible by the public and not needed by the general public. This also allows us (or just Zbatery) to more easily add support systems without FD_CLOEXEC or fcntl, and also to optimize away a fcntl call for systems that inherit FD_CLOEXEC. --- lib/rainbows/acceptor.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 lib/rainbows/acceptor.rb (limited to 'lib/rainbows/acceptor.rb') diff --git a/lib/rainbows/acceptor.rb b/lib/rainbows/acceptor.rb new file mode 100644 index 0000000..c67bf20 --- /dev/null +++ b/lib/rainbows/acceptor.rb @@ -0,0 +1,26 @@ +# -*- encoding: binary -*- + +# :enddoc: +require 'fcntl' + +# this should make life easier for Zbatery if compatibility with +# fcntl-crippled platforms is required (or if FD_CLOEXEC is inherited) +# and we want to microptimize away fcntl(2) syscalls. +module Rainbows::Acceptor + + # returns nil if accept fails + def sync_accept(sock) + rv = sock.accept + rv.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) + rv + rescue Errno::EAGAIN, Errno::ECONNABORTED, Errno::EINTR + end + + # returns nil if accept fails + def accept(sock) + rv = sock.accept_nonblock + rv.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) + rv + rescue Errno::EAGAIN, Errno::ECONNABORTED + end +end -- cgit v1.2.3-24-ge0c7