class Tanker::TankerStreamToIoWrapper
Constants
- READ_SIZE
Attributes
error[R]
Public Class Methods
new(tanker_stream, substream)
click to toggle source
# File lib/tanker/core/stream.rb, line 182 def initialize(tanker_stream, substream) @tanker_stream = tanker_stream @substream = substream end
Public Instance Methods
close()
click to toggle source
# File lib/tanker/core/stream.rb, line 199 def close tanker_stream = nil @substream.mutex.synchronize do @substream.close tanker_stream = @tanker_stream @tanker_stream = nil end CTanker.tanker_stream_close(tanker_stream).get end
init_io()
click to toggle source
# File lib/tanker/core/stream.rb, line 187 def init_io read, @write = IO.pipe @write.binmode read.binmode # The user will only read on the pipe, so we need something that reads # from Tanker and writes to the pipe, it's this thread. Thread.new { read_thread } read end
Private Instance Methods
read_thread()
click to toggle source
# File lib/tanker/core/stream.rb, line 213 def read_thread ffibuf = FFI::MemoryPointer.new(:char, READ_SIZE) begin loop do nb_read_fut = nil @substream.mutex.synchronize do unless @tanker_stream raise TankerError, { error_code: Errors::OPERATION_CANCELED, error_message: 'stream operation canceled' } end nb_read_fut = CTanker.tanker_stream_read(@tanker_stream, ffibuf, READ_SIZE) end nb_read = nb_read_fut.get.address break if nb_read.zero? # EOF @write.write(ffibuf.read_string(nb_read)) end rescue StandardError => e @error = @substream.error || e ensure @write.close end end