Sha256: a77f6df4b516377ddf36756ddf927aeb6ed95512382337283742330e25eb10f0

Contents?: true

Size: 1.23 KB

Versions: 11

Compression:

Stored size: 1.23 KB

Contents

# -*- encoding: binary -*-
# :enddoc:

module Rainbows::XEpoll::Client
  N = Raindrops.new(1)
  include Rainbows::Epoll::Client
  ACCEPTORS = Rainbows::HttpServer::LISTENERS.dup
  extend Rainbows::WorkerYield

  def self.included(klass)
    max = Rainbows.server.worker_connections
    ACCEPTORS.map! do |sock|
      Thread.new do
        begin
          if io = sock.kgio_accept(klass)
            N.incr(0, 1)
            io.epoll_once
          end
          worker_yield while N[0] >= max
        rescue => e
          Rainbows::Error.listen_loop(e)
        end while Rainbows.alive
      end
    end
  end

  def self.loop
    begin
      EP.wait(nil, 1000) { |_, obj| obj.epoll_run }
      while obj = ReRun.shift
        obj.epoll_run
      end
      Rainbows::Epoll::Client.expire
    rescue Errno::EINTR
    rescue => e
      Rainbows::Error.listen_loop(e)
    end while Rainbows.tick || N[0] > 0
    Rainbows::JoinThreads.acceptors(ACCEPTORS)
  end

  # only call this once
  def epoll_once
    @wr_queue = [] # may contain String, ResponsePipe, and StreamFile objects
    post_init
    EP.set(self, IN) # wake up the main thread
    rescue => e
      Rainbows::Error.write(self, e)
  end

  def on_close
    KATO.delete(self)
    N.decr(0, 1)
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rainbows-4.4.3 lib/rainbows/xepoll/client.rb
rainbows-4.4.2 lib/rainbows/xepoll/client.rb
rainbows-4.4.1.1.gd5c8c lib/rainbows/xepoll/client.rb
rainbows-4.4.1 lib/rainbows/xepoll/client.rb
rainbows-4.4.0 lib/rainbows/xepoll/client.rb
rainbows-4.3.1 lib/rainbows/xepoll/client.rb
rainbows-4.3.0 lib/rainbows/xepoll/client.rb
rainbows-4.2.0 lib/rainbows/xepoll/client.rb
rainbows-4.1.0 lib/rainbows/xepoll/client.rb
rainbows-4.0.0 lib/rainbows/xepoll/client.rb
rainbows-3.4.0 lib/rainbows/xepoll/client.rb