-
-
Notifications
You must be signed in to change notification settings - Fork 85
/
nio.rb
61 lines (52 loc) · 1.38 KB
/
nio.rb
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2011-2017, by Tony Arcieri.
# Copyright, 2013, by Stephen von Takach.
# Copyright, 2013, by Per Lundberg.
# Copyright, 2014, by Marek Kowalcze.
# Copyright, 2016, by Upekshe Jayasekera.
# Copyright, 2019-2023, by Samuel Williams.
# Copyright, 2021, by Jun Jiang.
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