diff options
author | Eric Wong <normalperson@yhbt.net> | 2013-10-06 11:02:38 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2013-10-06 11:19:02 +0000 |
commit | 019543aa3a1074582a460b944ad5ebcddecd4394 (patch) | |
tree | bb24e015b373c5b9daca04e3497230058c8bcdf7 /lib/dtas/buffer/read_write.rb | |
parent | b991345ff960229347b32eb1bfe9d7732441c19e (diff) | |
download | dtas-019543aa3a1074582a460b944ad5ebcddecd4394.tar.gz |
We do not need this for single sink situations (the common case) at all. We also do not need to check IO#nread for splice, either; we can just do non-blocking I/O. The only common path where we might still need it is the non-splice case with multiple sinks.
Diffstat (limited to 'lib/dtas/buffer/read_write.rb')
-rw-r--r-- | lib/dtas/buffer/read_write.rb | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/lib/dtas/buffer/read_write.rb b/lib/dtas/buffer/read_write.rb index 0044400..11d1a95 100644 --- a/lib/dtas/buffer/read_write.rb +++ b/lib/dtas/buffer/read_write.rb @@ -17,25 +17,30 @@ module DTAS::Buffer::ReadWrite # :nodoc: def discard(bytes) buf = _rbuf begin - @to_io.read(bytes, buf) or break # EOF + @to_io.readpartial(bytes, buf) bytes -= buf.bytesize + rescue EOFError + return end until bytes == 0 end # always block when we have a single target - def broadcast_one(targets, bytes) + def broadcast_one(targets) buf = _rbuf - @to_io.read(bytes, buf) + @to_io.readpartial(MAX_AT_ONCE, buf) n = targets[0].write(buf) # IO#write has write-in-full behavior @bytes_xfer += n :wait_readable + rescue EOFError + nil rescue Errno::EPIPE, IOError => e __dst_error(targets[0], e) targets.clear nil # do not return error here, we already spewed an error message end - def broadcast_inf(targets, bytes) + def broadcast_inf(targets) + bytes = inflight nr_nb = targets.count { |sink| sink.nonblock? } if nr_nb == 0 || nr_nb == targets.size # if all targets are full, don't start until they're all writable |