event 0.1.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -25,3 +25,4 @@
25
25
  #define EVENT_BACKEND_URING
26
26
 
27
27
  void Init_Event_Backend_URing(VALUE Event_Backend);
28
+ VALUE Event_Backend_URing_select(VALUE self, VALUE duration);
data/ext/event/epoll.o ADDED
Binary file
data/ext/event/event.o ADDED
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ #ifndef EXTCONF_H
2
+ #define EXTCONF_H
3
+ #define HAVE_LIBURING_H 1
4
+ #define HAVE_SYS_EPOLL_H 1
5
+ #endif
data/ext/event/extconf.rb CHANGED
@@ -28,6 +28,8 @@ extension_name = 'event'
28
28
  # The destination
29
29
  dir_config(extension_name)
30
30
 
31
+ $CFLAGS << " -Wall"
32
+
31
33
  $srcs = ["event.c"]
32
34
  $VPATH << "$(srcdir)/backend"
33
35
 
@@ -0,0 +1,84 @@
1
+ have_library: checking for -luring... -------------------- yes
2
+
3
+ "gcc -o conftest -I/home/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-linux -I/home/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/home/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -O3 -ggdb3 -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 -Wall conftest.c -L. -L/home/samuel/.rubies/ruby-3.0.1/lib -Wl,-rpath,/home/samuel/.rubies/ruby-3.0.1/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-rpath,/home/samuel/.rubies/ruby-3.0.1/lib -L/home/samuel/.rubies/ruby-3.0.1/lib -lruby-static -lz -lpthread -lrt -lrt -lgmp -ldl -lcrypt -lm -lm -lc"
4
+ checked program was:
5
+ /* begin */
6
+ 1: #include "ruby.h"
7
+ 2:
8
+ 3: int main(int argc, char **argv)
9
+ 4: {
10
+ 5: return !!argv[argc];
11
+ 6: }
12
+ /* end */
13
+
14
+ "gcc -o conftest -I/home/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-linux -I/home/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/home/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -O3 -ggdb3 -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 -Wall conftest.c -L. -L/home/samuel/.rubies/ruby-3.0.1/lib -Wl,-rpath,/home/samuel/.rubies/ruby-3.0.1/lib -L. -fstack-protector-strong -rdynamic -Wl,-export-dynamic -Wl,-rpath,/home/samuel/.rubies/ruby-3.0.1/lib -L/home/samuel/.rubies/ruby-3.0.1/lib -lruby-static -lz -lpthread -lrt -lrt -lgmp -ldl -lcrypt -lm -luring -lm -lc"
15
+ checked program was:
16
+ /* begin */
17
+ 1: #include "ruby.h"
18
+ 2:
19
+ 3: /*top*/
20
+ 4: extern int t(void);
21
+ 5: int main(int argc, char **argv)
22
+ 6: {
23
+ 7: if (argc > 1000000) {
24
+ 8: int (* volatile tp)(void)=(int (*)(void))&t;
25
+ 9: printf("%d", (*tp)());
26
+ 10: }
27
+ 11:
28
+ 12: return !!argv[argc];
29
+ 13: }
30
+ 14:
31
+ 15: int t(void) { ; return 0; }
32
+ /* end */
33
+
34
+ --------------------
35
+
36
+ have_header: checking for liburing.h... -------------------- yes
37
+
38
+ "gcc -E -I/home/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-linux -I/home/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/home/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -O3 -ggdb3 -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 -Wall conftest.c -o conftest.i"
39
+ checked program was:
40
+ /* begin */
41
+ 1: #include "ruby.h"
42
+ 2:
43
+ 3: #include <liburing.h>
44
+ /* end */
45
+
46
+ --------------------
47
+
48
+ have_header: checking for sys/epoll.h... -------------------- yes
49
+
50
+ "gcc -E -I/home/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-linux -I/home/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/home/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -O3 -ggdb3 -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 -Wall conftest.c -o conftest.i"
51
+ checked program was:
52
+ /* begin */
53
+ 1: #include "ruby.h"
54
+ 2:
55
+ 3: #include <sys/epoll.h>
56
+ /* end */
57
+
58
+ --------------------
59
+
60
+ have_header: checking for sys/event.h... -------------------- no
61
+
62
+ "gcc -E -I/home/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-linux -I/home/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/home/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -O3 -ggdb3 -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 -Wall conftest.c -o conftest.i"
63
+ conftest.c:3:10: fatal error: sys/event.h: No such file or directory
64
+ 3 | #include <sys/event.h>
65
+ | ^~~~~~~~~~~~~
66
+ compilation terminated.
67
+ checked program was:
68
+ /* begin */
69
+ 1: #include "ruby.h"
70
+ 2:
71
+ 3: #include <sys/event.h>
72
+ /* end */
73
+
74
+ --------------------
75
+
76
+ extconf.h is:
77
+ /* begin */
78
+ 1: #ifndef EXTCONF_H
79
+ 2: #define EXTCONF_H
80
+ 3: #define HAVE_LIBURING_H 1
81
+ 4: #define HAVE_SYS_EPOLL_H 1
82
+ 5: #endif
83
+ /* end */
84
+
data/ext/event/uring.o ADDED
Binary file
data/lib/event.rb CHANGED
@@ -19,7 +19,7 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  require_relative 'event/version'
22
- require_relative 'event/backend/select'
22
+ require_relative 'event/backend'
23
23
 
