event 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/event/Makefile +3 -3
- data/ext/event/event.bundle +0 -0
- data/ext/event/event.c +10 -10
- data/ext/event/event.h +3 -3
- data/ext/event/event.o +0 -0
- data/ext/event/extconf.rb +6 -5
- data/ext/event/kqueue.o +0 -0
- data/ext/event/mkmf.log +32 -1
- data/ext/event/selector.o +0 -0
- data/ext/event/{backend → selector}/epoll.c +112 -89
- data/ext/event/{backend → selector}/epoll.h +2 -2
- data/ext/event/{backend → selector}/kqueue.c +115 -94
- data/ext/event/{backend → selector}/kqueue.h +2 -2
- data/ext/event/{backend → selector}/pidfd.c +0 -0
- data/ext/event/selector/selector.c +263 -0
- data/ext/event/selector/selector.h +127 -0
- data/ext/event/{backend → selector}/uring.c +131 -107
- data/ext/event/{backend → selector}/uring.h +3 -3
- data/lib/event.rb +2 -1
- data/lib/event/debug.rb +126 -0
- data/lib/event/selector.rb +25 -2
- data/lib/event/{backend → selector}/select.rb +24 -7
- data/lib/event/version.rb +1 -1
- metadata +14 -15
- data/ext/event/backend.o +0 -0
- data/ext/event/backend/backend.c +0 -178
- data/ext/event/backend/backend.h +0 -112
- data/lib/event/backend.rb +0 -49
- data/lib/event/debug/selector.rb +0 -108
data/ext/event/backend/backend.h
DELETED
@@ -1,112 +0,0 @@
|
|
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 <ruby.h>
|
22
|
-
#include <ruby/thread.h>
|
23
|
-
#include <ruby/io.h>
|
24
|
-
|
25
|
-
#ifdef HAVE_RUBY_IO_BUFFER_H
|
26
|
-
#include <ruby/io/buffer.h>
|
27
|
-
#endif
|
28
|
-
|
29
|
-
#include <time.h>
|
30
|
-
|
31
|
-
enum Event {
|
32
|
-
READABLE = 1,
|
33
|
-
PRIORITY = 2,
|
34
|
-
WRITABLE = 4,
|
35
|
-
ERROR = 8,
|
36
|
-
HANGUP = 16
|
37
|
-
};
|
38
|
-
|
39
|
-
void Init_Event_Backend();
|
40
|
-
|
41
|
-
#ifdef HAVE__RB_FIBER_TRANSFER
|
42
|
-
#define Event_Backend_fiber_transfer(fiber) rb_fiber_transfer(fiber, 0, NULL)
|
43
|
-
#define Event_Backend_fiber_transfer_result(fiber, argument) rb_fiber_transfer(fiber, 1, &argument)
|
44
|
-
#else
|
45
|
-
VALUE Event_Backend_fiber_transfer(VALUE fiber);
|
46
|
-
VALUE Event_Backend_fiber_transfer_result(VALUE fiber, VALUE argument);
|
47
|
-
#endif
|
48
|
-
|
49
|
-
#ifdef HAVE_RB_IO_DESCRIPTOR
|
50
|
-
#define Event_Backend_io_descriptor(io) rb_io_descriptor(io)
|
51
|
-
#else
|
52
|
-
int Event_Backend_io_descriptor(VALUE io);
|
53
|
-
#endif
|
54
|
-
|
55
|
-
#ifdef HAVE_RB_PROCESS_STATUS_WAIT
|
56
|
-
#define Event_Backend_process_status_wait(pid) rb_process_status_wait(pid)
|
57
|
-
#else
|
58
|
-
VALUE Event_Backend_process_status_wait(rb_pid_t pid);
|
59
|
-
#endif
|
60
|
-
|
61
|
-
int Event_Backend_nonblock_set(int file_descriptor);
|
62
|
-
void Event_Backend_nonblock_restore(int file_descriptor, int flags);
|
63
|
-
|
64
|
-
struct Event_Backend_Queue {
|
65
|
-
struct Event_Backend_Queue *behind;
|
66
|
-
struct Event_Backend_Queue *infront;
|
67
|
-
|
68
|
-
VALUE fiber;
|
69
|
-
};
|
70
|
-
|
71
|
-
struct Event_Backend {
|
72
|
-
VALUE loop;
|
73
|
-
|
74
|
-
// Append to waiting.
|
75
|
-
struct Event_Backend_Queue *waiting;
|
76
|
-
// Process from ready.
|
77
|
-
struct Event_Backend_Queue *ready;
|
78
|
-
};
|
79
|
-
|
80
|
-
inline
|
81
|
-
void Event_Backend_initialize(struct Event_Backend *backend, VALUE loop) {
|
82
|
-
backend->loop = loop;
|
83
|
-
backend->waiting = NULL;
|
84
|
-
backend->ready = NULL;
|
85
|
-
}
|
86
|
-
|
87
|
-
inline
|
88
|
-
void Event_Backend_mark(struct Event_Backend *backend) {
|
89
|
-
rb_gc_mark(backend->loop);
|
90
|
-
|
91
|
-
struct Event_Backend_Queue *ready = backend->ready;
|
92
|
-
while (ready) {
|
93
|
-
rb_gc_mark(ready->fiber);
|
94
|
-
ready = ready->behind;
|
95
|
-
}
|
96
|
-
}
|
97
|
-
|
98
|
-
void Event_Backend_wait_and_transfer(struct Event_Backend *backend, VALUE fiber);
|
99
|
-
|
100
|
-
inline
|
101
|
-
void Event_Backend_defer(struct Event_Backend *backend)
|
102
|
-
{
|
103
|
-
Event_Backend_wait_and_transfer(backend, backend->loop);
|
104
|
-
}
|
105
|
-
|
106
|
-
void Event_Backend_ready_pop(struct Event_Backend *backend);
|
107
|
-
|
108
|
-
void Event_Backend_elapsed_time(struct timespec* start, struct timespec* stop, struct timespec *duration);
|
109
|
-
void Event_Backend_current_time(struct timespec *time);
|
110
|
-
|
111
|
-
#define PRINTF_TIMESPEC "%lld.%.9ld"
|
112
|
-
#define PRINTF_TIMESPEC_ARGS(ts) (long long)((ts).tv_sec), (ts).tv_nsec
|
data/lib/event/backend.rb
DELETED
@@ -1,49 +0,0 @@
|
|
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
|
data/lib/event/debug/selector.rb
DELETED
@@ -1,108 +0,0 @@
|
|
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 "event/version"
|
22
|
-
|
23
|
-
module Event
|
24
|
-
module Debug
|
25
|
-
class Selector
|
26
|
-
def initialize(selector)
|
27
|
-
@selector = selector
|
28
|
-
|
29
|
-
@readable = {}
|
30
|
-
@writable = {}
|
31
|
-
@priority = {}
|
32
|
-
end
|
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
|
-
|
43
|
-
def io_wait(fiber, io, events)
|
44
|
-
register_readable(fiber, io, events)
|
45
|
-
end
|
46
|
-
|
47
|
-
def select(duration = nil)
|
48
|
-
@selector.select(duration)
|
49
|
-
end
|
50
|
-
|
51
|
-
private
|
52
|
-
|
53
|
-
def register_readable(fiber, io, events)
|
54
|
-
if (events & READABLE) > 0
|
55
|
-
if @readable.key?(io)
|
56
|
-
raise "Cannot wait for #{io} to become readable from multiple fibers."
|
57
|
-
end
|
58
|
-
|
59
|
-
begin
|
60
|
-
@readable[io] = fiber
|
61
|
-
|
62
|
-
register_writable(fiber, io, events)
|
63
|
-
ensure
|
64
|
-
@readable.delete(io)
|
65
|
-
end
|
66
|
-
else
|
67
|
-
register_writable(fiber, io, events)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def register_writable(fiber, io, events)
|
72
|
-
if (events & WRITABLE) > 0
|
73
|
-
if @writable.key?(io)
|
74
|
-
raise "Cannot wait for #{io} to become writable from multiple fibers."
|
75
|
-
end
|
76
|
-
|
77
|
-
begin
|
78
|
-
@writable[io] = fiber
|
79
|
-
|
80
|
-
register_priority(fiber, io, events)
|
81
|
-
ensure
|
82
|
-
@writable.delete(io)
|
83
|
-
end
|
84
|
-
else
|
85
|
-
register_priority(fiber, io, events)
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def register_priority(fiber, io, events)
|
90
|
-
if (events & PRIORITY) > 0
|
91
|
-
if @priority.key?(io)
|
92
|
-
raise "Cannot wait for #{io} to become priority from multiple fibers."
|
93
|
-
end
|
94
|
-
|
95
|
-
begin
|
96
|
-
@priority[io] = fiber
|
97
|
-
|
98
|
-
@selector.io_wait(fiber, io, events)
|
99
|
-
ensure
|
100
|
-
@priority.delete(io)
|
101
|
-
end
|
102
|
-
else
|
103
|
-
@selector.io_wait(fiber, io, events)
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
108
|
-
end
|