io-event-machty 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ext/IO_Event.bundle +0 -0
- data/ext/Makefile +268 -0
- data/ext/event.o +0 -0
- data/ext/extconf.h +10 -0
- data/ext/extconf.rb +64 -0
- data/ext/interrupt.o +0 -0
- data/ext/io/event/event.c +52 -0
- data/ext/io/event/event.h +39 -0
- data/ext/io/event/interrupt.c +108 -0
- data/ext/io/event/interrupt.h +47 -0
- data/ext/io/event/selector/epoll.c +657 -0
- data/ext/io/event/selector/epoll.h +27 -0
- data/ext/io/event/selector/kqueue.c +742 -0
- data/ext/io/event/selector/kqueue.h +27 -0
- data/ext/io/event/selector/pidfd.c +36 -0
- data/ext/io/event/selector/selector.c +294 -0
- data/ext/io/event/selector/selector.h +130 -0
- data/ext/io/event/selector/uring.c +722 -0
- data/ext/io/event/selector/uring.h +27 -0
- data/ext/kqueue.o +0 -0
- data/ext/mkmf.log +273 -0
- data/ext/selector.o +0 -0
- data/lib/io/event/debug/selector.rb +161 -0
- data/lib/io/event/interrupt.rb +57 -0
- data/lib/io/event/selector/select.rb +270 -0
- data/lib/io/event/selector.rb +54 -0
- data/lib/io/event/version.rb +23 -0
- data/lib/io/event.rb +29 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b33380b810dd901bf3977e2bd919d1d5ce5f607e61c1644558dcfe8c2d0e272d
|
4
|
+
data.tar.gz: 153230069d87af00012f61e9407f3c91918a179672b362c1ce80d08c61796472
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 42d5caca0e95278badf7c7624f7a5eff491cb415005e387c03aeddb56a63a6d7ca8b8969771c583d49c5314f75702b6922310d8383d965ab910f513d0c510654
|
7
|
+
data.tar.gz: 387cb8999c1a331a41b1468e317d0182421dfa256f15c5a23d7db9ca8fd02ae1e91ce77fbbb742f58dbd3485777dda780a7d495797d4a4a7e430a415ee1d4e17
|
data/ext/IO_Event.bundle
ADDED
Binary file
|
data/ext/Makefile
ADDED
@@ -0,0 +1,268 @@
|
|
1
|
+
|
2
|
+
SHELL = /bin/sh
|
3
|
+
|
4
|
+
# V=0 quiet, V=1 verbose. other values don't work.
|
5
|
+
V = 0
|
6
|
+
V0 = $(V:0=)
|
7
|
+
Q1 = $(V:1=)
|
8
|
+
Q = $(Q1:0=@)
|
9
|
+
ECHO1 = $(V:1=@ :)
|
10
|
+
ECHO = $(ECHO1:0=@ echo)
|
11
|
+
NULLCMD = :
|
12
|
+
|
13
|
+
#### Start of system configuration section. ####
|
14
|
+
|
15
|
+
srcdir = .
|
16
|
+
topdir = /Users/machty/.rubies/ruby-3.1.0/include/ruby-3.1.0
|
17
|
+
hdrdir = $(topdir)
|
18
|
+
arch_hdrdir = /Users/machty/.rubies/ruby-3.1.0/include/ruby-3.1.0/x86_64-darwin20
|
19
|
+
PATH_SEPARATOR = :
|
20
|
+
VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby:$(srcdir)/io/event:$(srcdir)/io/event/selector
|
21
|
+
prefix = $(DESTDIR)/Users/machty/.rubies/ruby-3.1.0
|
22
|
+
rubysitearchprefix = $(rubylibprefix)/$(sitearch)
|
23
|
+
rubyarchprefix = $(rubylibprefix)/$(arch)
|
24
|
+
rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
|
25
|
+
exec_prefix = $(prefix)
|
26
|
+
vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
|
27
|
+
sitearchhdrdir = $(sitehdrdir)/$(sitearch)
|
28
|
+
rubyarchhdrdir = $(rubyhdrdir)/$(arch)
|
29
|
+
vendorhdrdir = $(rubyhdrdir)/vendor_ruby
|
30
|
+
sitehdrdir = $(rubyhdrdir)/site_ruby
|
31
|
+
rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
|
32
|
+
vendorarchdir = $(vendorlibdir)/$(sitearch)
|
33
|
+
vendorlibdir = $(vendordir)/$(ruby_version)
|
34
|
+
vendordir = $(rubylibprefix)/vendor_ruby
|
35
|
+
sitearchdir = $(sitelibdir)/$(sitearch)
|
36
|
+
sitelibdir = $(sitedir)/$(ruby_version)
|
37
|
+
sitedir = $(rubylibprefix)/site_ruby
|
38
|
+
rubyarchdir = $(rubylibdir)/$(arch)
|
39
|
+
rubylibdir = $(rubylibprefix)/$(ruby_version)
|
40
|
+
sitearchincludedir = $(includedir)/$(sitearch)
|
41
|
+
archincludedir = $(includedir)/$(arch)
|
42
|
+
sitearchlibdir = $(libdir)/$(sitearch)
|
43
|
+
archlibdir = $(libdir)/$(arch)
|
44
|
+
ridir = $(datarootdir)/$(RI_BASE_NAME)
|
45
|
+
mandir = $(datarootdir)/man
|
46
|
+
localedir = $(datarootdir)/locale
|
47
|
+
libdir = $(exec_prefix)/lib
|
48
|
+
psdir = $(docdir)
|
49
|
+
pdfdir = $(docdir)
|
50
|
+
dvidir = $(docdir)
|
51
|
+
htmldir = $(docdir)
|
52
|
+
infodir = $(datarootdir)/info
|
53
|
+
docdir = $(datarootdir)/doc/$(PACKAGE)
|
54
|
+
oldincludedir = $(DESTDIR)/usr/include
|
55
|
+
includedir = $(SDKROOT)$(prefix)/include
|
56
|
+
runstatedir = $(localstatedir)/run
|
57
|
+
localstatedir = $(prefix)/var
|
58
|
+
sharedstatedir = $(prefix)/com
|
59
|
+
sysconfdir = $(prefix)/etc
|
60
|
+
datadir = $(datarootdir)
|
61
|
+
datarootdir = $(prefix)/share
|
62
|
+
libexecdir = $(exec_prefix)/libexec
|
63
|
+
sbindir = $(exec_prefix)/sbin
|
64
|
+
bindir = $(exec_prefix)/bin
|
65
|
+
archdir = $(rubyarchdir)
|
66
|
+
|
67
|
+
|
68
|
+
CC_WRAPPER =
|
69
|
+
CC = clang
|
70
|
+
CXX = clang++
|
71
|
+
LIBRUBY = $(LIBRUBY_A)
|
72
|
+
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
73
|
+
LIBRUBYARG_SHARED =
|
74
|
+
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static -framework CoreFoundation $(MAINLIBS)
|
75
|
+
empty =
|
76
|
+
OUTFLAG = -o $(empty)
|
77
|
+
COUTFLAG = -o $(empty)
|
78
|
+
CSRCFLAG = $(empty)
|
79
|
+
|
80
|
+
RUBY_EXTCONF_H = extconf.h
|
81
|
+
cflags = -fdeclspec $(optflags) $(debugflags) $(warnflags)
|
82
|
+
cxxflags =
|
83
|
+
optflags = -O3 -fno-fast-math
|
84
|
+
debugflags = -ggdb3
|
85
|
+
warnflags = -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wextra-tokens -Wundef
|
86
|
+
cppflags =
|
87
|
+
CCDLFLAGS = -fno-common
|
88
|
+
CFLAGS = $(CCDLFLAGS) $(cflags) -pipe -Wall -std=c99 $(ARCH_FLAG)
|
89
|
+
INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
|
90
|
+
DEFS =
|
91
|
+
CPPFLAGS = -DRUBY_EXTCONF_H=\"$(RUBY_EXTCONF_H)\" -I/usr/local/opt/openssl@1.1/include -I/usr/local/opt/readline/include -I/usr/local/opt/libyaml/include -I/usr/local/opt/gdbm/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT $(DEFS) $(cppflags)
|
92
|
+
CXXFLAGS = $(CCDLFLAGS) -fdeclspec $(ARCH_FLAG)
|
93
|
+
ldflags = -L. -fstack-protector-strong -L/usr/local/lib -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/gdbm/lib
|
94
|
+
dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/gdbm/lib
|
95
|
+
ARCH_FLAG =
|
96
|
+
DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
|
97
|
+
LDSHARED = $(CC) -dynamic -bundle
|
98
|
+
LDSHAREDXX = $(CXX) -dynamic -bundle
|
99
|
+
AR = ar
|
100
|
+
EXEEXT =
|
101
|
+
|
102
|
+
RUBY_INSTALL_NAME = $(RUBY_BASE_NAME)
|
103
|
+
RUBY_SO_NAME = ruby.3.1
|
104
|
+
RUBYW_INSTALL_NAME =
|
105
|
+
RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
|
106
|
+
RUBYW_BASE_NAME = rubyw
|
107
|
+
RUBY_BASE_NAME = ruby
|
108
|
+
|
109
|
+
arch = x86_64-darwin20
|
110
|
+
sitearch = $(arch)
|
111
|
+
ruby_version = 3.1.0
|
112
|
+
ruby = $(bindir)/$(RUBY_BASE_NAME)
|
113
|
+
RUBY = $(ruby)
|
114
|
+
ruby_headers = $(hdrdir)/ruby.h $(hdrdir)/ruby/backward.h $(hdrdir)/ruby/ruby.h $(hdrdir)/ruby/defines.h $(hdrdir)/ruby/missing.h $(hdrdir)/ruby/intern.h $(hdrdir)/ruby/st.h $(hdrdir)/ruby/subst.h $(arch_hdrdir)/ruby/config.h $(RUBY_EXTCONF_H)
|
115
|
+
|
116
|
+
RM = rm -f
|
117
|
+
RM_RF = rm -fr
|
118
|
+
RMDIRS = rmdir -p
|
119
|
+
MAKEDIRS = /usr/local/bin/gmkdir -p
|
120
|
+
INSTALL = /usr/local/bin/ginstall -c
|
121
|
+
INSTALL_PROG = $(INSTALL) -m 0755
|
122
|
+
INSTALL_DATA = $(INSTALL) -m 644
|
123
|
+
COPY = cp
|
124
|
+
TOUCH = exit >
|
125
|
+
|
126
|
+
#### End of system configuration section. ####
|
127
|
+
|
128
|
+
preload =
|
129
|
+
libpath = . $(libdir) /usr/local/opt/openssl@1.1/lib /usr/local/opt/readline/lib /usr/local/opt/libyaml/lib /usr/local/opt/gdbm/lib
|
130
|
+
LIBPATH = -L. -L$(libdir) -L/usr/local/opt/openssl@1.1/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libyaml/lib -L/usr/local/opt/gdbm/lib
|
131
|
+
DEFFILE =
|
132
|
+
|
133
|
+
CLEANFILES = mkmf.log
|
134
|
+
DISTCLEANFILES =
|
135
|
+
DISTCLEANDIRS =
|
136
|
+
|
137
|
+
extout =
|
138
|
+
extout_prefix =
|
139
|
+
target_prefix =
|
140
|
+
LOCAL_LIBS =
|
141
|
+
LIBS =
|
142
|
+
ORIG_SRCS =
|
143
|
+
SRCS = $(ORIG_SRCS) event.c selector.c kqueue.c interrupt.c
|
144
|
+
OBJS = event.o selector.o kqueue.o interrupt.o
|
145
|
+
HDRS = $(srcdir)/extconf.h
|
146
|
+
LOCAL_HDRS =
|
147
|
+
TARGET = IO_Event
|
148
|
+
TARGET_NAME = IO_Event
|
149
|
+
TARGET_ENTRY = Init_$(TARGET_NAME)
|
150
|
+
DLLIB = $(TARGET).bundle
|
151
|
+
EXTSTATIC =
|
152
|
+
STATIC_LIB =
|
153
|
+
|
154
|
+
TIMESTAMP_DIR = .
|
155
|
+
BINDIR = $(bindir)
|
156
|
+
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
157
|
+
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
158
|
+
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
159
|
+
HDRDIR = $(sitehdrdir)$(target_prefix)
|
160
|
+
ARCHHDRDIR = $(sitearchhdrdir)$(target_prefix)
|
161
|
+
TARGET_SO_DIR =
|
162
|
+
TARGET_SO = $(TARGET_SO_DIR)$(DLLIB)
|
163
|
+
CLEANLIBS = $(TARGET_SO) $(TARGET_SO).dSYM
|
164
|
+
CLEANOBJS = *.o *.bak
|
165
|
+
|
166
|
+
all: $(DLLIB)
|
167
|
+
static: $(STATIC_LIB)
|
168
|
+
.PHONY: all install static install-so install-rb
|
169
|
+
.PHONY: clean clean-so clean-static clean-rb
|
170
|
+
|
171
|
+
clean-static::
|
172
|
+
clean-rb-default::
|
173
|
+
clean-rb::
|
174
|
+
clean-so::
|
175
|
+
clean: clean-so clean-static clean-rb-default clean-rb
|
176
|
+
-$(Q)$(RM_RF) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
|
177
|
+
|
178
|
+
distclean-rb-default::
|
179
|
+
distclean-rb::
|
180
|
+
distclean-so::
|
181
|
+
distclean-static::
|
182
|
+
distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
|
183
|
+
-$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
184
|
+
-$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
185
|
+
-$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
|
186
|
+
|
187
|
+
realclean: distclean
|
188
|
+
install: install-so install-rb
|
189
|
+
|
190
|
+
install-so: $(DLLIB) $(TIMESTAMP_DIR)/.sitearchdir.time
|
191
|
+
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
192
|
+
clean-static::
|
193
|
+
-$(Q)$(RM) $(STATIC_LIB)
|
194
|
+
install-rb: pre-install-rb do-install-rb install-rb-default
|
195
|
+
install-rb-default: pre-install-rb-default do-install-rb-default
|
196
|
+
pre-install-rb: Makefile
|
197
|
+
pre-install-rb-default: Makefile
|
198
|
+
do-install-rb:
|
199
|
+
do-install-rb-default:
|
200
|
+
pre-install-rb-default:
|
201
|
+
@$(NULLCMD)
|
202
|
+
$(TIMESTAMP_DIR)/.sitearchdir.time:
|
203
|
+
$(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
|
204
|
+
$(Q) $(TOUCH) $@
|
205
|
+
|
206
|
+
site-install: site-install-so site-install-rb
|
207
|
+
site-install-so: install-so
|
208
|
+
site-install-rb: install-rb
|
209
|
+
|
210
|
+
.SUFFIXES: .c .m .cc .mm .cxx .cpp .o .S
|
211
|
+
|
212
|
+
.cc.o:
|
213
|
+
$(ECHO) compiling $(<)
|
214
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
|
215
|
+
|
216
|
+
.cc.S:
|
217
|
+
$(ECHO) translating $(<)
|
218
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
|
219
|
+
|
220
|
+
.mm.o:
|
221
|
+
$(ECHO) compiling $(<)
|
222
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
|
223
|
+
|
224
|
+
.mm.S:
|
225
|
+
$(ECHO) translating $(<)
|
226
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
|
227
|
+
|
228
|
+
.cxx.o:
|
229
|
+
$(ECHO) compiling $(<)
|
230
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
|
231
|
+
|
232
|
+
.cxx.S:
|
233
|
+
$(ECHO) translating $(<)
|
234
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
|
235
|
+
|
236
|
+
.cpp.o:
|
237
|
+
$(ECHO) compiling $(<)
|
238
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
|
239
|
+
|
240
|
+
.cpp.S:
|
241
|
+
$(ECHO) translating $(<)
|
242
|
+
$(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
|
243
|
+
|
244
|
+
.c.o:
|
245
|
+
$(ECHO) compiling $(<)
|
246
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
|
247
|
+
|
248
|
+
.c.S:
|
249
|
+
$(ECHO) translating $(<)
|
250
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
|
251
|
+
|
252
|
+
.m.o:
|
253
|
+
$(ECHO) compiling $(<)
|
254
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
|
255
|
+
|
256
|
+
.m.S:
|
257
|
+
$(ECHO) translating $(<)
|
258
|
+
$(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
|
259
|
+
|
260
|
+
$(TARGET_SO): $(OBJS) Makefile
|
261
|
+
$(ECHO) linking shared-object $(DLLIB)
|
262
|
+
-$(Q)$(RM) $(@)
|
263
|
+
$(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
264
|
+
$(Q) $(POSTLINK)
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
$(OBJS): $(HDRS) $(ruby_headers)
|
data/ext/event.o
ADDED
Binary file
|
data/ext/extconf.h
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#ifndef EXTCONF_H
|
2
|
+
#define EXTCONF_H
|
3
|
+
#define HAVE_RB_EXT_RACTOR_SAFE 1
|
4
|
+
#define HAVE__RB_FIBER_TRANSFER 1
|
5
|
+
#define HAVE_SYS_EVENT_H 1
|
6
|
+
#define HAVE_RB_IO_DESCRIPTOR 1
|
7
|
+
#define HAVE_RB_FIBER_CURRENT 1
|
8
|
+
#define HAVE__RB_FIBER_RAISE 1
|
9
|
+
#define HAVE_RUBY_IO_BUFFER_H 1
|
10
|
+
#endif
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
+
#
|
5
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
# of this software and associated documentation files (the "Software"), to deal
|
7
|
+
# in the Software without restriction, including without limitation the rights
|
8
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
# copies of the Software, and to permit persons to whom the Software is
|
10
|
+
# furnished to do so, subject to the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be included in
|
13
|
+
# all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
# THE SOFTWARE.
|
22
|
+
|
23
|
+
require 'mkmf'
|
24
|
+
|
25
|
+
gem_name = File.basename(__dir__)
|
26
|
+
extension_name = 'IO_Event'
|
27
|
+
|
28
|
+
# dir_config(extension_name)
|
29
|
+
|
30
|
+
$CFLAGS << " -Wall -std=c99"
|
31
|
+
|
32
|
+
$srcs = ["io/event/event.c", "io/event/selector/selector.c"]
|
33
|
+
$VPATH << "$(srcdir)/io/event"
|
34
|
+
$VPATH << "$(srcdir)/io/event/selector"
|
35
|
+
|
36
|
+
have_func('rb_ext_ractor_safe')
|
37
|
+
have_func('&rb_fiber_transfer')
|
38
|
+
|
39
|
+
if have_library('uring') and have_header('liburing.h')
|
40
|
+
$srcs << "io/event/selector/uring.c"
|
41
|
+
end
|
42
|
+
|
43
|
+
if have_header('sys/epoll.h')
|
44
|
+
$srcs << "io/event/selector/epoll.c"
|
45
|
+
end
|
46
|
+
|
47
|
+
if have_header('sys/event.h')
|
48
|
+
$srcs << "io/event/selector/kqueue.c"
|
49
|
+
end
|
50
|
+
|
51
|
+
have_header('sys/eventfd.h')
|
52
|
+
$srcs << "io/event/interrupt.c"
|
53
|
+
|
54
|
+
have_func("rb_io_descriptor")
|
55
|
+
have_func("&rb_process_status_wait")
|
56
|
+
have_func('rb_fiber_current')
|
57
|
+
have_func("&rb_fiber_raise")
|
58
|
+
|
59
|
+
have_header('ruby/io/buffer.h')
|
60
|
+
|
61
|
+
create_header
|
62
|
+
|
63
|
+
# Generate the makefile to compile the native binary into `lib`:
|
64
|
+
create_makefile(extension_name)
|
data/ext/interrupt.o
ADDED
Binary file
|
@@ -0,0 +1,52 @@
|
|
1
|
+
// Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
8
|
+
// furnished to do so, subject to the following conditions:
|
9
|
+
//
|
10
|
+
// The above copyright notice and this permission notice shall be included in
|
11
|
+
// all copies or substantial portions of the Software.
|
12
|
+
//
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
// THE SOFTWARE.
|
20
|
+
|
21
|
+
#include "event.h"
|
22
|
+
#include "selector/selector.h"
|
23
|
+
|
24
|
+
VALUE IO_Event = Qnil;
|
25
|
+
VALUE IO_Event_Selector = Qnil;
|
26
|
+
|
27
|
+
void Init_IO_Event(void)
|
28
|
+
{
|
29
|
+
#ifdef HAVE_RB_EXT_RACTOR_SAFE
|
30
|
+
rb_ext_ractor_safe(true);
|
31
|
+
#endif
|
32
|
+
|
33
|
+
IO_Event = rb_define_module_under(rb_cIO, "Event");
|
34
|
+
rb_gc_register_mark_object(IO_Event);
|
35
|
+
|
36
|
+
IO_Event_Selector = rb_define_module_under(IO_Event, "Selector");
|
37
|
+
rb_gc_register_mark_object(IO_Event_Selector);
|
38
|
+
|
39
|
+
Init_IO_Event_Selector(IO_Event_Selector);
|
40
|
+
|
41
|
+
#ifdef IO_EVENT_SELECTOR_URING
|
42
|
+
Init_IO_Event_Selector_URing(IO_Event_Selector);
|
43
|
+
#endif
|
44
|
+
|
45
|
+
#ifdef IO_EVENT_SELECTOR_EPOLL
|
46
|
+
Init_IO_Event_Selector_EPoll(IO_Event_Selector);
|
47
|
+
#endif
|
48
|
+
|
49
|
+
#ifdef IO_EVENT_SELECTOR_KQUEUE
|
50
|
+
Init_IO_Event_Selector_KQueue(IO_Event_Selector);
|
51
|
+
#endif
|
52
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
// Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
8
|
+
// furnished to do so, subject to the following conditions:
|
9
|
+
//
|
10
|
+
// The above copyright notice and this permission notice shall be included in
|
11
|
+
// all copies or substantial portions of the Software.
|
12
|
+
//
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
// THE SOFTWARE.
|
20
|
+
|
21
|
+
#pragma once
|
22
|
+
|
23
|
+
#include <ruby.h>
|
24
|
+
|
25
|
+
#include "extconf.h"
|
26
|
+
|
27
|
+
void Init_IO_Event(void);
|
28
|
+
|
29
|
+
#ifdef HAVE_LIBURING_H
|
30
|
+
#include "selector/uring.h"
|
31
|
+
#endif
|
32
|
+
|
33
|
+
#ifdef HAVE_SYS_EPOLL_H
|
34
|
+
#include "selector/epoll.h"
|
35
|
+
#endif
|
36
|
+
|
37
|
+
#ifdef HAVE_SYS_EVENT_H
|
38
|
+
#include "selector/kqueue.h"
|
39
|
+
#endif
|
@@ -0,0 +1,108 @@
|
|
1
|
+
// Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
8
|
+
// furnished to do so, subject to the following conditions:
|
9
|
+
//
|
10
|
+
// The above copyright notice and this permission notice shall be included in
|
11
|
+
// all copies or substantial portions of the Software.
|
12
|
+
//
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
// THE SOFTWARE.
|
20
|
+
|
21
|
+
// static const int DEBUG = 0;
|
22
|
+
|
23
|
+
#include "interrupt.h"
|
24
|
+
#include <unistd.h>
|
25
|
+
|
26
|
+
#include "selector/selector.h"
|
27
|
+
|
28
|
+
#ifdef HAVE_SYS_EVENTFD_H
|
29
|
+
#include <sys/eventfd.h>
|
30
|
+
|
31
|
+
void IO_Event_Interrupt_open(struct IO_Event_Interrupt *interrupt)
|
32
|
+
{
|
33
|
+
interrupt->descriptor = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
|
34
|
+
rb_update_max_fd(interrupt->descriptor);
|
35
|
+
}
|
36
|
+
|
37
|
+
void IO_Event_Interrupt_close(struct IO_Event_Interrupt *interrupt)
|
38
|
+
{
|
39
|
+
close(interrupt->descriptor);
|
40
|
+
}
|
41
|
+
|
42
|
+
void IO_Event_Interrupt_signal(struct IO_Event_Interrupt *interrupt)
|
43
|
+
{
|
44
|
+
uint64_t value = 1;
|
45
|
+
ssize_t result = write(interrupt->descriptor, &value, sizeof(value));
|
46
|
+
|
47
|
+
if (result == -1) {
|
48
|
+
if (errno == EAGAIN || errno == EWOULDBLOCK) return;
|
49
|
+
|
50
|
+
rb_sys_fail("IO_Event_Interrupt_signal:write");
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
void IO_Event_Interrupt_clear(struct IO_Event_Interrupt *interrupt)
|
55
|
+
{
|
56
|
+
uint64_t value = 0;
|
57
|
+
ssize_t result = read(interrupt->descriptor, &value, sizeof(value));
|
58
|
+
|
59
|
+
if (result == -1) {
|
60
|
+
if (errno == EAGAIN || errno == EWOULDBLOCK) return;
|
61
|
+
|
62
|
+
rb_sys_fail("IO_Event_Interrupt_clear:read");
|
63
|
+
}
|
64
|
+
}
|
65
|
+
#else
|
66
|
+
void IO_Event_Interrupt_open(struct IO_Event_Interrupt *interrupt)
|
67
|
+
{
|
68
|
+
#ifdef __linux__
|
69
|
+
pipe2(interrupt->descriptor, O_CLOEXEC | O_NONBLOCK);
|
70
|
+
#else
|
71
|
+
pipe(interrupt->descriptor);
|
72
|
+
IO_Event_Selector_nonblock_set(interrupt->descriptor[0]);
|
73
|
+
IO_Event_Selector_nonblock_set(interrupt->descriptor[1]);
|
74
|
+
#endif
|
75
|
+
|
76
|
+
rb_update_max_fd(interrupt->descriptor[0]);
|
77
|
+
rb_update_max_fd(interrupt->descriptor[1]);
|
78
|
+
}
|
79
|
+
|
80
|
+
void IO_Event_Interrupt_close(struct IO_Event_Interrupt *interrupt)
|
81
|
+
{
|
82
|
+
close(interrupt->descriptor[0]);
|
83
|
+
close(interrupt->descriptor[1]);
|
84
|
+
}
|
85
|
+
|
86
|
+
void IO_Event_Interrupt_signal(struct IO_Event_Interrupt *interrupt)
|
87
|
+
{
|
88
|
+
ssize_t result = write(interrupt->descriptor[1], ".", 1);
|
89
|
+
|
90
|
+
if (result == -1) {
|
91
|
+
if (errno == EAGAIN || errno == EWOULDBLOCK) return;
|
92
|
+
|
93
|
+
rb_sys_fail("IO_Event_Interrupt_signal:write");
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
void IO_Event_Interrupt_clear(struct IO_Event_Interrupt *interrupt)
|
98
|
+
{
|
99
|
+
char buffer[128];
|
100
|
+
ssize_t result = read(interrupt->descriptor[0], buffer, sizeof(buffer));
|
101
|
+
|
102
|
+
if (result == -1) {
|
103
|
+
if (errno == EAGAIN || errno == EWOULDBLOCK) return;
|
104
|
+
|
105
|
+
rb_sys_fail("IO_Event_Interrupt_clear:read");
|
106
|
+
}
|
107
|
+
}
|
108
|
+
#endif
|
@@ -0,0 +1,47 @@
|
|
1
|
+
// Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
// of this software and associated documentation files (the "Software"), to deal
|
5
|
+
// in the Software without restriction, including without limitation the rights
|
6
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
// copies of the Software, and to permit persons to whom the Software is
|
8
|
+
// furnished to do so, subject to the following conditions:
|
9
|
+
//
|
10
|
+
// The above copyright notice and this permission notice shall be included in
|
11
|
+
// all copies or substantial portions of the Software.
|
12
|
+
//
|
13
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
// THE SOFTWARE.
|
20
|
+
|
21
|
+
#pragma once
|
22
|
+
|
23
|
+
#include "extconf.h"
|
24
|
+
|
25
|
+
#ifdef HAVE_SYS_EVENTFD_H
|
26
|
+
struct IO_Event_Interrupt {
|
27
|
+
int descriptor;
|
28
|
+
};
|
29
|
+
|
30
|
+
inline int IO_Event_Interrupt_descriptor(struct IO_Event_Interrupt *interrupt) {
|
31
|
+
return interrupt->descriptor;
|
32
|
+
}
|
33
|
+
#else
|
34
|
+
struct IO_Event_Interrupt {
|
35
|
+
int descriptor[2];
|
36
|
+
};
|
37
|
+
|
38
|
+
inline int IO_Event_Interrupt_descriptor(struct IO_Event_Interrupt *interrupt) {
|
39
|
+
return interrupt->descriptor[0];
|
40
|
+
}
|
41
|
+
#endif
|
42
|
+
|
43
|
+
void IO_Event_Interrupt_open(struct IO_Event_Interrupt *interrupt);
|
44
|
+
void IO_Event_Interrupt_close(struct IO_Event_Interrupt *interrupt);
|
45
|
+
|
46
|
+
void IO_Event_Interrupt_signal(struct IO_Event_Interrupt *interrupt);
|
47
|
+
void IO_Event_Interrupt_clear(struct IO_Event_Interrupt *interrupt);
|