rainbows.git  about / heads / tags
Unicorn for sleepy apps and slow clients
blob c67bf203c5ed16814f97e969418fcdd8be567bd6 660 bytes (raw)
$ git show v0.97.0:lib/rainbows/acceptor.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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

git clone https://yhbt.net/rainbows.git