Class: Async::HTTP::Body::Pipe
- Inherits:
-
Object
- Object
- Async::HTTP::Body::Pipe
- Defined in:
- lib/async/http/body/pipe.rb
Overview
A bidirectional pipe that connects an input body to an output body using a Unix socket pair.
Instance Method Summary collapse
-
#close ⇒ Object
Close the pipe and stop the reader and writer tasks.
-
#initialize(input, output = Writable.new, task: Task.current) ⇒ Pipe
constructor
If the input stream is closed first, it’s likely the output stream will also be closed.
- #to_io ⇒ Object
Constructor Details
#initialize(input, output = Writable.new, task: Task.current) ⇒ Pipe
If the input stream is closed first, it’s likely the output stream will also be closed.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/async/http/body/pipe.rb', line 15 def initialize(input, output = Writable.new, task: Task.current) @input = input @output = output head, tail = ::Socket.pair(Socket::AF_UNIX, Socket::SOCK_STREAM) @head = ::IO::Stream(head) @tail = tail @reader = nil @writer = nil task.async(transient: true, &self.method(:reader)) task.async(transient: true, &self.method(:writer)) end |
Instance Method Details
#close ⇒ Object
Close the pipe and stop the reader and writer tasks.
37 38 39 40 41 42 |
# File 'lib/async/http/body/pipe.rb', line 37 def close @reader&.stop @writer&.stop @tail.close end |
#to_io ⇒ Object
32 33 34 |
# File 'lib/async/http/body/pipe.rb', line 32 def to_io @tail end |