Sha256: 8615d6717832a86b7f45a1894bb475b8b1f20ddafd0d3506e2cac49b2b44374b

Contents?: true

Size: 835 Bytes

Versions: 3

Compression:

Stored size: 835 Bytes

Contents

# -*- encoding: binary -*-
# :enddoc:
module Rainbows::Epoll::Server
  @@nr = 0
  Rainbows::Epoll.nr_clients = lambda { @@nr }
  IN = SleepyPenguin::Epoll::IN | SleepyPenguin::Epoll::ET
  MAX = Rainbows.server.worker_connections
  THRESH = MAX - 1
  LISTENERS = Rainbows::HttpServer::LISTENERS
  EP = Rainbows::Epoll::EP

  def self.run
    LISTENERS.each { |sock| EP.add(sock.extend(self), IN) }
    Rainbows::Epoll.loop
  end

  # rearms all listeners when there's a free slot
  def self.decr
    THRESH == (@@nr -= 1) and LISTENERS.each { |sock| EP.set(sock, IN) }
  end

  def epoll_run
    return EP.delete(self) if @@nr >= MAX
    while io = kgio_tryaccept
      @@nr += 1
      # there's a chance the client never even sees epoll for simple apps
      io.epoll_once
      return EP.delete(self) if @@nr >= MAX
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rainbows-3.3.0 lib/rainbows/epoll/server.rb
rainbows-3.2.0 lib/rainbows/epoll/server.rb
rainbows-3.1.0 lib/rainbows/epoll/server.rb