event 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Binary file
data/ext/event/event.o CHANGED
Binary file
data/ext/event/extconf.rb CHANGED
@@ -47,6 +47,11 @@ if have_header('sys/event.h')
47
47
  $srcs << "backend/kqueue.c"
48
48
  end
49
49
 
50
+ have_func("rb_io_descriptor")
51
+ have_func("&rb_process_status_wait")
52
+
53
+ have_header('ruby/io/buffer.h')
54
+
50
55
  create_header
51
56
 
52
57
  # Generate the makefile to compile the native binary into `lib`:
data/ext/event/kqueue.o CHANGED
Binary file
data/ext/event/mkmf.log CHANGED
@@ -90,6 +90,101 @@ checked program was:
90
90
 
91
91
  --------------------
92
92
 
93
+ have_func: checking for rb_io_descriptor()... -------------------- no
94
+
95
+ "clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-darwin20 -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -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 -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.1/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
96
+ conftest.c:14:57: error: use of undeclared identifier 'rb_io_descriptor'
97
+ int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_io_descriptor; return !p; }
98
+ ^
99
+ 1 error generated.
100
+ checked program was:
101
+ /* begin */
102
+ 1: #include "ruby.h"
103
+ 2:
104
+ 3: /*top*/
105
+ 4: extern int t(void);
106
+ 5: int main(int argc, char **argv)
107
+ 6: {
108
+ 7: if (argc > 1000000) {
109
+ 8: int (* volatile tp)(void)=(int (*)(void))&t;
110
+ 9: printf("%d", (*tp)());
111
+ 10: }
112
+ 11:
113
+ 12: return !!argv[argc];
114
+ 13: }
115
+ 14: int t(void) { void ((*volatile p)()); p = (void ((*)()))rb_io_descriptor; return !p; }
116
+ /* end */
117
+
118
+ "clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-darwin20 -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -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 -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.1/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
119
+ Undefined symbols for architecture x86_64:
120
+ "_rb_io_descriptor", referenced from:
121
+ _t in conftest-9dccb6.o
122
+ ld: symbol(s) not found for architecture x86_64
123
+ clang: error: linker command failed with exit code 1 (use -v to see invocation)
124
+ checked program was:
125
+ /* begin */
126
+ 1: #include "ruby.h"
127
+ 2:
128
+ 3: /*top*/
129
+ 4: extern int t(void);
130
+ 5: int main(int argc, char **argv)
131
+ 6: {
132
+ 7: if (argc > 1000000) {
133
+ 8: int (* volatile tp)(void)=(int (*)(void))&t;
134
+ 9: printf("%d", (*tp)());
135
+ 10: }
136
+ 11:
137
+ 12: return !!argv[argc];
138
+ 13: }
139
+ 14: extern void rb_io_descriptor();
140
+ 15: int t(void) { rb_io_descriptor(); return 0; }
141
+ /* end */
142
+
143
+ --------------------
144
+
145
+ have_func: checking for &rb_process_status_wait()... -------------------- no
146
+
147
+ "clang -fdeclspec -o conftest -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-darwin20 -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -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 -pipe -Wall conftest.c -L. -L/Users/samuel/.rubies/ruby-3.0.1/lib -L/opt/local/lib -L. -fstack-protector-strong -L/opt/local/lib -lruby.3.0-static -framework Security -framework Foundation -lpthread -lgmp -ldl -lobjc "
148
+ conftest.c:14:76: error: use of undeclared identifier 'rb_process_status_wait'
149
+ int t(void) { const volatile void *volatile p; p = (const volatile void *)&rb_process_status_wait; return !p; }
150
+ ^
151
+ 1 error generated.
152
+ checked program was:
153
+ /* begin */
154
+ 1: #include "ruby.h"
155
+ 2:
156
+ 3: /*top*/
157
+ 4: extern int t(void);
158
+ 5: int main(int argc, char **argv)
159
+ 6: {
160
+ 7: if (argc > 1000000) {
161
+ 8: int (* volatile tp)(void)=(int (*)(void))&t;
162
+ 9: printf("%d", (*tp)());
163
+ 10: }
164
+ 11:
165
+ 12: return !!argv[argc];
166
+ 13: }
167
+ 14: int t(void) { const volatile void *volatile p; p = (const volatile void *)&rb_process_status_wait; return !p; }
168
+ /* end */
169
+
170
+ --------------------
171
+
172
+ have_header: checking for ruby/io/buffer.h... -------------------- no
173
+
174
+ "clang -E -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/x86_64-darwin20 -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0/ruby/backward -I/Users/samuel/.rubies/ruby-3.0.1/include/ruby-3.0.0 -I. -I/opt/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdivision-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -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 -pipe -Wall conftest.c -o conftest.i"
175
+ conftest.c:3:10: fatal error: 'ruby/io/buffer.h' file not found
176
+ #include <ruby/io/buffer.h>
177
+ ^~~~~~~~~~~~~~~~~~
178
+ 1 error generated.
179
+ checked program was:
180
+ /* begin */
181
+ 1: #include "ruby.h"
182
+ 2:
183
+ 3: #include <ruby/io/buffer.h>
184
+ /* end */
185
+
186
+ --------------------
187
+
93
188
  extconf.h is:
