diff options
author | Eric Wong <e@yhbt.net> | 2010-08-25 13:58:11 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-08-26 08:47:36 +0000 |
commit | 47e1ee2d90161abf92ce14562bf508398fdfa6c9 (patch) | |
tree | d4fb816d9874ec0b0bdfd285e9ca10e4f17d0227 /lib/rainbows/acceptor.rb | |
parent | bd3ed0b04f826b20cce83f9b77fc13c0eefd3902 (diff) | |
download | rainbows-47e1ee2d90161abf92ce14562bf508398fdfa6c9.tar.gz |
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.
Diffstat (limited to 'lib/rainbows/acceptor.rb')
-rw-r--r-- | lib/rainbows/acceptor.rb | 26 |
1 files changed, 26 insertions, 0 deletions
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 |