about summary refs log tree commit homepage
path: root/lib/yahns/http_client.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/yahns/http_client.rb')
-rw-r--r--lib/yahns/http_client.rb19
1 files changed, 15 insertions, 4 deletions
diff --git a/lib/yahns/http_client.rb b/lib/yahns/http_client.rb
index fd97624..d55a0db 100644
--- a/lib/yahns/http_client.rb
+++ b/lib/yahns/http_client.rb
@@ -322,12 +322,23 @@ class Yahns::HttpClient < Kgio::Socket # :nodoc:
     true
   end
 
-  def trysendio(io, offset, count)
-    return 0 if count == 0
+  def do_pread(io, count, offset)
     count = 0x4000 if count > 0x4000
     buf = Thread.current[:yahns_sfbuf] ||= ''.dup
-    io.pos = offset
-    str = io.read(count, buf) or return # nil for EOF
+    if io.respond_to?(:pread)
+      io.pread(count, offset, buf)
+    else
+      io.pos = offset
+      io.read(count, buf)
+    end
+  rescue EOFError
+    warn "BUG: do_pread overreach:\n #{caller.join("\n ")}\n"
+    nil
+  end
+
+  def trysendio(io, offset, count)
+    return 0 if count == 0
+    str = do_pread(io, count, offset) or return # nil for EOF
     n = 0
     case rv = kgio_trywrite(str)
     when String # partial write, keep trying