94
189
  /* begin */
95
190
  1: #ifndef EXTCONF_H
@@ -26,6 +26,8 @@ module Event
26
26
 
27
27
  @readable = {}
28
28
  @writable = {}
29
+
30
+ @ready = []
29
31
  end
30
32
 
31
33
  def close
@@ -34,6 +36,24 @@ module Event
34
36
  @writable = nil
35
37
  end
36
38
 
39
+ def defer
40
+ fiber = Fiber.current
41
+ @ready.push(fiber)
42
+ @loop.transfer
43
+ ensure
44
+ # Linear scan :(
45
+ @ready.delete(fiber)
46
+ end
47
+
48
+ def transfer(fiber)
49
+ @ready.push(Fiber.current)
50
+ fiber.transfer
51
+ end
52
+
53
+ def ready?
54
+ @ready.any?
55
+ end
56
+
37
57
  def io_wait(fiber, io, events)
38
58
  remove_readable = remove_writable = false
39
59
 
@@ -53,47 +73,51 @@ module Event
53
73
  @writable.delete(io) if remove_writable
54
74
  end
55
75
 
56
- def io_read(fiber, io, buffer, offset, length)
57
- buffer.force_encoding(Encoding::BINARY)
58
-
59
- while length > 0
60
- case result = io.read_nonblock(length, exception: false)
61
- when :wait_readable
62
- self.io_wait(fiber, io, READABLE)
63
- when :wait_writable
64
- self.io_wait(fiber, io, WRITABLE)
65
- else
66
- result.force_encoding(Encoding::BINARY)
67
- buffer[offset, result.bytesize] = result
76
+ if IO.const_defined?(:Buffer)
77
+ def io_read(fiber, io, buffer, length)
78
+ offset = 0
79
+
80
+ while length > 0
81
+ # The maximum size we can read:
82
+ maximum_size = buffer.size - offset
68
83
 
69
- offset += result.bytesize
70
- length -= result.bytesize
84
+ case result = io.read_nonblock(maximum_size, exception: false)
85
+ when :wait_readable
86
+ self.io_wait(fiber, io, READABLE)
87
+ when :wait_writable
88
+ self.io_wait(fiber, io, WRITABLE)
89
+ else
90
+ break if result.empty?
91
+
92
+ buffer.copy(result, offset)
93
+
94
+ offset += result.bytesize
95
+ length -= result.bytesize
96
+ end
71
97
  end
98
+
99
+ return offset
72
100
  end
73
- rescue EOFError
74
- return nil
75
- end
76
-
77
- def io_write(fiber, io, buffer, offset, length)
78
- buffer.force_encoding(Encoding::BINARY)
79
101
 
80
- total = 0
81
-
82
- while length > 0
83
- chunk = buffer[offset, length]
84
- case result = io.write_nonblock(chunk, exception: false)
85
- when :wait_readable
86
- self.io_wait(fiber, io, READABLE)
87
- when :wait_writable
88
- self.io_wait(fiber, io, WRITABLE)
89
- else
90
- offset += result
91
- length -= result
92
- total += result
102
+ def io_write(fiber, io, buffer, length)
103
+ offset = 0
104
+
105
+ while length > 0
106
+ # From offset until the end:
107
+ chunk = buffer.to_str(offset, length)
108
+ case result = io.write_nonblock(chunk, exception: false)
109
+ when :wait_readable
110
+ self.io_wait(fiber, io, READABLE)
111
+ when :wait_writable
112
+ self.io_wait(fiber, io, WRITABLE)
113
+ else
114
+ offset += result
115
+ length -= result
116
+ end
93
117
  end
118
+
119
+ return offset
94
120
  end
95
-
96
- return total
97
121
  end
98
122
 
99
123
  def process_wait(fiber, pid, flags)
@@ -115,6 +139,10 @@ module Event
115
139
  end
116
140
 
117
141
  def select(duration = nil)
142
+ while @ready.any?
143
+ @ready.pop.transfer
144
+ end
145
+
118
146
  readable, writable, _ = ::IO.select(@readable.keys, @writable.keys, nil, duration)
119
147
 
120
148
  ready = Hash.new(0)
data/lib/event/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Event
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.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.6.0
4
+ version: 0.7.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-07-01 00:00:00.000000000 Z
11
+ date: 2021-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bake