about summary refs log tree commit homepage
path: root/bin/dtas-readahead
diff options
context:
space:
mode:
Diffstat (limited to 'bin/dtas-readahead')
-rwxr-xr-xbin/dtas-readahead40
1 files changed, 13 insertions, 27 deletions
diff --git a/bin/dtas-readahead b/bin/dtas-readahead
index 93ab8c9..f2ab514 100755
--- a/bin/dtas-readahead
+++ b/bin/dtas-readahead
@@ -1,5 +1,5 @@
 #!/usr/bin/env ruby
-# Copyright (C) 2015-2019 all contributors <dtas-all@nongnu.org>
+# Copyright (C) all contributors <dtas-all@nongnu.org>
 # License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
 # frozen_string_literal: true
 #
@@ -12,13 +12,11 @@ end
 @ffprobe = 'ffprobe'
 @avprobe = 'avprobe'
 
-require 'yaml'
 require 'io/wait'
 require 'dtas/unix_client'
 require 'dtas/process'
 
 include DTAS::Process
-include DTAS::SpawnFix
 trap(:CHLD) { DTAS::Process.reaper {} }
 trap(:INT) { exit(0) }
 trap(:TERM) { exit(0) }
@@ -30,18 +28,6 @@ null = DTAS.null
 @redir = { err: null, out: null, in: null }.freeze
 require 'pp'
 
-if RUBY_VERSION.to_r >= '2.3'.to_r
-  # Old Rubies did FIONREAD, which breaks on SOCK_SEQPACKET
-  def wait_read(w, timeout)
-    w.to_io.wait_readable(timeout)
-  end
-else
-  def wait_read(w, timeout)
-    r = IO.select([w], nil, nil, timeout)
-    r ? r[0] : nil
-  end
-end
-
 def seek_to_cur_pos(cur_pid, fp)
   cur_fd = []
   fpst = fp.stat
@@ -57,7 +43,7 @@ def seek_to_cur_pos(cur_pid, fp)
       end
     end
   rescue Errno::ENOENT => e # race, process is dead
-    return false
+    return nil
   rescue => e
     warn "error reading FDs from for PID:#{cur_pid}: #{e.message}"
   end
@@ -71,7 +57,7 @@ def seek_to_cur_pos(cur_pid, fp)
   end
   pos
 rescue Errno::ENOENT => e # race, process is dead
-  return false
+  return nil
 end
 
 def children_of(ppid)
@@ -122,7 +108,7 @@ def do_ra(fp, pos, w)
     len -= n
 
     # stop reading immediately if there's an event
-    if wait_read(w, 0)
+    if w.to_io.wait_readable(0)
       adj = @todo_ra
       pos += size
       break
@@ -141,8 +127,8 @@ def do_open(path)
       when "---\n"
         buf << fp.read(fp.size - 4)
         Dir.chdir(File.dirname(path)) do
-          yml = YAML.load(buf)
-          x = yml['infile'] and return File.open(File.expand_path(x).freeze)
+          yml = DTAS.yaml_load(buf)
+          x = yml['infile'] and return File.open(-File.expand_path(x))
         end
       end
     end
@@ -156,12 +142,12 @@ begin
   @todo_ra = @max_ra
   t0 = DTAS.now
   fp = nil
-  cur = YAML.load(c.req('current'))
+  cur = DTAS.yaml_load(c.req('current'))
   while @todo_ra > 0 && fp.nil?
     if current = cur['current']
       track = current['infile']
       break unless track.kind_of?(String)
-      track.freeze
+      track = -track
       fp = work[track] ||= do_open(track)
       cur_pid = current['pid']
       if fp
@@ -178,7 +164,7 @@ begin
     end
 
     # queue has priority, work on it, first
-    queue = YAML.load(c.req('queue cat'))
+    queue = DTAS.yaml_load(c.req('queue cat'))
     while @todo_ra > 0 && track = queue.shift
       next unless track.kind_of?(String)
       fp = nil
@@ -198,7 +184,7 @@ begin
     repeat = c.req('tl repeat').split[-1]
     while @todo_ra > 0 && idx && (cid = ids[idx])
       fp = nil
-      track = c.req("tl get #{cid}").sub!(/\A1 \d+=/, '').freeze
+      track = -(c.req("tl get #{cid}").sub!(/\A1 \d+=/, ''))
       begin
         fp = work[track] ||= do_open(track)
       rescue SystemCallError
@@ -210,7 +196,7 @@ begin
       end
     end
     idx or break
-    cur = YAML.load(c.req('current'))
+    cur = DTAS.yaml_load(c.req('current'))
     current = cur['current'] or break
   end
   if current
@@ -220,10 +206,10 @@ begin
     timeout = 0 if timeout < 0
   else
     work.each_value(&:close).clear
-    fp.close if fp && !fp.closed?
+    fp.close if fp
     fp = timeout = nil
   end
-  r = wait_read(w, timeout)
+  r = w.to_io.wait_readable(timeout)
   p w.res_wait if r
 rescue EOFError
   abort "dtas-player exited"