@@ -37,7 +37,7 @@ implementation that allows integration with the entire Ruby ecosystem.
3737- Excellent performance characteristics for concurrent I/O-bound applications.
3838- ` Fiber::Scheduler ` implementation to automatically integrate with the Ruby
3939 ecosystem in a transparent fashion.
40- - [ Connection ] ( #connections ) class with automatic buffer management for reading.
40+ - [ IO ] ( #io-api ) class with automatic buffer management for reading.
4141- Optimized I/O for encrypted SSL connections.
4242
4343## Design
@@ -286,70 +286,69 @@ fiber = Fiber.schedule do
286286end
287287```
288288
289- ## Connections
289+ ## IO API
290290
291- ` UringMachine::Connection ` is a class designed for efficiently read from and
292- write to a socket or other file descriptor. Connections are ideal for
293- implementing the read side of protocols, and provide an API that is useful for
294- both line-based protocols and binary (frame-based) protocols.
291+ ` UringMachine::IO ` is a class designed for efficiently read from and write to a
292+ socket or other file descriptor. The IO class is ideal for implementing
293+ line-based and binary (frame-based) protocols.
295294
296- A connection is associated with a UringMachine instance and a target file
297- descriptor (or SSL socket, see also [ connection modes] ( #connection -modes )
298- below). Behind the scenes, connections take advantage of io_uring's registered
299- buffers feature, and more recently, the introduction of [ incremental buffer
295+ An IO is associated with a UringMachine instance and a target file descriptor
296+ (or SSL socket, see also [ IO modes] ( #io -modes ) below). Behind the scenes, the IO
297+ class takes advantage of io_uring's provided buffers feature, and more recently,
298+ the introduction of [ incremental buffer
300299consumption] ( https://github.com/axboe/liburing/wiki/What's-new-with-io_uring-in-6.11-and-6.12#incremental-provided-buffer-consumption ) .
301300
302- When connections are used, UringMachine automatically manages the buffers it
301+ When IO instances are used, UringMachine automatically manages the buffers it
303302provides to the kernel, maximizing buffer reuse and minimizing allocations.
304303UringMachine also responds to stress conditions (increased incoming traffic) by
305304automatically provisioning additional buffers.
306305
307- To create a connection for a given fd, use ` UM#connection ` :
306+ To create an IO for a given fd, use ` UM#io ` :
308307
309308``` ruby
310- conn = machine.connection (fd)
309+ io = machine.io (fd)
311310
312- # you can also provide a block that will be passed the connection instance:
313- machine.connection (fd) { |c | do_something_with(c ) }
311+ # you can provide a block that will be passed the IO instance:
312+ machine.io (fd) { |io | do_something_with(io ) }
314313
315- # you can also instantiate a connection directly:
316- conn = UM ::Connection .new (machine, fd)
314+ # you can also instantiate an IO directly:
315+ io = UM ::IO .new (machine, fd)
317316```
318317
319- The following API is used to interact with the connection :
318+ The following API is used to interact with an IO :
320319
321320``` ruby
322321# Read until a newline character is encountered:
323- line = conn .read_line(0 )
322+ line = io .read_line(0 )
324323
325324# Read line with a maximum length of 13 bytes:
326- line = conn .read_line(13 )
325+ line = io .read_line(13 )
327326
328327# Read all data:
329- buf = conn .read(0 )
328+ buf = io .read(0 )
330329
331330# Read exactly 13 bytes:
332- buf = conn .read(13 )
331+ buf = io .read(13 )
333332
334333# Read up to 13 bytes:
335- buf = conn .read(- 13 )
334+ buf = io .read(- 13 )
336335
337336# Read continuously until EOF
338- conn .read_each { |data | ... }
337+ io .read_each { |data | ... }
339338
340339# Skip 3 bytes:
341- conn .skip(3 )
340+ io .skip(3 )
342341
343342# Write
344- conn .write(' foo' , ' bar' , ' baz' )
343+ io .write(' foo' , ' bar' , ' baz' )
345344```
346345
347346Here's an example of a how a basic HTTP request parser might be implemented
348- using a connection :
347+ using a ` UM::IO ` :
349348
350349``` ruby
351- def parse_http_request_headers (conn )
352- request_line = conn .read_line(0 )
350+ def parse_http_request_headers (io )
351+ request_line = io .read_line(0 )
353352 m = request_line.match(REQUEST_LINE_RE )
354353 return nil if ! m
355354
@@ -360,7 +359,7 @@ def parse_http_request_headers(conn)
360359 }
361360
362361 while true
363- line = conn .read_line(0 )
362+ line = io .read_line(0 )
364363 break if ! line || line.empty?
365364
366365 m = line.match(HEADER_RE )
@@ -370,26 +369,26 @@ def parse_http_request_headers(conn)
370369end
371370```
372371
373- ### Connection modes
372+ ### IO modes
374373
375- Connection modes allow connections to be transport agnostic. Currently
376- connections support three modes :
374+ IO modes allow IOs to be transport agnostic. The following modes are currently
375+ supported :
377376
378377- ` :fd ` - use the buffer pool, read data using multishot read
379378 (this is the default mode).
380379- ` :socket ` - use the buffer pool, read data using multishot recv.
381380- ` :ssl ` - read from an ` SSLSocket ` object.
382381
383- The mode is specified as an additional argument to ` Connection .new` :
382+ The mode is specified as an additional argument to ` IO .new` :
384383
385384``` ruby
386385# using recv/send:
387- conn = machine.connection (fd, :socket )
386+ io = machine.io (fd, :socket )
388387
389388# SSL I/O:
390- conn = machine.connection (ssl, :ssl )
389+ io = machine.io (ssl, :ssl )
391390# or simply:
392- conn = machine.connection (ssl)
391+ io = machine.io (ssl)
393392```
394393
395394## Performance
0 commit comments