Sha256: 771124e48948503e2279613eb46c57deabd4bed84708d9dd8371e6b49f12bcf8

Contents?: true

Size: 1.07 KB

Versions: 6

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

require "socket"
require "nio/version"

# New I/O for Ruby
module NIO
  # NIO implementation, one of the following (as a string):
  # * select: in pure Ruby using Kernel.select
  # * libev: as a C extension using libev
  # * java: using Java NIO
  def self.engine
    ENGINE
  end

  def self.pure?(env = ENV)
    # The user has explicitly opted in to non-native implementation:
    if env["NIO4R_PURE"] == "true"
      return true
    end

    # Native Ruby on Windows is not supported:
    if (Gem.win_platform? && !defined?(JRUBY_VERSION))
      return true
    end

    # M1 native extension is crashing on M1 (arm64):
    if RUBY_PLATFORM =~ /darwin/ && RUBY_PLATFORM =~ /arm64/
      return true
    end

    return false
  end
end

if NIO.pure?
  require "nio/monitor"
  require "nio/selector"
  require "nio/bytebuffer"
  NIO::ENGINE = "ruby"
else
  require "nio4r_ext"

  if defined?(JRUBY_VERSION)
    require "java"
    require "jruby"
    org.nio4r.Nio4r.new.load(JRuby.runtime, false)
    NIO::ENGINE = "java"
  else
    NIO::ENGINE = "libev"
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
tdiary-5.1.6 vendor/bundle/ruby/2.7.0/gems/tdiary-5.1.5/vendor/bundle/ruby/3.0.0/gems/nio4r-2.5.5/lib/nio.rb
nio4r-2.5.6-java lib/nio.rb
nio4r-2.5.6 lib/nio.rb
tdiary-5.1.5 vendor/bundle/ruby/3.0.0/gems/nio4r-2.5.5/lib/nio.rb
nio4r-2.5.5-java lib/nio.rb
nio4r-2.5.5 lib/nio.rb