io-event 1.2.2 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/ext/extconf.rb +7 -24
- data/ext/io/event/selector/array.h +135 -0
- data/ext/io/event/selector/epoll.c +474 -204
- data/ext/io/event/selector/kqueue.c +513 -222
- data/ext/io/event/selector/list.h +88 -0
- data/ext/io/event/selector/selector.c +16 -21
- data/ext/io/event/selector/selector.h +23 -8
- data/ext/io/event/selector/uring.c +459 -223
- data/lib/io/event/interrupt.rb +1 -1
- data/lib/io/event/selector/nonblock.rb +1 -1
- data/lib/io/event/selector/select.rb +123 -22
- data/lib/io/event/selector.rb +2 -6
- data/lib/io/event/support.rb +11 -0
- data/lib/io/event/version.rb +2 -2
- data/lib/io/event.rb +1 -1
- data/license.md +2 -1
- data/readme.md +13 -5
- data.tar.gz.sig +0 -0
- metadata +8 -61
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3362ef0fb1bd825601c2476c06e99d32aa911a4e66b189b1518f40b6246b1ab6
|
4
|
+
data.tar.gz: a41015ab836dd0e28656427001882a87ba26a424395babb81aecd0e6d07d5fdd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1563b616697985daed4bb585bfdeaec00f6dfbaa9f377e99b278a9070f5ee32b475136e0f8f7626e4238a0d623a0bdb745ef03a612ec0de4b7f2eb9ef2f4510
|
7
|
+
data.tar.gz: d061bea14bd722ae77eddc68e81d0c4138a5de1b1b12e6fce22a45bc62391c7bf3d9dd25cf0f876361309b04d9e480a06c9752128103c999a504d01e6ffb78d3
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/ext/extconf.rb
CHANGED
@@ -2,27 +2,8 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
# Released under the MIT License.
|
5
|
-
# Copyright, 2021, by Samuel Williams.
|
6
|
-
|
7
|
-
# Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
8
|
-
#
|
9
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
10
|
-
# of this software and associated documentation files (the "Software"), to deal
|
11
|
-
# in the Software without restriction, including without limitation the rights
|
12
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
13
|
-
# copies of the Software, and to permit persons to whom the Software is
|
14
|
-
# furnished to do so, subject to the following conditions:
|
15
|
-
#
|
16
|
-
# The above copyright notice and this permission notice shall be included in
|
17
|
-
# all copies or substantial portions of the Software.
|
18
|
-
#
|
19
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
20
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
21
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
22
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
23
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
24
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
25
|
-
# THE SOFTWARE.
|
5
|
+
# Copyright, 2021-2023, by Samuel Williams.
|
6
|
+
# Copyright, 2023, by Math Ieu.
|
26
7
|
|
27
8
|
return if RUBY_DESCRIPTION =~ /jruby/
|
28
9
|
|
@@ -35,6 +16,10 @@ extension_name = 'IO_Event'
|
|
35
16
|
|
36
17
|
$CFLAGS << " -Wall -Wno-unknown-pragmas -std=c99"
|
37
18
|
|
19
|
+
if ENV.key?('RUBY_DEBUG')
|
20
|
+
$CFLAGS << " -DRUBY_DEBUG -O0"
|
21
|
+
end
|
22
|
+
|
38
23
|
$srcs = ["io/event/event.c", "io/event/selector/selector.c"]
|
39
24
|
$VPATH << "$(srcdir)/io/event"
|
40
25
|
$VPATH << "$(srcdir)/io/event/selector"
|
@@ -50,9 +35,7 @@ if have_header('sys/epoll.h')
|
|
50
35
|
$srcs << "io/event/selector/epoll.c"
|
51
36
|
end
|
52
37
|
|
53
|
-
|
54
|
-
# The `have_header` call is just to add the -D to the compiler flags.
|
55
|
-
if have_const('EV_UDATA_SPECIFIC', 'sys/event.h') and have_header('sys/event.h')
|
38
|
+
if have_header('sys/event.h')
|
56
39
|
$srcs << "io/event/selector/kqueue.c"
|
57
40
|
end
|
58
41
|
|
@@ -0,0 +1,135 @@
|
|
1
|
+
// Released under the MIT License.
|
2
|
+
// Copyright, 2023, by Samuel Williams.
|
3
|
+
|
4
|
+
// Provides a simple implementation of unique pointers to elements of the given size.
|
5
|
+
|
6
|
+
#include <stdlib.h>
|
7
|
+
#include <errno.h>
|
8
|
+
#include <assert.h>
|
9
|
+
|
10
|
+
struct IO_Event_Array {
|
11
|
+
// The array of pointers to elements:
|
12
|
+
void **base;
|
13
|
+
|
14
|
+
// The allocated size of the array:
|
15
|
+
size_t count;
|
16
|
+
|
17
|
+
// The biggest item we've seen so far:
|
18
|
+
size_t limit;
|
19
|
+
|
20
|
+
// The size of each element that is allocated:
|
21
|
+
size_t element_size;
|
22
|
+
|
23
|
+
void (*element_initialize)(void*);
|
24
|
+
void (*element_free)(void*);
|
25
|
+
};
|
26
|
+
|
27
|
+
inline static void IO_Event_Array_allocate(struct IO_Event_Array *array, size_t count, size_t element_size)
|
28
|
+
{
|
29
|
+
if (count) {
|
30
|
+
array->base = (void**)calloc(count, sizeof(void*));
|
31
|
+
array->count = count;
|
32
|
+
} else {
|
33
|
+
array->base = NULL;
|
34
|
+
array->count = 0;
|
35
|
+
}
|
36
|
+
|
37
|
+
array->limit = 0;
|
38
|
+
array->element_size = element_size;
|
39
|
+
}
|
40
|
+
|
41
|
+
inline static size_t IO_Event_Array_memory_size(const struct IO_Event_Array *array)
|
42
|
+
{
|
43
|
+
// Upper bound.
|
44
|
+
return array->count * (sizeof(void*) + array->element_size);
|
45
|
+
}
|
46
|
+
|
47
|
+
inline static void IO_Event_Array_free(struct IO_Event_Array *array)
|
48
|
+
{
|
49
|
+
for (size_t i = 0; i < array->limit; i += 1) {
|
50
|
+
void *element = array->base[i];
|
51
|
+
if (element) {
|
52
|
+
array->element_free(element);
|
53
|
+
free(element);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
if (array->base)
|
58
|
+
free(array->base);
|
59
|
+
|
60
|
+
array->base = NULL;
|
61
|
+
array->count = 0;
|
62
|
+
array->limit = 0;
|
63
|
+
}
|
64
|
+
|
65
|
+
inline static int IO_Event_Array_resize(struct IO_Event_Array *array, size_t count)
|
66
|
+
{
|
67
|
+
if (count <= array->count) {
|
68
|
+
return 0;
|
69
|
+
}
|
70
|
+
|
71
|
+
// Compute the next multiple (ideally a power of 2):
|
72
|
+
size_t new_count = array->count;
|
73
|
+
while (new_count < count) {
|
74
|
+
new_count *= 2;
|
75
|
+
}
|
76
|
+
|
77
|
+
void **new_base = (void**)realloc(array->base, new_count * sizeof(void*));
|
78
|
+
|
79
|
+
if (new_base == NULL) {
|
80
|
+
return -1;
|
81
|
+
}
|
82
|
+
|
83
|
+
// Zero out the new memory:
|
84
|
+
memset(new_base + array->count, 0, (new_count - array->count) * sizeof(void*));
|
85
|
+
|
86
|
+
array->base = (void**)new_base;
|
87
|
+
array->count = new_count;
|
88
|
+
|
89
|
+
return 1;
|
90
|
+
}
|
91
|
+
|
92
|
+
inline static void* IO_Event_Array_lookup(struct IO_Event_Array *array, size_t index)
|
93
|
+
{
|
94
|
+
size_t count = index + 1;
|
95
|
+
|
96
|
+
// Resize the array if necessary:
|
97
|
+
if (count > array->count) {
|
98
|
+
if (IO_Event_Array_resize(array, count) == -1) {
|
99
|
+
return NULL;
|
100
|
+
}
|
101
|
+
}
|
102
|
+
|
103
|
+
// Get the element:
|
104
|
+
void **element = array->base + index;
|
105
|
+
|
106
|
+
// Allocate the element if it doesn't exist:
|
107
|
+
if (*element == NULL) {
|
108
|
+
*element = malloc(array->element_size);
|
109
|
+
|
110
|
+
if (array->element_initialize) {
|
111
|
+
array->element_initialize(*element);
|
112
|
+
}
|
113
|
+
|
114
|
+
// Update the limit:
|
115
|
+
if (count > array->limit) array->limit = count;
|
116
|
+
}
|
117
|
+
|
118
|
+
return *element;
|
119
|
+
}
|
120
|
+
|
121
|
+
// Push a new element onto the end of the array.
|
122
|
+
inline static void* IO_Event_Array_push(struct IO_Event_Array *array)
|
123
|
+
{
|
124
|
+
return IO_Event_Array_lookup(array, array->limit);
|
125
|
+
}
|
126
|
+
|
127
|
+
inline static void IO_Event_Array_each(struct IO_Event_Array *array, void (*callback)(void*))
|
128
|
+
{
|
129
|
+
for (size_t i = 0; i < array->limit; i += 1) {
|
130
|
+
void *element = array->base[i];
|
131
|
+
if (element) {
|
132
|
+
callback(element);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|