uringmachine 0.31.0 → 0.32.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.
@@ -1,24 +1,24 @@
1
1
  #include "um.h"
2
2
 
3
- VALUE cConnection;
4
- VALUE eConnectionRESPError;
3
+ VALUE cIO;
4
+ VALUE eIORESPError;
5
5
 
6
6
  VALUE SYM_fd;
7
7
  VALUE SYM_socket;
8
8
  VALUE SYM_ssl;
9
9
 
10
- inline int connection_has_target_obj_p(struct um_connection *conn) {
10
+ inline int io_has_target_obj_p(struct um_io *conn) {
11
11
  switch (conn->mode) {
12
- case CONNECTION_SSL:
13
- case CONNECTION_STRING:
14
- case CONNECTION_IO_BUFFER:
12
+ case IO_SSL:
13
+ case IO_STRING:
14
+ case IO_IO_BUFFER:
15
15
  return true;
16
16
  default:
17
17
  return false;
18
18
  }
19
19
  }
20
20
 
21
- inline void connection_mark_segments(struct um_connection *conn) {
21
+ inline void io_mark_segments(struct um_io *conn) {
22
22
  struct um_segment *curr = conn->head;
23
23
  while (curr) {
24
24
  // rb_gc_mark_movable(curr->obj);
@@ -26,7 +26,7 @@ inline void connection_mark_segments(struct um_connection *conn) {
26
26
  }
27
27
  }
28
28
 
29
- inline void connection_compact_segments(struct um_connection *conn) {
29
+ inline void io_compact_segments(struct um_io *conn) {
30
30
  struct um_segment *curr = conn->head;
31
31
  while (curr) {
32
32
  // curr->obj = rb_gc_location(curr->obj);
@@ -34,63 +34,63 @@ inline void connection_compact_segments(struct um_connection *conn) {
34
34
  }
35
35
  }
36
36
 
37
- static void Connection_mark(void *ptr) {
38
- struct um_connection *conn = ptr;
37
+ static void IO_mark(void *ptr) {
38
+ struct um_io *conn = ptr;
39
39
  rb_gc_mark_movable(conn->self);
40
40
  rb_gc_mark_movable(conn->machine->self);
41
41
 
42
- if (connection_has_target_obj_p(conn)) {
42
+ if (io_has_target_obj_p(conn)) {
43
43
  rb_gc_mark_movable(conn->target);
44
- connection_mark_segments(conn);
44
+ io_mark_segments(conn);
45
45
  }
46
46
  }
47
47
 
48
- static void Connection_compact(void *ptr) {
49
- struct um_connection *conn = ptr;
48
+ static void IO_compact(void *ptr) {
49
+ struct um_io *conn = ptr;
50
50
  conn->self = rb_gc_location(conn->self);
51
51
 
52
- if (connection_has_target_obj_p(conn)) {
52
+ if (io_has_target_obj_p(conn)) {
53
53
  conn->target = rb_gc_location(conn->target);
54
- connection_compact_segments(conn);
54
+ io_compact_segments(conn);
55
55
  }
56
56
  }
57
57
 
58
- static void Connection_free(void *ptr) {
59
- struct um_connection *conn = ptr;
60
- connection_clear(conn);
58
+ static void IO_free(void *ptr) {
59
+ struct um_io *conn = ptr;
60
+ io_clear(conn);
61
61
  }
62
62
 
63
- static const rb_data_type_t Connection_type = {
64
- .wrap_struct_name = "UringMachine::Connection",
63
+ static const rb_data_type_t IO_type = {
64
+ .wrap_struct_name = "UringMachine::IO",
65
65
  .function = {
66
- .dmark = Connection_mark,
67
- .dfree = Connection_free,
66
+ .dmark = IO_mark,
67
+ .dfree = IO_free,
68
68
  .dsize = NULL,
69
- .dcompact = Connection_compact
69
+ .dcompact = IO_compact
70
70
  },
71
71
  .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
72
72
  };
73
73
 
74
- static VALUE Connection_allocate(VALUE klass) {
75
- struct um_connection *conn;
76
- VALUE self = TypedData_Make_Struct(klass, struct um_connection, &Connection_type, conn);
74
+ static VALUE IO_allocate(VALUE klass) {
75
+ struct um_io *conn;
76
+ VALUE self = TypedData_Make_Struct(klass, struct um_io, &IO_type, conn);
77
77
  return self;
78
78
  }
79
79
 
80
- static inline struct um_connection *um_get_connection(VALUE self) {
81
- struct um_connection *conn;
82
- TypedData_Get_Struct(self, struct um_connection, &Connection_type, conn);
80
+ static inline struct um_io *um_get_io(VALUE self) {
81
+ struct um_io *conn;
82
+ TypedData_Get_Struct(self, struct um_io, &IO_type, conn);
83
83
  return conn;
84
84
  }
85
85
 
86
- static inline void connection_set_target(struct um_connection *conn, VALUE target, enum um_connection_mode mode) {
86
+ static inline void io_set_target(struct um_io *conn, VALUE target, enum um_io_mode mode) {
87
87
  conn->mode = mode;
88
88
  switch (mode) {
89
- case CONNECTION_FD:
90
- case CONNECTION_SOCKET:
89
+ case IO_FD:
90
+ case IO_SOCKET:
91
91
  conn->fd = NUM2INT(target);
92
92
  return;
93
- case CONNECTION_SSL:
93
+ case IO_SSL:
94
94
  conn->target = target;
95
95
  um_ssl_set_bio(conn->machine, target);
96
96
  return;
@@ -99,20 +99,20 @@ static inline void connection_set_target(struct um_connection *conn, VALUE targe
99
99
  }
100
100
  }
101
101
 
102
- static inline void connection_setup(struct um_connection *conn, VALUE target, VALUE mode) {
102
+ static inline void io_setup(struct um_io *conn, VALUE target, VALUE mode) {
103
103
  conn->working_buffer = NULL;
104
104
  if (NIL_P(mode)) {
105
105
  if (TYPE(target) == T_DATA)
106
- connection_set_target(conn, target, CONNECTION_SSL);
106
+ io_set_target(conn, target, IO_SSL);
107
107
  else
108
- connection_set_target(conn, target, CONNECTION_FD);
108
+ io_set_target(conn, target, IO_FD);
109
109
  }
110
110
  else if (mode == SYM_fd)
111
- connection_set_target(conn, target, CONNECTION_FD);
111
+ io_set_target(conn, target, IO_FD);
112
112
  else if (mode == SYM_socket)
113
- connection_set_target(conn, target, CONNECTION_SOCKET);
113
+ io_set_target(conn, target, IO_SOCKET);
114
114
  else if (mode == SYM_ssl)
115
- connection_set_target(conn, target, CONNECTION_SSL);
115
+ io_set_target(conn, target, IO_SSL);
116
116
  else
117
117
  rb_raise(eUMError, "Invalid connection mode");
118
118
  }
@@ -131,18 +131,18 @@ static inline void connection_setup(struct um_connection *conn, VALUE target, VA
131
131
  * @param mode [Symbol] optional connection mode: :fd, :socket, :ssl
132
132
  * @return [void]
133
133
  */
134
- VALUE Connection_initialize(int argc, VALUE *argv, VALUE self) {
134
+ VALUE IO_initialize(int argc, VALUE *argv, VALUE self) {
135
135
  VALUE machine;
136
136
  VALUE target;
137
137
  VALUE mode;
138
138
  rb_scan_args(argc, argv, "21", &machine, &target, &mode);
139
139
 
140
- struct um_connection *conn = um_get_connection(self);
141
- memset(conn, 0, sizeof(struct um_connection));
140
+ struct um_io *conn = um_get_io(self);
141
+ memset(conn, 0, sizeof(struct um_io));
142
142
 
143
143
  RB_OBJ_WRITE(self, &conn->self, self);
144
144
  conn->machine = um_get_machine(machine);
145
- connection_setup(conn, target, mode);
145
+ io_setup(conn, target, mode);
146
146
 
147
147
  return self;
148
148
  }
@@ -154,12 +154,12 @@ VALUE Connection_initialize(int argc, VALUE *argv, VALUE self) {
154
154
  *
155
155
  * @return [Symbol] connection mode
156
156
  */
157
- VALUE Connection_mode(VALUE self) {
158
- struct um_connection *conn = um_get_connection(self);
157
+ VALUE IO_mode(VALUE self) {
158
+ struct um_io *conn = um_get_io(self);
159
159
  switch (conn->mode) {
160
- case CONNECTION_FD: return SYM_fd;
161
- case CONNECTION_SOCKET: return SYM_socket;
162
- case CONNECTION_SSL: return SYM_ssl;
160
+ case IO_FD: return SYM_fd;
161
+ case IO_SOCKET: return SYM_socket;
162
+ case IO_SSL: return SYM_ssl;
163
163
  default: return Qnil;
164
164
  }
165
165
  return Qnil;
@@ -175,9 +175,9 @@ VALUE Connection_mode(VALUE self) {
175
175
  * @param limit [integer] maximum line length (0 means no limit)
176
176
  * @return [String, nil] read data or nil
177
177
  */
178
- VALUE Connection_read_line(VALUE self, VALUE limit) {
179
- struct um_connection *conn = um_get_connection(self);
180
- return connection_read_line(conn, Qnil, NUM2ULONG(limit));
178
+ VALUE IO_read_line(VALUE self, VALUE limit) {
179
+ struct um_io *conn = um_get_io(self);
180
+ return io_read_line(conn, Qnil, NUM2ULONG(limit));
181
181
  }
182
182
 
183
183
  /* call-seq:
@@ -190,9 +190,9 @@ VALUE Connection_read_line(VALUE self, VALUE limit) {
190
190
  * @param len [integer] number of bytes to read
191
191
  * @return [String, nil] read data or nil
192
192
  */
193
- VALUE Connection_read(VALUE self, VALUE len) {
194
- struct um_connection *conn = um_get_connection(self);
195
- return connection_read(conn, Qnil, NUM2LONG(len), 0, false);
193
+ VALUE IO_read(VALUE self, VALUE len) {
194
+ struct um_io *conn = um_get_io(self);
195
+ return io_read(conn, Qnil, NUM2LONG(len), 0, false);
196
196
  }
197
197
 
198
198
  /* call-seq:
@@ -210,9 +210,9 @@ VALUE Connection_read(VALUE self, VALUE len) {
210
210
  * @param delim [String] delimiter (single byte) @param limit [integer] maximum
211
211
  * line length (0 means no limit) @return [String, nil] read data or nil
212
212
  */
213
- VALUE Connection_read_to_delim(VALUE self, VALUE delim, VALUE limit) {
214
- struct um_connection *conn = um_get_connection(self);
215
- return connection_read_to_delim(conn, Qnil, delim, NUM2LONG(limit));
213
+ VALUE IO_read_to_delim(VALUE self, VALUE delim, VALUE limit) {
214
+ struct um_io *conn = um_get_io(self);
215
+ return io_read_to_delim(conn, Qnil, delim, NUM2LONG(limit));
216
216
  }
217
217
 
218
218
  /* call-seq:
@@ -223,9 +223,9 @@ VALUE Connection_read_to_delim(VALUE self, VALUE delim, VALUE limit) {
223
223
  * @param len [integer] number of bytes to skip
224
224
  * @return [Integer] len
225
225
  */
226
- VALUE Connection_skip(VALUE self, VALUE len) {
227
- struct um_connection *conn = um_get_connection(self);
228
- connection_skip(conn, NUM2LONG(len), true);
226
+ VALUE IO_skip(VALUE self, VALUE len) {
227
+ struct um_io *conn = um_get_io(self);
228
+ io_skip(conn, NUM2LONG(len), true);
229
229
  return len;
230
230
  }
231
231
 
@@ -234,11 +234,11 @@ VALUE Connection_skip(VALUE self, VALUE len) {
234
234
  *
235
235
  * Reads from the target, passing each chunk to the given block.
236
236
  *
237
- * @return [UringMachine::Connection] conn
237
+ * @return [UringMachine::IO] conn
238
238
  */
239
- VALUE Connection_read_each(VALUE self) {
240
- struct um_connection *conn = um_get_connection(self);
241
- connection_read_each(conn);
239
+ VALUE IO_read_each(VALUE self) {
240
+ struct um_io *conn = um_get_io(self);
241
+ io_read_each(conn);
242
242
  return self;
243
243
  }
244
244
 
@@ -251,9 +251,9 @@ VALUE Connection_read_each(VALUE self) {
251
251
  * @param bufs [Array<String, IO::Buffer>] data to write
252
252
  * @return [Integer] total bytes written
253
253
  */
254
- VALUE Connection_write(int argc, VALUE *argv, VALUE self) {
255
- struct um_connection *conn = um_get_connection(self);
256
- return connection_writev(conn, argc, argv);
254
+ VALUE IO_write(int argc, VALUE *argv, VALUE self) {
255
+ struct um_io *conn = um_get_io(self);
256
+ return io_writev(conn, argc, argv);
257
257
  }
258
258
 
259
259
  /* call-seq:
@@ -263,8 +263,8 @@ VALUE Connection_write(int argc, VALUE *argv, VALUE self) {
263
263
  *
264
264
  * @return [any] decoded object
265
265
  */
266
- VALUE Connection_resp_read(VALUE self) {
267
- struct um_connection *conn = um_get_connection(self);
266
+ VALUE IO_resp_read(VALUE self) {
267
+ struct um_io *conn = um_get_io(self);
268
268
  VALUE out_buffer = rb_utf8_str_new_literal("");
269
269
  VALUE obj = resp_read(conn, out_buffer);
270
270
  RB_GC_GUARD(out_buffer);
@@ -280,8 +280,8 @@ VALUE Connection_resp_read(VALUE self) {
280
280
  * @param obj [any] object to write
281
281
  * @return [Integer] total bytes written
282
282
  */
283
- VALUE Connection_resp_write(VALUE self, VALUE obj) {
284
- struct um_connection *conn = um_get_connection(self);
283
+ VALUE IO_resp_write(VALUE self, VALUE obj) {
284
+ struct um_io *conn = um_get_io(self);
285
285
 
286
286
  VALUE str = rb_str_new(NULL, 0);
287
287
  struct um_write_buffer buf;
@@ -290,7 +290,7 @@ VALUE Connection_resp_write(VALUE self, VALUE obj) {
290
290
  resp_encode(&buf, obj);
291
291
  write_buffer_update_len(&buf);
292
292
 
293
- size_t len = connection_write_raw(conn, buf.ptr, buf.len);
293
+ size_t len = io_write_raw(conn, buf.ptr, buf.len);
294
294
  RB_GC_GUARD(str);
295
295
  return ULONG2NUM(len);
296
296
  }
@@ -304,7 +304,7 @@ VALUE Connection_resp_write(VALUE self, VALUE obj) {
304
304
  * @param obj [any] object to be encoded
305
305
  * @return [String] str
306
306
  */
307
- VALUE Connection_resp_encode(VALUE self, VALUE str, VALUE obj) {
307
+ VALUE IO_resp_encode(VALUE self, VALUE str, VALUE obj) {
308
308
  struct um_write_buffer buf;
309
309
  write_buffer_init(&buf, str);
310
310
  rb_str_modify(str);
@@ -320,8 +320,8 @@ VALUE Connection_resp_encode(VALUE self, VALUE str, VALUE obj) {
320
320
  *
321
321
  * @return [bool] EOF reached
322
322
  */
323
- VALUE Connection_eof_p(VALUE self) {
324
- struct um_connection *conn = um_get_connection(self);
323
+ VALUE IO_eof_p(VALUE self) {
324
+ struct um_io *conn = um_get_io(self);
325
325
  return conn->eof ? Qtrue : Qfalse;
326
326
  }
327
327
 
@@ -332,8 +332,8 @@ VALUE Connection_eof_p(VALUE self) {
332
332
  *
333
333
  * @return [Integer] total bytes consumed
334
334
  */
335
- VALUE Connection_consumed(VALUE self) {
336
- struct um_connection *conn = um_get_connection(self);
335
+ VALUE IO_consumed(VALUE self) {
336
+ struct um_io *conn = um_get_io(self);
337
337
  return LONG2NUM(conn->consumed_bytes);
338
338
  }
339
339
 
@@ -344,8 +344,8 @@ VALUE Connection_consumed(VALUE self) {
344
344
  *
345
345
  * @return [Integer] bytes available
346
346
  */
347
- VALUE Connection_pending(VALUE self) {
348
- struct um_connection *conn = um_get_connection(self);
347
+ VALUE IO_pending(VALUE self) {
348
+ struct um_io *conn = um_get_io(self);
349
349
  return LONG2NUM(conn->pending_bytes);
350
350
  }
351
351
 
@@ -356,37 +356,37 @@ VALUE Connection_pending(VALUE self) {
356
356
  *
357
357
  * @return [UM::Stream] self
358
358
  */
359
- VALUE Connection_clear(VALUE self) {
360
- struct um_connection *conn = um_get_connection(self);
361
- connection_clear(conn);
359
+ VALUE IO_clear(VALUE self) {
360
+ struct um_io *conn = um_get_io(self);
361
+ io_clear(conn);
362
362
  return self;
363
363
  }
364
364
 
365
- void Init_Stream(void) {
366
- cConnection = rb_define_class_under(cUM, "Connection", rb_cObject);
367
- rb_define_alloc_func(cConnection, Connection_allocate);
365
+ void Init_IO(void) {
366
+ cIO = rb_define_class_under(cUM, "IO", rb_cObject);
367
+ rb_define_alloc_func(cIO, IO_allocate);
368
368
 
369
- rb_define_method(cConnection, "initialize", Connection_initialize, -1);
370
- rb_define_method(cConnection, "mode", Connection_mode, 0);
369
+ rb_define_method(cIO, "initialize", IO_initialize, -1);
370
+ rb_define_method(cIO, "mode", IO_mode, 0);
371
371
 
372
- rb_define_method(cConnection, "read_line", Connection_read_line, 1);
373
- rb_define_method(cConnection, "read", Connection_read, 1);
374
- rb_define_method(cConnection, "read_to_delim", Connection_read_to_delim, 2);
375
- rb_define_method(cConnection, "skip", Connection_skip, 1);
376
- rb_define_method(cConnection, "read_each", Connection_read_each, 0);
372
+ rb_define_method(cIO, "read_line", IO_read_line, 1);
373
+ rb_define_method(cIO, "read", IO_read, 1);
374
+ rb_define_method(cIO, "read_to_delim", IO_read_to_delim, 2);
375
+ rb_define_method(cIO, "skip", IO_skip, 1);
376
+ rb_define_method(cIO, "read_each", IO_read_each, 0);
377
377
 
378
- rb_define_method(cConnection, "write", Connection_write, -1);
378
+ rb_define_method(cIO, "write", IO_write, -1);
379
379
 
380
- rb_define_method(cConnection, "resp_read", Connection_resp_read, 0);
381
- rb_define_method(cConnection, "resp_write", Connection_resp_write, 1);
382
- rb_define_singleton_method(cConnection, "resp_encode", Connection_resp_encode, 2);
380
+ rb_define_method(cIO, "resp_read", IO_resp_read, 0);
381
+ rb_define_method(cIO, "resp_write", IO_resp_write, 1);
382
+ rb_define_singleton_method(cIO, "resp_encode", IO_resp_encode, 2);
383
383
 
384
- rb_define_method(cConnection, "eof?", Connection_eof_p, 0);
385
- rb_define_method(cConnection, "consumed", Connection_consumed, 0);
386
- rb_define_method(cConnection, "pending", Connection_pending, 0);
387
- rb_define_method(cConnection, "clear", Connection_clear, 0);
384
+ rb_define_method(cIO, "eof?", IO_eof_p, 0);
385
+ rb_define_method(cIO, "consumed", IO_consumed, 0);
386
+ rb_define_method(cIO, "pending", IO_pending, 0);
387
+ rb_define_method(cIO, "clear", IO_clear, 0);
388
388
 
389
- eConnectionRESPError = rb_define_class_under(cConnection, "RESPError", rb_eStandardError);
389
+ eIORESPError = rb_define_class_under(cIO, "RESPError", rb_eStandardError);
390
390
 
391
391
  SYM_fd = ID2SYM(rb_intern("fd"));
392
392
  SYM_socket = ID2SYM(rb_intern("socket"));
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class UringMachine
4
- VERSION = '0.31.0'
4
+ VERSION = '0.32.0'
5
5
  end
data/lib/uringmachine.rb CHANGED
@@ -195,24 +195,24 @@ class UringMachine
195
195
  end
196
196
 
197
197
  # call-seq:
198
- # machine.connection(fd, mode = nil) -> conn
199
- # machine.connection(fd, mode = nil) { |conn| }
198
+ # machine.io(fd, mode = nil) -> conn
199
+ # machine.io(fd, mode = nil) { |conn| }
200
200
  #
201
- # Creates a connection for reading from the given target fd or other object.
202
- # The mode indicates the type of target and how it is read from:
201
+ # Creates an UM::IO for the given target (fd or SSLSocket). The mode indicates
202
+ # the type of target and how it is read from:
203
203
  #
204
204
  # - :fd - read from the given fd using the buffer pool (default mode)
205
205
  # - :socket - receive from the given socket fd using the buffer pool
206
- # - :ssl - read from the given SSL connection
206
+ # - :ssl - read from the given SSL socket
207
207
  #
208
- # If a block is given, the block will be called with the connection object and
209
- # the method will return the block's return value.
208
+ # If a block is given, the block will be called with the IO instance as
209
+ # argument and the method will return the block's return value.
210
210
  #
211
- # @param target [Integer, OpenSSL::SSL::SSLSocket] fd or ssl connection
212
- # @param mode [Symbol, nil] connection mode
213
- # @return [UringMachine::Stream] connection object
214
- def connection(target, mode = nil)
215
- conn = UM::Connection.new(self, target, mode)
211
+ # @param target [Integer, OpenSSL::SSL::SSLSocket] fd or ssl socket
212
+ # @param mode [Symbol, nil] IO mode
213
+ # @return [UringMachine::IO] IO object
214
+ def io(target, mode = nil)
215
+ conn = UM::IO.new(self, target, mode)
216
216
  return conn if !block_given?
217
217
 
218
218
  res = yield(conn)
@@ -5,13 +5,13 @@ require 'securerandom'
5
5
  require 'openssl'
6
6
  require 'localhost/authority'
7
7
 
8
- class ConnectionBaseTest < UMBaseTest
8
+ class IOBaseTest < UMBaseTest
9
9
  attr_reader :conn
10
10
 
11
11
  def setup
12
12
  super
13
13
  @rfd, @wfd = UM.pipe
14
- @conn = UM::Connection.new(@machine, @rfd)
14
+ @conn = UM::IO.new(@machine, @rfd)
15
15
  end
16
16
 
17
17
  def teardown
@@ -22,7 +22,7 @@ class ConnectionBaseTest < UMBaseTest
22
22
  end
23
23
  end
24
24
 
25
- class ConnectionTest < ConnectionBaseTest
25
+ class IOTest < IOBaseTest
26
26
  def buffer_metrics
27
27
  machine.metrics.fetch_values(
28
28
  :buffers_allocated,
@@ -55,7 +55,7 @@ class ConnectionTest < ConnectionBaseTest
55
55
 
56
56
  def test_connection_clear
57
57
  rfd, wfd = UM.pipe
58
- conn = UM::Connection.new(machine, rfd)
58
+ conn = UM::IO.new(machine, rfd)
59
59
 
60
60
  assert_equal [0, 0, 0, 0, 0], buffer_metrics
61
61
  machine.write(wfd, "foobar")
@@ -79,7 +79,7 @@ class ConnectionTest < ConnectionBaseTest
79
79
 
80
80
  def test_connection_big_read
81
81
  s1, s2 = UM.socketpair(UM::AF_UNIX, UM::SOCK_STREAM, 0)
82
- conn = UM::Connection.new(machine, s2)
82
+ conn = UM::IO.new(machine, s2)
83
83
 
84
84
  msg = '1234567' * 20000
85
85
 
@@ -98,7 +98,7 @@ class ConnectionTest < ConnectionBaseTest
98
98
 
99
99
  def test_connection_buffer_reuse
100
100
  s1, s2 = UM.socketpair(UM::AF_UNIX, UM::SOCK_STREAM, 0)
101
- conn = UM::Connection.new(machine, s2)
101
+ conn = UM::IO.new(machine, s2)
102
102
 
103
103
  msg = '1234567' * 20000
104
104
 
@@ -307,13 +307,13 @@ class ConnectionTest < ConnectionBaseTest
307
307
  end
308
308
  end
309
309
 
310
- class ConnectionWriteTest < UMBaseTest
310
+ class IOWriteTest < UMBaseTest
311
311
  attr_reader :conn
312
312
 
313
313
  def setup
314
314
  super
315
315
  @s1, @s2 = UM.socketpair(UM::AF_UNIX, UM::SOCK_STREAM, 0)
316
- @conn = UM::Connection.new(@machine, @s1)
316
+ @conn = UM::IO.new(@machine, @s1)
317
317
  end
318
318
 
319
319
  def teardown
@@ -340,7 +340,7 @@ class ConnectionWriteTest < UMBaseTest
340
340
  end
341
341
 
342
342
  def test_connection_write_socket_mode
343
- conn = machine.connection(@s2, :socket)
343
+ conn = machine.io(@s2, :socket)
344
344
 
345
345
  assert_equal 6, conn.write('foo', 'bar')
346
346
 
@@ -363,8 +363,8 @@ class ConnectionWriteTest < UMBaseTest
363
363
  ssl2.connect
364
364
  refute_equal 0, @machine.metrics[:total_ops]
365
365
 
366
- conn1 = machine.connection(ssl1)
367
- conn2 = machine.connection(ssl2)
366
+ conn1 = machine.io(ssl1)
367
+ conn2 = machine.io(ssl2)
368
368
 
369
369
  assert_equal 10, conn1.write('foobar', "\n", 'baz')
370
370
 
@@ -379,7 +379,7 @@ class ConnectionWriteTest < UMBaseTest
379
379
  end
380
380
  end
381
381
 
382
- class ConnectionRespTest < ConnectionBaseTest
382
+ class IORespTest < IOBaseTest
383
383
  def test_connection_resp_read
384
384
  machine.write(@wfd, "+foo bar\r\n")
385
385
  assert_equal "foo bar", conn.resp_read
@@ -389,12 +389,12 @@ class ConnectionRespTest < ConnectionBaseTest
389
389
 
390
390
  machine.write(@wfd, "-foobar\r\n")
391
391
  o = conn.resp_read
392
- assert_kind_of UM::Connection::RESPError, o
392
+ assert_kind_of UM::IO::RESPError, o
393
393
  assert_equal "foobar", o.message
394
394
 
395
395
  machine.write(@wfd, "!3\r\nbaz\r\n")
396
396
  o = conn.resp_read
397
- assert_kind_of UM::Connection::RESPError, o
397
+ assert_kind_of UM::IO::RESPError, o
398
398
  assert_equal "baz", o.message
399
399
 
400
400
  machine.write(@wfd, ":123\r\n")
@@ -459,7 +459,7 @@ class ConnectionRespTest < ConnectionBaseTest
459
459
  end
460
460
 
461
461
  def test_connection_resp_write
462
- writer = machine.connection(@wfd)
462
+ writer = machine.io(@wfd)
463
463
 
464
464
  writer.resp_write(nil);
465
465
  assert_equal "_\r\n", conn.read(-100)
@@ -490,7 +490,7 @@ class ConnectionRespTest < ConnectionBaseTest
490
490
  end
491
491
 
492
492
  def test_connection_resp_encode
493
- s = UM::Connection
493
+ s = UM::IO
494
494
  assert_equal "_\r\n", s.resp_encode(+'', nil)
495
495
  assert_equal "#t\r\n", s.resp_encode(+'', true)
496
496
  assert_equal "#f\r\n", s.resp_encode(+'', false)
@@ -507,7 +507,7 @@ class ConnectionRespTest < ConnectionBaseTest
507
507
  end
508
508
  end
509
509
 
510
- class ConnectionStressTest < UMBaseTest
510
+ class IOStressTest < UMBaseTest
511
511
  def setup
512
512
  super
513
513
 
@@ -525,7 +525,7 @@ class ConnectionStressTest < UMBaseTest
525
525
 
526
526
  def start_connection_fiber(fd)
527
527
  machine.spin do
528
- conn = UM::Connection.new(machine, fd)
528
+ conn = UM::IO.new(machine, fd)
529
529
  while (msg = conn.read_line(0))
530
530
  @received << msg
531
531
  end
@@ -620,10 +620,10 @@ class ConnectionStressTest < UMBaseTest
620
620
  end
621
621
  end
622
622
 
623
- class ConnectionDevRandomTest < UMBaseTest
623
+ class IODevRandomTest < UMBaseTest
624
624
  def test_connection_dev_random_read_line
625
625
  fd = machine.open('/dev/random', UM::O_RDONLY)
626
- conn = UM::Connection.new(machine, fd)
626
+ conn = UM::IO.new(machine, fd)
627
627
 
628
628
  n = 100000
629
629
  lines = []
@@ -639,7 +639,7 @@ class ConnectionDevRandomTest < UMBaseTest
639
639
 
640
640
  def read_line_do(n, acc)
641
641
  fd = @machine.open('/dev/random', UM::O_RDONLY)
642
- conn = UM::Connection.new(@machine, fd)
642
+ conn = UM::IO.new(@machine, fd)
643
643
  n.times { acc << conn.read_line(0) }
644
644
  end
645
645
 
@@ -656,7 +656,7 @@ class ConnectionDevRandomTest < UMBaseTest
656
656
 
657
657
  def test_connection_dev_random_read
658
658
  fd = machine.open('/dev/random', UM::O_RDONLY)
659
- conn = UM::Connection.new(machine, fd)
659
+ conn = UM::IO.new(machine, fd)
660
660
 
661
661
  n = 256
662
662
  size = 65536 * 8
@@ -676,10 +676,10 @@ class ConnectionDevRandomTest < UMBaseTest
676
676
  end
677
677
  end
678
678
 
679
- class ConnectionModeTest < UMBaseTest
679
+ class IOModeTest < UMBaseTest
680
680
  def test_connection_default_mode
681
681
  r, w = UM.pipe
682
- conn = UM::Connection.new(machine, r)
682
+ conn = UM::IO.new(machine, r)
683
683
  assert_equal :fd, conn.mode
684
684
  ensure
685
685
  machine.close(r) rescue nil
@@ -692,7 +692,7 @@ class ConnectionModeTest < UMBaseTest
692
692
  sock1, sock2 = UNIXSocket.pair
693
693
 
694
694
  s1 = OpenSSL::SSL::SSLSocket.new(sock1, @server_ctx)
695
- conn = UM::Connection.new(machine, s1)
695
+ conn = UM::IO.new(machine, s1)
696
696
  assert_equal :ssl, conn.mode
697
697
  ensure
698
698
  sock1&.close rescue nil
@@ -704,7 +704,7 @@ class ConnectionModeTest < UMBaseTest
704
704
  machine.write(w, 'foobar')
705
705
  machine.close(w)
706
706
 
707
- conn = UM::Connection.new(machine, r, :socket)
707
+ conn = UM::IO.new(machine, r, :socket)
708
708
  assert_equal :socket, conn.mode
709
709
  # assert :socket, conn.mode
710
710
  assert_raises(Errno::ENOTSOCK) { conn.read(0) }
@@ -718,7 +718,7 @@ class ConnectionModeTest < UMBaseTest
718
718
  machine.write(w, 'foobar')
719
719
  machine.close(w)
720
720
 
721
- conn = UM::Connection.new(machine, r, :socket)
721
+ conn = UM::IO.new(machine, r, :socket)
722
722
  assert_equal :socket, conn.mode
723
723
  buf = conn.read(0)
724
724
  assert_equal 'foobar', buf
@@ -751,7 +751,7 @@ class ConnectionModeTest < UMBaseTest
751
751
  assert_equal 10, @machine.ssl_write(s1, buf, buf.bytesize)
752
752
  buf = +''
753
753
 
754
- conn = UM::Connection.new(machine, s2, :ssl)
754
+ conn = UM::IO.new(machine, s2, :ssl)
755
755
  assert_equal "foobar", conn.read_line(0)
756
756
 
757
757
  buf = "buh"
@@ -774,7 +774,7 @@ class ConnectionModeTest < UMBaseTest
774
774
  end
775
775
  end
776
776
 
777
- class ConnectionByteCountsTest < ConnectionBaseTest
777
+ class IOByteCountsTest < IOBaseTest
778
778
  def test_connection_byte_counts
779
779
  machine.write(@wfd, "foobar")
780
780