diff options
author | Eric Wong <e@80x24.org> | 2017-03-16 03:14:11 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2017-03-18 01:28:47 +0000 |
commit | 160ebb01ff5ac17d7ad78b8005e922cacadc56e4 (patch) | |
tree | cc8ad2227779f714402ce96f060397977a75eb64 /lib | |
parent | a7db691c628dc91084e15e0bd105420e93a9f1b4 (diff) | |
download | raindrops-160ebb01ff5ac17d7ad78b8005e922cacadc56e4.tar.gz |
IO.copy_stream is standard in 1.9+ and can use pread when given an offset. We do not need to use pwrite with fcntl locking, actually.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/raindrops/aggregate/pmq.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/raindrops/aggregate/pmq.rb b/lib/raindrops/aggregate/pmq.rb index f543302..5a6a1f6 100644 --- a/lib/raindrops/aggregate/pmq.rb +++ b/lib/raindrops/aggregate/pmq.rb @@ -3,8 +3,8 @@ require "tempfile" require "aggregate" require "posix_mq" require "fcntl" -require "io/extra" require "thread" +require "stringio" # \Aggregate + POSIX message queues support for Ruby 1.9 and \Linux # @@ -19,7 +19,6 @@ require "thread" # or libraries: # # * aggregate (tested with 0.2.2) -# * io-extra (tested with 1.2.3) # * posix_mq (tested with 1.0.0) # # == Design @@ -84,6 +83,7 @@ class Raindrops::Aggregate::PMQ @wr = File.open(t.path, "wb") @rd = File.open(t.path, "rb") end + @wr.sync = true @cached_aggregate = @aggregate flush_master @mq_send = if opts[:lossy] @@ -151,7 +151,10 @@ class Raindrops::Aggregate::PMQ @cached_aggregate ||= begin flush Marshal.load(synchronize(@rd, RDLOCK) do |rd| - IO.pread rd.fileno, rd.stat.size, 0 + dst = StringIO.new + dst.binmode + IO.copy_stream(rd, dst, rd.stat.size, 0) + dst.string end) end end @@ -163,7 +166,8 @@ class Raindrops::Aggregate::PMQ dump = Marshal.dump @aggregate synchronize(@wr, WRLOCK) do |wr| wr.truncate 0 - IO.pwrite wr.fileno, dump, 0 + wr.rewind + wr.write(dump) end end |