class Tanker::IoToTankerStreamWrapper
Attributes
error[R]
mutex[R]
read_method[R]
Public Class Methods
new(read_in)
click to toggle source
# File lib/tanker/core/stream.rb, line 126 def initialize(read_in) @read_in = read_in # This is the object we will pass to ffi, it must be kept alive @read_method = method(:read) @closed = false @mutex = Mutex.new end
Public Instance Methods
close()
click to toggle source
# File lib/tanker/core/stream.rb, line 134 def close raise 'mutex should be locked by the caller' unless @mutex.owned? @closed = true @read_in.close end
read(buffer, buffer_size, operation, _)
click to toggle source
# File lib/tanker/core/stream.rb, line 141 def read(buffer, buffer_size, operation, _) # We must not block Tanker's thread, for performance but also to avoid # deadlocks, so let's run this function somewhere else Thread.new do do_read(buffer, buffer_size, operation) end end
Private Instance Methods
do_read(buffer, buffer_size, operation)
click to toggle source
# File lib/tanker/core/stream.rb, line 151 def do_read(buffer, buffer_size, operation) @mutex.synchronize do return if @closed if @read_in.eof? CTanker.tanker_stream_read_operation_finish(operation, 0) return end end rbbuf = @read_in.readpartial(buffer_size) @mutex.synchronize do return if @closed buffer.put_bytes(0, rbbuf) CTanker.tanker_stream_read_operation_finish(operation, rbbuf.size) end rescue StandardError => e @mutex.synchronize do return if @closed @error = e CTanker.tanker_stream_read_operation_finish(operation, -1) end end