event 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 820b9a8295d89939388b1fa56c818addaad4e46a3af90eb0318a6c4d4338b729
4
- data.tar.gz: a925d6a51efeacb281c68cdb51840fe81a1c97aa22297c684f7a441d9ee2afc3
3
+ metadata.gz: 1e032d8ef7daf3803999a2ac9cba5a72e95f6a3b6551f4724be451eb026b03e0
4
+ data.tar.gz: 1cdb73bcd9a5f52483faa2da537c1033ebfaba64b41abc80734b475afbd1fd72
5
5
  SHA512:
6
- metadata.gz: a591c0f50e2f1fa19d895eea4a94141b6d6ed2f359325f61400f67c35a51e1f89ff4a8806ae764042f0e747612a0c291554bed423c83ae9ec58afbc24bf20c3b
7
- data.tar.gz: e32064f234f542aee8bff87e19e1c3647c08e054c962d4943674e7a17167860f5898bc76b1c134494fea1a46a8f2a40da0b30d5516470950eecd02df470893c8
6
+ metadata.gz: 471fbc3ded644b8bfadbc4e1cca562f926bcd203141a59c6981e5ca85e225a9a1b09df4ed2f0792077272b2652ef50a81ea208c0fd44bd35b05158bfdb949c9b
7
+ data.tar.gz: a22b2804acdc8ad4dc5bc300fb23aa5991a2d69db301c2d6d5d71016643848e13cb1d9392c6367eebf4f3b179357b60c86cdbcd5b2bad8053c0dd0e1b42f38f9
@@ -0,0 +1,266 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ # V=0 quiet, V=1 verbose. other values don't work.
5
+ V = 0
6
+ Q1 = $(V:1=)
7
+ Q = $(Q1:0=@)
8
+ ECHO1 = $(V:1=@ :)
9
+ ECHO = $(ECHO1:0=@ echo)
10
+ NULLCMD = :
11
+
12
+ #### Start of system configuration section. ####
13
+
14
+ srcdir = .
15
+ topdir = /home/samuel/.rubies/ruby-3.0.0/include/ruby-3.0.0
16
+ hdrdir = $(topdir)
17
+ arch_hdrdir = /home/samuel/.rubies/ruby-3.0.0/include/ruby-3.0.0/x86_64-linux
18
+ PATH_SEPARATOR = :
19
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby:$(srcdir)/backend
20
+ prefix = $(DESTDIR)/home/samuel/.rubies/ruby-3.0.0
21
+ rubysitearchprefix = $(rubylibprefix)/$(sitearch)
22
+ rubyarchprefix = $(rubylibprefix)/$(arch)
23
+ rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
24
+ exec_prefix = $(prefix)
25
+ vendorarchhdrdir = $(vendorhdrdir)/$(sitearch)
26
+ sitearchhdrdir = $(sitehdrdir)/$(sitearch)
27
+ rubyarchhdrdir = $(rubyhdrdir)/$(arch)
28
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
29
+ sitehdrdir = $(rubyhdrdir)/site_ruby
30
+ rubyhdrdir = $(includedir)/$(RUBY_VERSION_NAME)
31
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
32
+ vendorlibdir = $(vendordir)/$(ruby_version)
33
+ vendordir = $(rubylibprefix)/vendor_ruby
34
+ sitearchdir = $(sitelibdir)/$(sitearch)
35
+ sitelibdir = $(sitedir)/$(ruby_version)
36
+ sitedir = $(rubylibprefix)/site_ruby
37
+ rubyarchdir = $(rubylibdir)/$(arch)
38
+ rubylibdir = $(rubylibprefix)/$(ruby_version)
39
+ sitearchincludedir = $(includedir)/$(sitearch)
40
+ archincludedir = $(includedir)/$(arch)
41
+ sitearchlibdir = $(libdir)/$(sitearch)
42
+ archlibdir = $(libdir)/$(arch)
43
+ ridir = $(datarootdir)/$(RI_BASE_NAME)
44
+ mandir = $(datarootdir)/man
45
+ localedir = $(datarootdir)/locale
46
+ libdir = $(exec_prefix)/lib
47
+ psdir = $(docdir)
48
+ pdfdir = $(docdir)
49
+ dvidir = $(docdir)
50
+ htmldir = $(docdir)
51
+ infodir = $(datarootdir)/info
52
+ docdir = $(datarootdir)/doc/$(PACKAGE)
53
+ oldincludedir = $(DESTDIR)/usr/include
54
+ includedir = $(prefix)/include
55
+ runstatedir = $(localstatedir)/run
56
+ localstatedir = $(prefix)/var
57
+ sharedstatedir = $(prefix)/com
58
+ sysconfdir = $(prefix)/etc
59
+ datadir = $(datarootdir)
60
+ datarootdir = $(prefix)/share
61
+ libexecdir = $(exec_prefix)/libexec
62
+ sbindir = $(exec_prefix)/sbin
63
+ bindir = $(exec_prefix)/bin
64
+ archdir = $(rubyarchdir)
65
+
66
+
67
+ CC_WRAPPER =
68
+ CC = gcc
69
+ CXX = g++
70
+ LIBRUBY = $(LIBRUBY_A)
71
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
72
+ LIBRUBYARG_SHARED = -Wl,-rpath,$(libdir) -L$(libdir)
73
+ LIBRUBYARG_STATIC = -Wl,-rpath,$(libdir) -L$(libdir) -l$(RUBY_SO_NAME)-static $(MAINLIBS)
74
+ empty =
75
+ OUTFLAG = -o $(empty)
76
+ COUTFLAG = -o $(empty)
77
+ CSRCFLAG = $(empty)
78
+
79
+ RUBY_EXTCONF_H = extconf.h
80
+ cflags = $(optflags) $(debugflags) $(warnflags)
81
+ cxxflags =
82
+ optflags = -O3
83
+ debugflags = -ggdb3
84
+ warnflags = -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable
85
+ cppflags =
86
+ CCDLFLAGS = -fPIC
87
+ CFLAGS = $(CCDLFLAGS) $(cflags) $(ARCH_FLAG)
88
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
89
+ DEFS =
90
+ CPPFLAGS = -DRUBY_EXTCONF_H=\"$(RUBY_EXTCONF_H)\" $(DEFS) $(cppflags)
91
+ CXXFLAGS = $(CCDLFLAGS) $(ARCH_FLAG)
92
+ ldflags = -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic
93
+ dldflags = -Wl,--compress-debug-sections=zlib
94
+ ARCH_FLAG =
95
+ DLDFLAGS = $(ldflags) $(dldflags) $(ARCH_FLAG)
96
+ LDSHARED = $(CC) -shared
97
+ LDSHAREDXX = $(CXX) -shared
98
+ AR = gcc-ar
99
+ EXEEXT =
100
+
101
+ RUBY_INSTALL_NAME = $(RUBY_BASE_NAME)
102
+ RUBY_SO_NAME = ruby
103
+ RUBYW_INSTALL_NAME =
104
+ RUBY_VERSION_NAME = $(RUBY_BASE_NAME)-$(ruby_version)
105
+ RUBYW_BASE_NAME = rubyw
106
+ RUBY_BASE_NAME = ruby
107
+
108
+ arch = x86_64-linux
109
+ sitearch = $(arch)
110
+ ruby_version = 3.0.0
111
+ ruby = $(bindir)/$(RUBY_BASE_NAME)
112
+ RUBY = $(ruby)
113
+ 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)
114
+
115
+ RM = rm -f
116
+ RM_RF = $(RUBY) -run -e rm -- -rf
117
+ RMDIRS = rmdir --ignore-fail-on-non-empty -p
118
+ MAKEDIRS = /usr/bin/mkdir -p
119
+ INSTALL = /usr/bin/install -c
120
+ INSTALL_PROG = $(INSTALL) -m 0755
121
+ INSTALL_DATA = $(INSTALL) -m 644
122
+ COPY = cp
123
+ TOUCH = exit >
124
+
125
+ #### End of system configuration section. ####
126
+
127
+ preload =
128
+ libpath = . $(libdir)
129
+ LIBPATH = -L. -L$(libdir) -Wl,-rpath,$(libdir)
130
+ DEFFILE =
131
+
132
+ CLEANFILES = mkmf.log
133
+ DISTCLEANFILES =
134
+ DISTCLEANDIRS =
135
+
136
+ extout =
137
+ extout_prefix =
138
+ target_prefix = /event
139
+ LOCAL_LIBS =
140
+ LIBS = -luring -lm -lc
141
+ ORIG_SRCS = event.c
142
+ SRCS = $(ORIG_SRCS) event.c uring.c epoll.c
143
+ OBJS = event.o uring.o epoll.o
144
+ HDRS = $(srcdir)/event.h $(srcdir)/extconf.h
145
+ LOCAL_HDRS =
146
+ TARGET = event
147
+ TARGET_NAME = event
148
+ TARGET_ENTRY = Init_$(TARGET_NAME)
149
+ DLLIB = $(TARGET).so
150
+ EXTSTATIC =
151
+ STATIC_LIB =
152
+
153
+ TIMESTAMP_DIR = .
154
+ BINDIR = $(bindir)
155
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
156
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
157
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
158
+ HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
159
+ ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
160
+ TARGET_SO_DIR =
161
+ TARGET_SO = $(TARGET_SO_DIR)$(DLLIB)
162
+ CLEANLIBS = $(TARGET_SO)
163
+ CLEANOBJS = *.o *.bak
164
+
165
+ all: $(DLLIB)
166
+ static: $(STATIC_LIB)
167
+ .PHONY: all install static install-so install-rb
168
+ .PHONY: clean clean-so clean-static clean-rb
169
+
170
+ clean-static::
171
+ clean-rb-default::
172
+ clean-rb::
173
+ clean-so::
174
+ clean: clean-so clean-static clean-rb-default clean-rb
175
+ -$(Q)$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES) .*.time
176
+
177
+ distclean-rb-default::
178
+ distclean-rb::
179
+ distclean-so::
180
+ distclean-static::
181
+ distclean: clean distclean-so distclean-static distclean-rb-default distclean-rb
182
+ -$(Q)$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
183
+ -$(Q)$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
184
+ -$(Q)$(RMDIRS) $(DISTCLEANDIRS) 2> /dev/null || true
185
+
186
+ realclean: distclean
187
+ install: install-so install-rb
188
+
189
+ install-so: $(DLLIB) $(TIMESTAMP_DIR)/.sitearchdir.-.event.time
190
+ $(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
191
+ clean-static::
192
+ -$(Q)$(RM) $(STATIC_LIB)
193
+ install-rb: pre-install-rb do-install-rb install-rb-default
194
+ install-rb-default: pre-install-rb-default do-install-rb-default
195
+ pre-install-rb: Makefile
196
+ pre-install-rb-default: Makefile
197
+ do-install-rb:
198
+ do-install-rb-default:
199
+ pre-install-rb-default:
200
+ @$(NULLCMD)
201
+ $(TIMESTAMP_DIR)/.sitearchdir.-.event.time:
202
+ $(Q) $(MAKEDIRS) $(@D) $(RUBYARCHDIR)
203
+ $(Q) $(TOUCH) $@
204
+
205
+ site-install: site-install-so site-install-rb
206
+ site-install-so: install-so
207
+ site-install-rb: install-rb
208
+
209
+ .SUFFIXES: .c .m .cc .mm .cxx .cpp .o .S
210
+
211
+ .cc.o:
212
+ $(ECHO) compiling $(<)
213
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
214
+
215
+ .cc.S:
216
+ $(ECHO) translating $(<)
217
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
218
+
219
+ .mm.o:
220
+ $(ECHO) compiling $(<)
221
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
222
+
223
+ .mm.S:
224
+ $(ECHO) translating $(<)
225
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
226
+
227
+ .cxx.o:
228
+ $(ECHO) compiling $(<)
229
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
230
+
231
+ .cxx.S:
232
+ $(ECHO) translating $(<)
233
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
234
+
235
+ .cpp.o:
236
+ $(ECHO) compiling $(<)
237
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
238
+
239
+ .cpp.S:
240
+ $(ECHO) translating $(<)
241
+ $(Q) $(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
242
+
243
+ .c.o:
244
+ $(ECHO) compiling $(<)
245
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
246
+
247
+ .c.S:
248
+ $(ECHO) translating $(<)
249
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
250
+
251
+ .m.o:
252
+ $(ECHO) compiling $(<)
253
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -c $(CSRCFLAG)$<
254
+
255
+ .m.S:
256
+ $(ECHO) translating $(<)
257
+ $(Q) $(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) $(COUTFLAG)$@ -S $(CSRCFLAG)$<
258
+
259
+ $(TARGET_SO): $(OBJS) Makefile
260
+ $(ECHO) linking shared-object event/$(DLLIB)
261
+ -$(Q)$(RM) $(@)
262
+ $(Q) $(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
263
+
264
+
265
+
266
+ $(OBJS): $(HDRS) $(ruby_headers)
@@ -28,7 +28,7 @@
28
28
  static VALUE Event_Backend_EPoll = Qnil;
29
29
  static ID id_fileno, id_transfer;
30
30
 
31
- static const unsigned EPOLL_MAX_EVENTS = 1024;
31
+ static const unsigned EPOLL_MAX_EVENTS = 64;
32
32
 
33
33
  struct Event_Backend_EPoll {
34
34
  VALUE loop;
@@ -123,6 +123,7 @@ int events_from_epoll_flags(uint32_t flags) {
123
123
 
124
124
  struct io_wait_arguments {
125
125
  struct Event_Backend_EPoll *data;
126
+ int descriptor;
126
127
  int duplicate;
127
128
  };
128
129
 
@@ -131,7 +132,11 @@ VALUE io_wait_ensure(VALUE _arguments) {
131
132
  struct io_wait_arguments *arguments = (struct io_wait_arguments *)_arguments;
132
133
 
133
134
  if (arguments->duplicate >= 0) {
135
+ epoll_ctl(arguments->data->descriptor, EPOLL_CTL_DEL, arguments->duplicate, NULL);
136
+
134
137
  close(arguments->duplicate);
138
+ } else {
139
+ epoll_ctl(arguments->data->descriptor, EPOLL_CTL_DEL, arguments->descriptor, NULL);
135
140
  }
136
141
 
137
142
  return Qnil;
@@ -158,8 +163,10 @@ VALUE Event_Backend_EPoll_io_wait(VALUE self, VALUE fiber, VALUE io, VALUE event
158
163
  event.events = epoll_flags_from_events(NUM2INT(events));
159
164
  event.data.ptr = (void*)fiber;
160
165
 
166
+ // fprintf(stderr, "<- fiber=%p descriptor=%d\n", (void*)fiber, descriptor);
167
+
161
168
  // A better approach is to batch all changes:
162
- int result = epoll_ctl(data->descriptor, EPOLL_CTL_ADD, descriptor, &event);;
169
+ int result = epoll_ctl(data->descriptor, EPOLL_CTL_ADD, descriptor, &event);
163
170
 
164
171
  if (result == -1 && errno == EEXIST) {
165
172
  // The file descriptor was already inserted into epoll.
@@ -170,7 +177,7 @@ VALUE Event_Backend_EPoll_io_wait(VALUE self, VALUE fiber, VALUE io, VALUE event
170
177
  if (descriptor == -1)
171
178
  rb_sys_fail("dup");
172
179
 
173
- result = epoll_ctl(data->descriptor, EPOLL_CTL_ADD, descriptor, &event);;
180
+ result = epoll_ctl(data->descriptor, EPOLL_CTL_ADD, descriptor, &event);
174
181
  }
175
182
 
176
183
  if (result == -1) {
@@ -179,6 +186,7 @@ VALUE Event_Backend_EPoll_io_wait(VALUE self, VALUE fiber, VALUE io, VALUE event
179
186
 
180
187
  struct io_wait_arguments io_wait_arguments = {
181
188
  .data = data,
189
+ .descriptor = descriptor,
182
190
  .duplicate = duplicate
183
191
  };
184
192
 
@@ -220,6 +228,8 @@ VALUE Event_Backend_EPoll_select(VALUE self, VALUE duration) {
220
228
  VALUE fiber = (VALUE)events[i].data.ptr;
221
229
  VALUE result = INT2NUM(events[i].events);
222
230
 
231
+ // fprintf(stderr, "-> fiber=%p descriptor=%d\n", (void*)fiber, events[i].data.fd);
232
+
223
233
  rb_funcall(fiber, id_transfer, 1, result);
224
234
  }
225
235
 
@@ -28,14 +28,7 @@
28
28
  static VALUE Event_Backend_KQueue = Qnil;
29
29
  static ID id_fileno, id_transfer;
30
30
 
31
- static const int
32
- READABLE = 1,
33
- PRIORITY = 2,
34
- WRITABLE = 4,
35
- ERROR = 8,
36
- HANGUP = 16;
37
-
38
- static const unsigned KQUEUE_MAX_EVENTS = 1024;
31
+ static const unsigned KQUEUE_MAX_EVENTS = 64;
39
32
 
40
33
  struct Event_Backend_KQueue {
41
34
  VALUE loop;
@@ -28,12 +28,12 @@
28
28
  static VALUE Event_Backend_URing = Qnil;
29
29
  static ID id_fileno, id_transfer;
30
30
 
31
- static const int URING_ENTRIES = 1024;
32
- static const int URING_MAX_EVENTS = 1024;
31
+ static const int URING_ENTRIES = 64;
32
+ static const int URING_MAX_EVENTS = 64;
33
33
 
34
34
  struct Event_Backend_URing {
35
35
  VALUE loop;
36
- struct io_uring* ring;
36
+ struct io_uring ring;
37
37
  };
38
38
 
39
39
  void Event_Backend_URing_Type_mark(void *_data)
@@ -46,9 +46,9 @@ void Event_Backend_URing_Type_free(void *_data)
46
46
  {
47
47
  struct Event_Backend_URing *data = _data;
48
48
 
49
- if (data->ring) {
50
- io_uring_queue_exit(data->ring);
51
- xfree(data->ring);
49
+ if (data->ring.ring_fd >= 0) {
50
+ io_uring_queue_exit(&data->ring);
51
+ data->ring.ring_fd = -1;
52
52
  }
53
53
 
54
54
  free(data);
@@ -75,7 +75,7 @@ VALUE Event_Backend_URing_allocate(VALUE self) {
75
75
  VALUE instance = TypedData_Make_Struct(self, struct Event_Backend_URing, &Event_Backend_URing_Type, data);
76
76
 
77
77
  data->loop = Qnil;
78
- data->ring = NULL;
78
+ data->ring.ring_fd = -1;
79
79
 
80
80
  return instance;
81
81
  }
@@ -85,14 +85,15 @@ VALUE Event_Backend_URing_initialize(VALUE self, VALUE loop) {
85
85
  TypedData_Get_Struct(self, struct Event_Backend_URing, &Event_Backend_URing_Type, data);
86
86
 
87
87
  data->loop = loop;
88
- data->ring = xmalloc(sizeof(struct io_uring));
89
88
 
90
- int result = io_uring_queue_init(URING_ENTRIES, data->ring, 0);
89
+ int result = io_uring_queue_init(URING_ENTRIES, &data->ring, 0);
91
90
 
92
- if (result == -1) {
93
- rb_sys_fail("io_uring_queue_init");
91
+ if (result < 0) {
92
+ rb_syserr_fail(-result, "io_uring_queue_init");
94
93
  }
95
94
 
95
+ rb_update_max_fd(data->ring.ring_fd);
96
+
96
97
  return self;
97
98
  }
98
99
 
@@ -126,7 +127,7 @@ VALUE Event_Backend_URing_io_wait(VALUE self, VALUE fiber, VALUE io, VALUE event
126
127
  TypedData_Get_Struct(self, struct Event_Backend_URing, &Event_Backend_URing_Type, data);
127
128
 
128
129
  int descriptor = NUM2INT(rb_funcall(io, id_fileno, 0));
129
- struct io_uring_sqe *sqe = io_uring_get_sqe(data->ring);
130
+ struct io_uring_sqe *sqe = io_uring_get_sqe(&data->ring);
130
131
 
131
132
  short flags = poll_flags_from_events(NUM2INT(events));
132
133
 
@@ -134,7 +135,7 @@ VALUE Event_Backend_URing_io_wait(VALUE self, VALUE fiber, VALUE io, VALUE event
134
135
 
135
136
  io_uring_prep_poll_add(sqe, descriptor, flags);
136
137
  io_uring_sqe_set_data(sqe, (void*)fiber);
137
- io_uring_submit(data->ring);
138
+ io_uring_submit(&data->ring);
138
139
 
139
140
  VALUE result = rb_funcall(data->loop, id_transfer, 0);
140
141
 
@@ -145,39 +146,13 @@ VALUE Event_Backend_URing_io_wait(VALUE self, VALUE fiber, VALUE io, VALUE event
145
146
  return INT2NUM(events_from_poll_flags(flags));
146
147
  }
147
148
 
148
- static
149
- struct __kernel_timespec * make_timeout(VALUE duration, struct __kernel_timespec *storage) {
150
- if (duration == Qnil) {
151
- return NULL;
152
- }
153
-
154
- if (FIXNUM_P(duration)) {
155
- storage->tv_sec = NUM2TIMET(duration);
156
- storage->tv_nsec = 0;
157
-
158
- return storage;
159
- }
160
-
161
- else if (RB_FLOAT_TYPE_P(duration)) {
162
- double value = RFLOAT_VALUE(duration);
163
- time_t seconds = duration;
164
-
165
- storage->tv_sec = seconds;
166
- storage->tv_nsec = (value - seconds) * 1000000000L;
167
-
168
- return storage;
169
- }
170
-
171
- rb_raise(rb_eRuntimeError, "unable to convert timeout");
172
- }
173
-
174
149
  inline static
175
150
  void resize_to_capacity(VALUE string, size_t offset, size_t length) {
176
151
  size_t current_length = RSTRING_LEN(string);
177
152
  long difference = (long)(offset + length) - (long)current_length;
178
-
153
+
179
154
  difference += 1;
180
-
155
+
181
156
  if (difference > 0) {
182
157
  rb_str_modify_expand(string, difference);
183
158
  } else {
@@ -188,7 +163,7 @@ void resize_to_capacity(VALUE string, size_t offset, size_t length) {
188
163
  inline static
189
164
  void resize_to_fit(VALUE string, size_t offset, size_t length) {
190
165
  size_t current_length = RSTRING_LEN(string);
191
-
166
+
192
167
  if (current_length < (offset + length)) {
193
168
  rb_str_set_len(string, offset + length);
194
169
  }
@@ -197,63 +172,89 @@ void resize_to_fit(VALUE string, size_t offset, size_t length) {
197
172
  VALUE Event_Backend_URing_io_read(VALUE self, VALUE fiber, VALUE io, VALUE buffer, VALUE offset, VALUE length) {
198
173
  struct Event_Backend_URing *data = NULL;
199
174
  TypedData_Get_Struct(self, struct Event_Backend_URing, &Event_Backend_URing_Type, data);
200
-
175
+
201
176
  resize_to_capacity(buffer, NUM2SIZET(offset), NUM2SIZET(length));
202
-
177
+
203
178
  int descriptor = NUM2INT(rb_funcall(io, id_fileno, 0));
204
- struct io_uring_sqe *sqe = io_uring_get_sqe(data->ring);
205
-
179
+ struct io_uring_sqe *sqe = io_uring_get_sqe(&data->ring);
180
+
206
181
  struct iovec iovecs[1];
207
182
  iovecs[0].iov_base = RSTRING_PTR(buffer) + NUM2SIZET(offset);
208
183
  iovecs[0].iov_len = NUM2SIZET(length);
209
-
184
+
210
185
  io_uring_prep_readv(sqe, descriptor, iovecs, 1, 0);
211
186
  io_uring_sqe_set_data(sqe, (void*)fiber);
212
- io_uring_submit(data->ring);
213
-
187
+ io_uring_submit(&data->ring);
188
+
214
189
  // fprintf(stderr, "prep_readv(%p, %d, %ld)\n", sqe, descriptor, iovecs[0].iov_len);
215
-
190
+
216
191
  int result = NUM2INT(rb_funcall(data->loop, id_transfer, 0));
217
-
192
+
218
193
  if (result < 0) {
219
194
  rb_syserr_fail(-result, strerror(-result));
220
195
  }
221
-
196
+
222
197
  resize_to_fit(buffer, NUM2SIZET(offset), (size_t)result);
223
-
198
+
224
199
  return INT2NUM(result);
225
200
  }
226
201
 
227
202
  VALUE Event_Backend_URing_io_write(VALUE self, VALUE fiber, VALUE io, VALUE buffer, VALUE offset, VALUE length) {
228
203
  struct Event_Backend_URing *data = NULL;
229
204
  TypedData_Get_Struct(self, struct Event_Backend_URing, &Event_Backend_URing_Type, data);
230
-
205
+
231
206
  if ((size_t)RSTRING_LEN(buffer) < NUM2SIZET(offset) + NUM2SIZET(length)) {
232
207
  rb_raise(rb_eRuntimeError, "invalid offset/length exceeds bounds of buffer");
233
208
  }
234
-
209
+
235
210
  int descriptor = NUM2INT(rb_funcall(io, id_fileno, 0));
236
- struct io_uring_sqe *sqe = io_uring_get_sqe(data->ring);
237
-
211
+ struct io_uring_sqe *sqe = io_uring_get_sqe(&data->ring);
212
+
238
213
  struct iovec iovecs[1];
239
214
  iovecs[0].iov_base = RSTRING_PTR(buffer) + NUM2SIZET(offset);
240
215
  iovecs[0].iov_len = NUM2SIZET(length);
241
-
216
+
242
217
  io_uring_prep_writev(sqe, descriptor, iovecs, 1, 0);
243
218
  io_uring_sqe_set_data(sqe, (void*)fiber);
244
- io_uring_submit(data->ring);
219
+ io_uring_submit(&data->ring);
245
220
 
246
221
  // fprintf(stderr, "prep_writev(%p, %d, %ld)\n", sqe, descriptor, iovecs[0].iov_len);
247
222
 
248
223
  int result = NUM2INT(rb_funcall(data->loop, id_transfer, 0));
249
-
224
+
250
225
  if (result < 0) {
251
226
  rb_syserr_fail(-result, strerror(-result));
252
227
  }
253
-
228
+
254
229
  return INT2NUM(result);
255
230
  }
256
231
 
232
+ static
233
+ struct __kernel_timespec * make_timeout(VALUE duration, struct __kernel_timespec *storage) {
234
+ if (duration == Qnil) {
235
+ return NULL;
236
+ }
237
+
238
+ if (FIXNUM_P(duration)) {
239
+ storage->tv_sec = NUM2TIMET(duration);
240
+ storage->tv_nsec = 0;
241
+
242
+ return storage;
243
+ }
244
+
245
+ else if (RB_FLOAT_TYPE_P(duration)) {
246
+ double value = RFLOAT_VALUE(duration);
247
+ time_t seconds = duration;
248
+
249
+ storage->tv_sec = seconds;
250
+ storage->tv_nsec = (value - seconds) * 1000000000L;
251
+
252
+ return storage;
253
+ }
254
+
255
+ rb_raise(rb_eRuntimeError, "unable to convert timeout");
256
+ }
257
+
257
258
  VALUE Event_Backend_URing_select(VALUE self, VALUE duration) {
258
259
  struct Event_Backend_URing *data = NULL;
259
260
  TypedData_Get_Struct(self, struct Event_Backend_URing, &Event_Backend_URing_Type, data);
@@ -261,14 +262,14 @@ VALUE Event_Backend_URing_select(VALUE self, VALUE duration) {
261
262
  struct io_uring_cqe *cqes[URING_MAX_EVENTS];
262
263
  struct __kernel_timespec storage;
263
264
 
264
- int result = io_uring_peek_batch_cqe(data->ring, cqes, URING_MAX_EVENTS);
265
+ int result = io_uring_peek_batch_cqe(&data->ring, cqes, URING_MAX_EVENTS);
265
266
 
266
267
  // fprintf(stderr, "result = %d\n", result);
267
268
 
268
269
  if (result < 0) {
269
270
  rb_syserr_fail(-result, strerror(-result));
270
- } else if (result == 0) {
271
- result = io_uring_wait_cqes(data->ring, cqes, 1, make_timeout(duration, &storage), NULL);
271
+ } else if (result == 0 && duration != Qnil) {
272
+ result = io_uring_wait_cqes(&data->ring, cqes, 1, make_timeout(duration, &storage), NULL);
272
273
 
273
274
  // fprintf(stderr, "result (timeout) = %d\n", result);
274
275
 
@@ -285,7 +286,7 @@ VALUE Event_Backend_URing_select(VALUE self, VALUE duration) {
285
286
 
286
287
  // fprintf(stderr, "cqes[i]->res = %d\n", cqes[i]->res);
287
288
 
288
- io_uring_cqe_seen(data->ring, cqes[i]);
289
+ io_uring_cqe_seen(&data->ring, cqes[i]);
289
290
 
290
291
  rb_funcall(fiber, id_transfer, 1, result);
291
292
  }
@@ -304,7 +305,7 @@ void Init_Event_Backend_URing(VALUE Event_Backend) {
304
305
 
305
306
  rb_define_method(Event_Backend_URing, "io_wait", Event_Backend_URing_io_wait, 3);
306
307
  rb_define_method(Event_Backend_URing, "select", Event_Backend_URing_select, 1);
307
-
308
+
308
309
  rb_define_method(Event_Backend_URing, "io_read", Event_Backend_URing_io_read, 5);
309
310
  rb_define_method(Event_Backend_URing, "io_write", Event_Backend_URing_io_write, 5);
310
311
  }
@@ -41,7 +41,7 @@ module Event
41
41
  end
42
42
 
43
43
  def select(duration = nil)
44
- readable, writable, _ = IO.select(@readable.keys, @writable.keys, nil, duration)
44
+ readable, writable, _ = ::IO.select(@readable.keys, @writable.keys, nil, duration)
45
45
 
46
46
  ready = Hash.new(0)
47
47
 
data/lib/event/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Event
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-27 00:00:00.000000000 Z
11
+ date: 2021-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bake
@@ -73,6 +73,7 @@ extensions:
73
73
  - ext/event/extconf.rb
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ext/event/Makefile
76
77
  - ext/event/backend/backend.h
77
78
  - ext/event/backend/epoll.c
78
79
  - ext/event/backend/epoll.h
@@ -107,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  - !ruby/object:Gem::Version
108
109
  version: '0'
109
110
  requirements: []
110
- rubygems_version: 3.1.2
111
+ rubygems_version: 3.2.3
111
112
  signing_key:
112
113
  specification_version: 4
113
114
  summary: An event loop.