nio4r 2.5.8 → 2.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/workflow.yml +33 -19
- data/.mailmap +16 -0
- data/Gemfile +5 -4
- data/{CHANGES.md → changes.md} +37 -0
- data/examples/echo_server.rb +7 -0
- data/ext/nio4r/bytebuffer.c +75 -38
- data/ext/nio4r/extconf.rb +19 -1
- data/ext/nio4r/monitor.c +47 -22
- data/ext/nio4r/nio4r.h +1 -5
- data/ext/nio4r/org/nio4r/ByteBuffer.java +1 -1
- data/ext/nio4r/org/nio4r/Monitor.java +2 -2
- data/ext/nio4r/org/nio4r/Selector.java +2 -2
- data/ext/nio4r/selector.c +72 -48
- data/lib/nio/bytebuffer.rb +6 -0
- data/lib/nio/monitor.rb +7 -0
- data/lib/nio/selector.rb +15 -0
- data/lib/nio/version.rb +6 -1
- data/lib/nio.rb +9 -0
- data/lib/nio4r.rb +5 -0
- data/license.md +77 -0
- data/nio4r.gemspec +4 -3
- data/rakelib/extension.rake +1 -2
- data/readme.md +95 -0
- data/spec/nio/acceptables_spec.rb +4 -0
- data/spec/nio/bytebuffer_spec.rb +6 -0
- data/spec/nio/monitor_spec.rb +7 -0
- data/spec/nio/selectables/pipe_spec.rb +6 -0
- data/spec/nio/selectables/ssl_socket_spec.rb +8 -3
- data/spec/nio/selectables/tcp_socket_spec.rb +7 -0
- data/spec/nio/selectables/udp_socket_spec.rb +7 -0
- data/spec/nio/selector_spec.rb +12 -0
- data/spec/spec_helper.rb +5 -2
- data/spec/support/selectable_examples.rb +8 -0
- metadata +12 -7
- data/README.md +0 -133
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54febf2b0d954eb8270ca97cd81e552f3c8ef975b4abb2d8265dcc6151df725f
|
4
|
+
data.tar.gz: 655358505bcbde6a568e585b3f166160d10d97ffd04d8b47ae983e3e6fd3119b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32cbd3ff499173cd7adb3797fadfda14aea5e74638632609dd4d2bda625f274acd0941a1a6f5790bf080d041c7ecb1d2eb17379e13688500ecf904458e5f6070
|
7
|
+
data.tar.gz: b904ecc64938f5206ad046202bdd48d700457967aa49365ab78916584b035ce1b72c6eb77f56ecb9926e1b6aeb7df54960f0380142cba1300bb3edc59e2cb313
|
@@ -14,34 +14,48 @@ jobs:
|
|
14
14
|
strategy:
|
15
15
|
fail-fast: false
|
16
16
|
matrix:
|
17
|
-
os:
|
18
|
-
|
17
|
+
os:
|
18
|
+
- ubuntu-22.04
|
19
|
+
- macos-11
|
20
|
+
- windows-2022
|
21
|
+
ruby:
|
22
|
+
- "2.4"
|
23
|
+
- "2.5"
|
24
|
+
- "2.6"
|
25
|
+
- "2.7"
|
26
|
+
- "3.0"
|
27
|
+
- "3.1"
|
28
|
+
- "3.2"
|
29
|
+
- "head"
|
30
|
+
- "jruby"
|
31
|
+
- "truffleruby"
|
19
32
|
include:
|
20
|
-
- {
|
21
|
-
- {
|
33
|
+
- {os: ubuntu-20.04, ruby: "3.2"}
|
34
|
+
- {os: windows-2019, ruby: "3.2"}
|
35
|
+
- {os: windows-2022, ruby: ucrt}
|
22
36
|
exclude:
|
23
|
-
- {
|
24
|
-
- {
|
25
|
-
- {
|
37
|
+
- {os: windows-2022, ruby: head}
|
38
|
+
- {os: windows-2022, ruby: jruby}
|
39
|
+
- {os: windows-2022, ruby: truffleruby}
|
26
40
|
|
27
41
|
steps:
|
28
|
-
-
|
29
|
-
uses: actions/checkout@v2
|
42
|
+
- uses: actions/checkout@v3
|
30
43
|
|
31
|
-
- name:
|
32
|
-
|
44
|
+
- name: set JAVA_HOME
|
45
|
+
if: |
|
46
|
+
startsWith(matrix.ruby, 'jruby')
|
47
|
+
shell: bash
|
48
|
+
run: |
|
49
|
+
echo JAVA_HOME=$JAVA_HOME_11_X64 >> $GITHUB_ENV
|
50
|
+
|
51
|
+
- uses: ruby/setup-ruby@v1
|
33
52
|
with:
|
34
53
|
ruby-version: ${{matrix.ruby}}
|
54
|
+
bundler-cache: true
|
35
55
|
|
36
|
-
- name:
|
37
|
-
run: gem update --system --no-document --conservative
|
38
|
-
|
39
|
-
- name: bundle install
|
40
|
-
run: bundle install --path .bundle/gems --without development
|
41
|
-
|
42
|
-
- name: compile
|
56
|
+
- name: Compile
|
43
57
|
run: bundle exec rake compile
|
44
58
|
|
45
|
-
- name:
|
59
|
+
- name: Test
|
46
60
|
run: bundle exec rake spec
|
47
61
|
timeout-minutes: 10
|
data/.mailmap
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
Sadayuki Furuhashi <frsyuki@users.sourceforge.jp>
|
2
|
+
Shannon Skipper <shannonskipper@gmail.com>
|
3
|
+
Anatol Pomozov <anatol.pomozov@gmail.com>
|
4
|
+
Hiroshi Shibata <shibata.hiroshi@gmail.com>
|
5
|
+
John Thornton <ubergeek3141@gmail.com>
|
6
|
+
Upekshe Jayasekera <usmj000@gmail.com>
|
7
|
+
Upekshe Jayasekera <upekshej.11@cse.mrt.ac.lk>
|
8
|
+
Usaku Nakamura <usa@garbagecollect.jp>
|
9
|
+
Tomoya Ishida <tomoyapenguin@gmail.com>
|
10
|
+
Tiago Cardoso <cardoso_tiago@hotmail.com>
|
11
|
+
Ravil Bayramgalin <brainopia@evilmartians.com>
|
12
|
+
Gregory Longtin <Greg.mpls@gmail.com>
|
13
|
+
Gregory Longtin <Greg.mpls@gmail.com> <MSP-Greg@users.noreply.github.com>
|
14
|
+
Elad Eyal <elad.eyal@intel.com>
|
15
|
+
Boaz Segev <bo@bowild.com>
|
16
|
+
Tao Luo <luotao.ruby@gmail.com>
|
data/Gemfile
CHANGED
@@ -6,13 +6,14 @@ gemspec
|
|
6
6
|
|
7
7
|
gem "jruby-openssl" if defined? JRUBY_VERSION
|
8
8
|
|
9
|
-
group :
|
10
|
-
gem "
|
9
|
+
group :maintenance, optional: true do
|
10
|
+
gem "bake"
|
11
|
+
gem "bake-gem"
|
12
|
+
# gem "bake-modernize"
|
11
13
|
end
|
12
14
|
|
13
15
|
group :development, :test do
|
14
|
-
gem "
|
15
|
-
gem "rake-compiler", require: false
|
16
|
+
gem "rake-compiler", "~> 1.1.9", require: false
|
16
17
|
gem "rspec", "~> 3.7", require: false
|
17
18
|
gem "rubocop", "0.82.0", require: false
|
18
19
|
end
|
data/{CHANGES.md → changes.md}
RENAMED
@@ -1,3 +1,40 @@
|
|
1
|
+
## 2.7.0
|
2
|
+
|
3
|
+
* Convert NIO objects to TypedData API.
|
4
|
+
|
5
|
+
## 2.6.1
|
6
|
+
|
7
|
+
* Don't update `io` which is subsequently stored. Retain the original.
|
8
|
+
|
9
|
+
## 2.6.0
|
10
|
+
|
11
|
+
* Fix conversion loses int precision.
|
12
|
+
* Avoid direct access to IO internals.
|
13
|
+
* Resolve issue loading both nio and nio4r gems.
|
14
|
+
|
15
|
+
## 2.5.9 (2023-04-02)
|
16
|
+
|
17
|
+
https://github.com/socketry/nio4r/compare/v2.5.8..v2.5.9
|
18
|
+
|
19
|
+
## 2.5.8 (2021-08-03)
|
20
|
+
|
21
|
+
* [#276](https://github.com/socketry/nio4r/pull/276)
|
22
|
+
Fix missing return statement in function returning non-void (issue [#275](https://github.com/socketry/nio4r/pull/275))
|
23
|
+
([@ioquatix])
|
24
|
+
* Remove `guard-rspec` from development dependencies ([@ioquatix])
|
25
|
+
|
26
|
+
## 2.5.7 (2021-03-04)
|
27
|
+
|
28
|
+
* [#267](https://github.com/socketry/nio4r/pull/267)
|
29
|
+
Don't try to link universal extension
|
30
|
+
([@ioquatix])
|
31
|
+
|
32
|
+
## 2.5.6 (2021-03-04)
|
33
|
+
|
34
|
+
* [#268](https://github.com/socketry/nio4r/pull/268)
|
35
|
+
Prefer kqueue when on OSX >= v10.12.2
|
36
|
+
([@jcmfernandes])
|
37
|
+
|
1
38
|
## 2.5.5 (2021-02-05)
|
2
39
|
|
3
40
|
* [#256](https://github.com/socketry/nio4r/pull/256)
|
data/examples/echo_server.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
# Released under the MIT License.
|
5
|
+
# Copyright, 2012-2016, by Tony Arcieri.
|
6
|
+
# Copyright, 2016, by Jun Aruga.
|
7
|
+
# Copyright, 2019, by Zhang Kang.
|
8
|
+
# Copyright, 2020, by Thomas Dziedzic.
|
9
|
+
# Copyright, 2023, by Samuel Williams.
|
10
|
+
|
4
11
|
$LOAD_PATH.push File.expand_path("../lib", __dir__)
|
5
12
|
require "nio"
|
6
13
|
require "socket"
|
data/ext/nio4r/bytebuffer.c
CHANGED
@@ -8,8 +8,8 @@ static VALUE cNIO_ByteBuffer_MarkUnsetError = Qnil;
|
|
8
8
|
|
9
9
|
/* Allocator/deallocator */
|
10
10
|
static VALUE NIO_ByteBuffer_allocate(VALUE klass);
|
11
|
-
static void
|
12
|
-
static
|
11
|
+
static void NIO_ByteBuffer_free(void *data);
|
12
|
+
static size_t NIO_ByteBuffer_memsize(const void *data);
|
13
13
|
|
14
14
|
/* Methods */
|
15
15
|
static VALUE NIO_ByteBuffer_initialize(VALUE self, VALUE capacity);
|
@@ -36,6 +36,26 @@ static VALUE NIO_ByteBuffer_inspect(VALUE self);
|
|
36
36
|
|
37
37
|
#define MARK_UNSET -1
|
38
38
|
|
39
|
+
/* Compatibility for Ruby <= 3.1 */
|
40
|
+
#ifndef HAVE_RB_IO_DESCRIPTOR
|
41
|
+
static int
|
42
|
+
io_descriptor_fallback(VALUE io)
|
43
|
+
{
|
44
|
+
rb_io_t *fptr;
|
45
|
+
GetOpenFile(io, fptr);
|
46
|
+
return fptr->fd;
|
47
|
+
}
|
48
|
+
#define rb_io_descriptor io_descriptor_fallback
|
49
|
+
#endif
|
50
|
+
|
51
|
+
static void
|
52
|
+
io_set_nonblock(VALUE io)
|
53
|
+
{
|
54
|
+
rb_io_t *fptr;
|
55
|
+
GetOpenFile(io, fptr);
|
56
|
+
rb_io_set_nonblock(fptr);
|
57
|
+
}
|
58
|
+
|
39
59
|
void Init_NIO_ByteBuffer()
|
40
60
|
{
|
41
61
|
mNIO = rb_define_module("NIO");
|
@@ -72,28 +92,46 @@ void Init_NIO_ByteBuffer()
|
|
72
92
|
rb_define_method(cNIO_ByteBuffer, "inspect", NIO_ByteBuffer_inspect, 0);
|
73
93
|
}
|
74
94
|
|
95
|
+
static const rb_data_type_t NIO_ByteBuffer_type = {
|
96
|
+
"NIO::ByteBuffer",
|
97
|
+
{
|
98
|
+
NULL, // Nothing to mark
|
99
|
+
NIO_ByteBuffer_free,
|
100
|
+
NIO_ByteBuffer_memsize,
|
101
|
+
},
|
102
|
+
0,
|
103
|
+
0,
|
104
|
+
RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED
|
105
|
+
};
|
106
|
+
|
75
107
|
static VALUE NIO_ByteBuffer_allocate(VALUE klass)
|
76
108
|
{
|
77
109
|
struct NIO_ByteBuffer *bytebuffer = (struct NIO_ByteBuffer *)xmalloc(sizeof(struct NIO_ByteBuffer));
|
78
110
|
bytebuffer->buffer = NULL;
|
79
|
-
return
|
111
|
+
return TypedData_Wrap_Struct(klass, &NIO_ByteBuffer_type, bytebuffer);
|
80
112
|
}
|
81
113
|
|
82
|
-
static void
|
114
|
+
static void NIO_ByteBuffer_free(void *data)
|
83
115
|
{
|
116
|
+
struct NIO_ByteBuffer *buffer = (struct NIO_ByteBuffer *)data;
|
117
|
+
if (buffer->buffer)
|
118
|
+
xfree(buffer->buffer);
|
119
|
+
xfree(buffer);
|
84
120
|
}
|
85
121
|
|
86
|
-
static
|
122
|
+
static size_t NIO_ByteBuffer_memsize(const void *data)
|
87
123
|
{
|
124
|
+
const struct NIO_ByteBuffer *buffer = (const struct NIO_ByteBuffer *)data;
|
125
|
+
size_t memsize = sizeof(struct NIO_ByteBuffer);
|
88
126
|
if (buffer->buffer)
|
89
|
-
|
90
|
-
|
127
|
+
memsize += buffer->capacity;
|
128
|
+
return memsize;
|
91
129
|
}
|
92
130
|
|
93
131
|
static VALUE NIO_ByteBuffer_initialize(VALUE self, VALUE capacity)
|
94
132
|
{
|
95
133
|
struct NIO_ByteBuffer *buffer;
|
96
|
-
|
134
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
97
135
|
|
98
136
|
buffer->capacity = NUM2INT(capacity);
|
99
137
|
buffer->buffer = xmalloc(buffer->capacity);
|
@@ -106,7 +144,7 @@ static VALUE NIO_ByteBuffer_initialize(VALUE self, VALUE capacity)
|
|
106
144
|
static VALUE NIO_ByteBuffer_clear(VALUE self)
|
107
145
|
{
|
108
146
|
struct NIO_ByteBuffer *buffer;
|
109
|
-
|
147
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
110
148
|
|
111
149
|
memset(buffer->buffer, 0, buffer->capacity);
|
112
150
|
|
@@ -120,7 +158,7 @@ static VALUE NIO_ByteBuffer_clear(VALUE self)
|
|
120
158
|
static VALUE NIO_ByteBuffer_get_position(VALUE self)
|
121
159
|
{
|
122
160
|
struct NIO_ByteBuffer *buffer;
|
123
|
-
|
161
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
124
162
|
|
125
163
|
return INT2NUM(buffer->position);
|
126
164
|
}
|
@@ -129,7 +167,7 @@ static VALUE NIO_ByteBuffer_set_position(VALUE self, VALUE new_position)
|
|
129
167
|
{
|
130
168
|
int pos;
|
131
169
|
struct NIO_ByteBuffer *buffer;
|
132
|
-
|
170
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
133
171
|
|
134
172
|
pos = NUM2INT(new_position);
|
135
173
|
|
@@ -153,7 +191,7 @@ static VALUE NIO_ByteBuffer_set_position(VALUE self, VALUE new_position)
|
|
153
191
|
static VALUE NIO_ByteBuffer_get_limit(VALUE self)
|
154
192
|
{
|
155
193
|
struct NIO_ByteBuffer *buffer;
|
156
|
-
|
194
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
157
195
|
|
158
196
|
return INT2NUM(buffer->limit);
|
159
197
|
}
|
@@ -162,7 +200,7 @@ static VALUE NIO_ByteBuffer_set_limit(VALUE self, VALUE new_limit)
|
|
162
200
|
{
|
163
201
|
int lim;
|
164
202
|
struct NIO_ByteBuffer *buffer;
|
165
|
-
|
203
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
166
204
|
|
167
205
|
lim = NUM2INT(new_limit);
|
168
206
|
|
@@ -190,7 +228,7 @@ static VALUE NIO_ByteBuffer_set_limit(VALUE self, VALUE new_limit)
|
|
190
228
|
static VALUE NIO_ByteBuffer_capacity(VALUE self)
|
191
229
|
{
|
192
230
|
struct NIO_ByteBuffer *buffer;
|
193
|
-
|
231
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
194
232
|
|
195
233
|
return INT2NUM(buffer->capacity);
|
196
234
|
}
|
@@ -198,7 +236,7 @@ static VALUE NIO_ByteBuffer_capacity(VALUE self)
|
|
198
236
|
static VALUE NIO_ByteBuffer_remaining(VALUE self)
|
199
237
|
{
|
200
238
|
struct NIO_ByteBuffer *buffer;
|
201
|
-
|
239
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
202
240
|
|
203
241
|
return INT2NUM(buffer->limit - buffer->position);
|
204
242
|
}
|
@@ -206,7 +244,7 @@ static VALUE NIO_ByteBuffer_remaining(VALUE self)
|
|
206
244
|
static VALUE NIO_ByteBuffer_full(VALUE self)
|
207
245
|
{
|
208
246
|
struct NIO_ByteBuffer *buffer;
|
209
|
-
|
247
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
210
248
|
|
211
249
|
return buffer->position == buffer->limit ? Qtrue : Qfalse;
|
212
250
|
}
|
@@ -216,7 +254,7 @@ static VALUE NIO_ByteBuffer_get(int argc, VALUE *argv, VALUE self)
|
|
216
254
|
int len;
|
217
255
|
VALUE length, result;
|
218
256
|
struct NIO_ByteBuffer *buffer;
|
219
|
-
|
257
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
220
258
|
|
221
259
|
rb_scan_args(argc, argv, "01", &length);
|
222
260
|
|
@@ -244,7 +282,7 @@ static VALUE NIO_ByteBuffer_fetch(VALUE self, VALUE index)
|
|
244
282
|
{
|
245
283
|
int i;
|
246
284
|
struct NIO_ByteBuffer *buffer;
|
247
|
-
|
285
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
248
286
|
|
249
287
|
i = NUM2INT(index);
|
250
288
|
|
@@ -263,7 +301,7 @@ static VALUE NIO_ByteBuffer_put(VALUE self, VALUE string)
|
|
263
301
|
{
|
264
302
|
long length;
|
265
303
|
struct NIO_ByteBuffer *buffer;
|
266
|
-
|
304
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
267
305
|
|
268
306
|
StringValue(string);
|
269
307
|
length = RSTRING_LEN(string);
|
@@ -281,19 +319,19 @@ static VALUE NIO_ByteBuffer_put(VALUE self, VALUE string)
|
|
281
319
|
static VALUE NIO_ByteBuffer_read_from(VALUE self, VALUE io)
|
282
320
|
{
|
283
321
|
struct NIO_ByteBuffer *buffer;
|
284
|
-
rb_io_t *fptr;
|
285
322
|
ssize_t nbytes, bytes_read;
|
286
323
|
|
287
|
-
|
288
|
-
|
289
|
-
|
324
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
325
|
+
|
326
|
+
io = rb_convert_type(io, T_FILE, "IO", "to_io");
|
327
|
+
io_set_nonblock(io);
|
290
328
|
|
291
329
|
nbytes = buffer->limit - buffer->position;
|
292
330
|
if (nbytes == 0) {
|
293
331
|
rb_raise(cNIO_ByteBuffer_OverflowError, "buffer is full");
|
294
332
|
}
|
295
333
|
|
296
|
-
bytes_read = read(
|
334
|
+
bytes_read = read(rb_io_descriptor(io), buffer->buffer + buffer->position, nbytes);
|
297
335
|
|
298
336
|
if (bytes_read < 0) {
|
299
337
|
if (errno == EAGAIN) {
|
@@ -305,25 +343,24 @@ static VALUE NIO_ByteBuffer_read_from(VALUE self, VALUE io)
|
|
305
343
|
|
306
344
|
buffer->position += bytes_read;
|
307
345
|
|
308
|
-
return
|
346
|
+
return SIZET2NUM(bytes_read);
|
309
347
|
}
|
310
348
|
|
311
349
|
static VALUE NIO_ByteBuffer_write_to(VALUE self, VALUE io)
|
312
350
|
{
|
313
351
|
struct NIO_ByteBuffer *buffer;
|
314
|
-
rb_io_t *fptr;
|
315
352
|
ssize_t nbytes, bytes_written;
|
316
353
|
|
317
|
-
|
318
|
-
|
319
|
-
|
354
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
355
|
+
io = rb_convert_type(io, T_FILE, "IO", "to_io");
|
356
|
+
io_set_nonblock(io);
|
320
357
|
|
321
358
|
nbytes = buffer->limit - buffer->position;
|
322
359
|
if (nbytes == 0) {
|
323
360
|
rb_raise(cNIO_ByteBuffer_UnderflowError, "no data remaining in buffer");
|
324
361
|
}
|
325
362
|
|
326
|
-
bytes_written = write(
|
363
|
+
bytes_written = write(rb_io_descriptor(io), buffer->buffer + buffer->position, nbytes);
|
327
364
|
|
328
365
|
if (bytes_written < 0) {
|
329
366
|
if (errno == EAGAIN) {
|
@@ -335,13 +372,13 @@ static VALUE NIO_ByteBuffer_write_to(VALUE self, VALUE io)
|
|
335
372
|
|
336
373
|
buffer->position += bytes_written;
|
337
374
|
|
338
|
-
return
|
375
|
+
return SIZET2NUM(bytes_written);
|
339
376
|
}
|
340
377
|
|
341
378
|
static VALUE NIO_ByteBuffer_flip(VALUE self)
|
342
379
|
{
|
343
380
|
struct NIO_ByteBuffer *buffer;
|
344
|
-
|
381
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
345
382
|
|
346
383
|
buffer->limit = buffer->position;
|
347
384
|
buffer->position = 0;
|
@@ -353,7 +390,7 @@ static VALUE NIO_ByteBuffer_flip(VALUE self)
|
|
353
390
|
static VALUE NIO_ByteBuffer_rewind(VALUE self)
|
354
391
|
{
|
355
392
|
struct NIO_ByteBuffer *buffer;
|
356
|
-
|
393
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
357
394
|
|
358
395
|
buffer->position = 0;
|
359
396
|
buffer->mark = MARK_UNSET;
|
@@ -364,7 +401,7 @@ static VALUE NIO_ByteBuffer_rewind(VALUE self)
|
|
364
401
|
static VALUE NIO_ByteBuffer_mark(VALUE self)
|
365
402
|
{
|
366
403
|
struct NIO_ByteBuffer *buffer;
|
367
|
-
|
404
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
368
405
|
|
369
406
|
buffer->mark = buffer->position;
|
370
407
|
return self;
|
@@ -373,7 +410,7 @@ static VALUE NIO_ByteBuffer_mark(VALUE self)
|
|
373
410
|
static VALUE NIO_ByteBuffer_reset(VALUE self)
|
374
411
|
{
|
375
412
|
struct NIO_ByteBuffer *buffer;
|
376
|
-
|
413
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
377
414
|
|
378
415
|
if (buffer->mark < 0) {
|
379
416
|
rb_raise(cNIO_ByteBuffer_MarkUnsetError, "mark has not been set");
|
@@ -387,7 +424,7 @@ static VALUE NIO_ByteBuffer_reset(VALUE self)
|
|
387
424
|
static VALUE NIO_ByteBuffer_compact(VALUE self)
|
388
425
|
{
|
389
426
|
struct NIO_ByteBuffer *buffer;
|
390
|
-
|
427
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
391
428
|
|
392
429
|
memmove(buffer->buffer, buffer->buffer + buffer->position, buffer->limit - buffer->position);
|
393
430
|
buffer->position = buffer->limit - buffer->position;
|
@@ -400,7 +437,7 @@ static VALUE NIO_ByteBuffer_each(VALUE self)
|
|
400
437
|
{
|
401
438
|
int i;
|
402
439
|
struct NIO_ByteBuffer *buffer;
|
403
|
-
|
440
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
404
441
|
|
405
442
|
if (rb_block_given_p()) {
|
406
443
|
for (i = 0; i < buffer->limit; i++) {
|
@@ -416,7 +453,7 @@ static VALUE NIO_ByteBuffer_each(VALUE self)
|
|
416
453
|
static VALUE NIO_ByteBuffer_inspect(VALUE self)
|
417
454
|
{
|
418
455
|
struct NIO_ByteBuffer *buffer;
|
419
|
-
|
456
|
+
TypedData_Get_Struct(self, struct NIO_ByteBuffer, &NIO_ByteBuffer_type, buffer);
|
420
457
|
|
421
458
|
return rb_sprintf(
|
422
459
|
"#<%s:%p @position=%d @limit=%d @capacity=%d>",
|
data/ext/nio4r/extconf.rb
CHANGED
@@ -1,10 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
# Released under the MIT License.
|
4
|
+
# Copyright, 2011-2020, by Tony Arcieri.
|
5
|
+
# Copyright, 2014, by Hiroshi Shibata.
|
6
|
+
# Copyright, 2014, by Sergey Avseyev.
|
7
|
+
# Copyright, 2015, by Daniel Berger.
|
8
|
+
# Copyright, 2017, by Jun Aruga.
|
9
|
+
# Copyright, 2017, by Usaku Nakamura.
|
10
|
+
# Copyright, 2017, by Lars Kanis.
|
11
|
+
# Copyright, 2019-2023, by Samuel Williams.
|
12
|
+
# Copyright, 2020, by Gregory Longtin.
|
13
|
+
# Copyright, 2020, by Boaz Segev.
|
14
|
+
# Copyright, 2020, by Joao Fernandes.
|
15
|
+
# Copyright, 2021, by Jeffrey Martin.
|
16
|
+
|
3
17
|
require "rubygems"
|
4
18
|
|
5
19
|
# Write a dummy Makefile on Windows because we use the pure Ruby implementation there
|
6
20
|
if Gem.win_platform?
|
7
|
-
|
21
|
+
begin
|
22
|
+
require "devkit" if RUBY_PLATFORM.include?("mingw")
|
23
|
+
rescue LoadError => e
|
24
|
+
end
|
8
25
|
File.write("Makefile", "all install::\n")
|
9
26
|
File.write("nio4r_ext.so", "")
|
10
27
|
exit
|
@@ -13,6 +30,7 @@ end
|
|
13
30
|
require "mkmf"
|
14
31
|
|
15
32
|
have_header("unistd.h")
|
33
|
+
have_func("rb_io_descriptor")
|
16
34
|
|
17
35
|
$defs << "-DEV_USE_LINUXAIO" if have_header("linux/aio_abi.h")
|
18
36
|
$defs << "-DEV_USE_IOURING" if have_header("linux/io_uring.h")
|