24
24
  module Event
25
25
  # These constants are the same as those defined in IO.
@@ -0,0 +1,49 @@
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
+ require_relative 'backend/select'
22
+
23
+ module Event
24
+ module Backend
25
+ def self.default(env = ENV)
26
+ if backend = env['EVENT_BACKEND']&.to_sym
27
+ if Event::Backend.const_defined?(backend)
28
+ return Event::Backend.const_get(backend)
29
+ else
30
+ warn "Could not find EVENT_BACKEND=#{backend}!"
31
+ end
32
+ end
33
+
34
+ if self.const_defined?(:URing)
35
+ return Event::Backend::URing
36
+ elsif self.const_defined?(:KQueue)
37
+ return Event::Backend::KQueue
38
+ elsif self.const_defined?(:EPoll)
39
+ return Event::Backend::EPoll
40
+ else
41
+ return Event::Backend::Select
42
+ end
43
+ end
44
+
45
+ def self.new(...)
46
+ default.new(...)
47
+ end
48
+ end
49
+ end
@@ -28,35 +28,48 @@ module Event
28
28
  @writable = {}
29
29
  end
30
30
 
31
+ def close
32
+ @loop = nil
33
+ @readable = nil
34
+ @writable = nil
35
+ end
36
+
31
37
  def io_wait(fiber, io, events)
38
+ remove_readable = remove_writable = false
39
+
32
40
  if (events & READABLE) > 0 or (events & PRIORITY) > 0
33
41
  @readable[io] = fiber
42
+ remove_readable = true
34
43
  end
35
44
 
36
45
  if (events & WRITABLE) > 0
37
46
  @writable[io] = fiber
47
+ remove_writable = true
38
48
  end
39
49
 
40
50
  @loop.transfer
51
+ ensure
52
+ @readable.delete(io) if remove_readable
53
+ @writable.delete(io) if remove_writable
41
54
  end
42
55
 
43
56
  def select(duration = nil)
44
- readable, writable, _ = IO.select(@readable.keys, @writable.keys, nil, duration)
57
+ readable, writable, _ = ::IO.select(@readable.keys, @writable.keys, nil, duration)
45
58
 
46
- ready = {}
59
+ ready = Hash.new(0)
47
60
 
48
61
  readable&.each do |io|
49
62
  fiber = @readable.delete(io)
50
- ready[fiber] = true
63
+ ready[fiber] |= READABLE
51
64
  end
52
65
 
53
66
  writable&.each do |io|
54
67
  fiber = @writable.delete(io)
55
- ready[fiber] = true
68
+ ready[fiber] |= WRITABLE
56
69
  end
57
70
 
58
- ready.each_key do |fiber|
59
- fiber.transfer
71
+ ready.each do |fiber, events|
72
+ fiber.transfer(events)
60
73
  end
61
74
  end
62
75
  end
@@ -31,6 +31,15 @@ module Event
31
31
  @priority = {}
32
32
  end
33
33
 
34
+ def close
35
+ if @selector.nil?
36
+ raise "Selector already closed!"
37
+ end
38
+
39
+ @selector.close
40
+ @selector = nil
41
+ end
42
+
34
43
  def io_wait(fiber, io, events)
35
44
  register_readable(fiber, io, events)
36
45
  end
data/lib/event/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Event
2
- VERSION = "0.1.2"
2
+ VERSION = "0.4.0"
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.1.2
4
+ version: 0.4.0
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-26 00:00:00.000000000 Z
11
+ date: 2021-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bake
@@ -73,16 +73,25 @@ extensions:
73
73
  - ext/event/extconf.rb
74
74
  extra_rdoc_files: []
75
75
  files:
76
+ - ext/event/Makefile
77
+ - ext/event/backend/backend.h
76
78
  - ext/event/backend/epoll.c
77
79
  - ext/event/backend/epoll.h
78
80
  - ext/event/backend/kqueue.c
79
81
  - ext/event/backend/kqueue.h
80
82
  - ext/event/backend/uring.c
81
83
  - ext/event/backend/uring.h
84
+ - ext/event/epoll.o
82
85
  - ext/event/event.c
83
86
  - ext/event/event.h
87
+ - ext/event/event.o
88
+ - ext/event/event.so
89
+ - ext/event/extconf.h
84
90
  - ext/event/extconf.rb
91
+ - ext/event/mkmf.log
92
+ - ext/event/uring.o
85
93
  - lib/event.rb
94
+ - lib/event/backend.rb
86
95
  - lib/event/backend/select.rb
87
96
  - lib/event/debug/selector.rb
88
97
  - lib/event/selector.rb
@@ -106,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
115
  - !ruby/object:Gem::Version
107
116
  version: '0'
108
117
  requirements: []
109
- rubygems_version: 3.1.2
118
+ rubygems_version: 3.2.15
110
119
  signing_key:
111
120
  specification_version: 4
112
121
  summary: An event loop.