raindrops RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: raindrops-public@bogomips.org
Subject: [PATCH 2/3] aggregate/pmq: remove io-extra requirement
Date: Thu, 16 Mar 2017 03:14:11 +0000	[thread overview]
Message-ID: <20170316031412.16713-3-e@80x24.org> (raw)
In-Reply-To: <20170316031412.16713-1-e@80x24.org>

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.
---
 lib/raindrops/aggregate/pmq.rb | 12 ++++++++----
 raindrops.gemspec              |  1 -
 2 files changed, 8 insertions(+), 5 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 "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 @@
 # 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 @@ def initialize(params = {})
       @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 @@ def aggregate
     @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 @@ def flush_master
     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
 
diff --git a/raindrops.gemspec b/raindrops.gemspec
index c00a6b5..4651fa9 100644
--- a/raindrops.gemspec
+++ b/raindrops.gemspec
@@ -22,7 +22,6 @@
   s.test_files = test_files
   s.add_development_dependency('aggregate', '~> 0.2')
   s.add_development_dependency('test-unit', '~> 3.0')
-  s.add_development_dependency('io-extra', [ '~> 1.2', '>= 1.2.3'])
   s.add_development_dependency('posix_mq', '~> 2.0')
   s.add_development_dependency('rack', [ '>= 1.2', '< 3.0' ])
   s.add_development_dependency('olddoc', '~> 1.0')
-- 
EW


  parent reply	other threads:[~2017-03-16  3:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-16  3:14 [PATCH 0/3] aggregate/pmq: various fixes and cleanups Eric Wong
2017-03-16  3:14 ` [PATCH 1/3] aggregate/pmq: avoid false sharing of lock buffers Eric Wong
2017-03-16  3:14 ` Eric Wong [this message]
2017-03-16  3:14 ` [PATCH 3/3] aggregate/pmq: avoid File#stat allocation Eric Wong
2017-03-21 23:48 ` [PATCH 0/3] aggregate/pmq: various fixes and cleanups Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://yhbt.net/raindrops/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170316031412.16713-3-e@80x24.org \
    --to=e@80x24.org \
    --cc=raindrops-public@bogomips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhbt.net/raindrops.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).