Sha256: f2caf0131ca11bee319fd4ef879c5c89f91bd8fdfca1cfaf4fcfc2857d17da3b
Contents?: true
Size: 1.08 KB
Versions: 27
Compression:
Stored size: 1.08 KB
Contents
require 'timeout' module RunLoop module Fifo BUFFER_SIZE = 4096 class NoReaderConfiguredError < RuntimeError end class WriteTimedOut < RuntimeError end def self.write(pipe, msg, options={}) msg = "#{msg}\n" timeout = options[:timeout] || 10 begin_at = Time.now begin open(pipe, File::WRONLY | File::NONBLOCK) do |pipe_io| bytes_written = 0 bytes_to_write = msg.length until bytes_written >= bytes_to_write do begin wrote = pipe_io.write_nonblock msg bytes_written += wrote msg = msg[wrote..-1] rescue IO::WaitWritable, Errno::EINTR timeout_left = timeout - (Time.now - begin_at) raise WriteTimedOut if timeout_left <= 0 IO.select nil, [pipe_io], nil, timeout_left end end end rescue Errno::ENXIO sleep(0.5) timeout_left = timeout - (Time.now - begin_at) raise NoReaderConfiguredError if timeout_left <= 0 retry end end end end
Version data entries
27 entries across 27 versions & 1 rubygems