From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, T_RP_MATCHES_RCVD,URIBL_BLOCKED shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: yahns-public@yhbt.net Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id C396E1F5F1 for ; Wed, 1 Apr 2015 23:36:17 +0000 (UTC) From: Eric Wong To: yahns-public@yhbt.net Subject: [PATCH] tmpio: add writev support via kgio Date: Wed, 1 Apr 2015 23:36:17 +0000 Message-Id: <1427931377-25473-1-git-send-email-e@80x24.org> List-Id: This will allow us to write arrays for chunked output without unnecessary data copies. --- lib/yahns/tmpio.rb | 1 + test/test_tmpio.rb | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 test/test_tmpio.rb diff --git a/lib/yahns/tmpio.rb b/lib/yahns/tmpio.rb index f0ddd2f..d25d5e8 100644 --- a/lib/yahns/tmpio.rb +++ b/lib/yahns/tmpio.rb @@ -7,6 +7,7 @@ require 'tmpdir' # well with unlinked files. This one is much shorter, easier # to understand, and slightly faster (no delegation). class Yahns::TmpIO < File # :nodoc: + include Kgio::PipeMethods # creates and returns a new File object. The File is unlinked # immediately, switched to binary mode, and userspace output diff --git a/test/test_tmpio.rb b/test/test_tmpio.rb new file mode 100644 index 0000000..79c9f32 --- /dev/null +++ b/test/test_tmpio.rb @@ -0,0 +1,20 @@ +# -*- encoding: binary -*- +# Copyright (C) 2009-2015 all contributors +# License: GPLv3 or later (https://www.gnu.org/licenses/gpl-2.0.txt) +require_relative 'helper' + +class TestTmpIO < Testcase + def test_writev + a, b = UNIXSocket.pair + a.extend Kgio::PipeMethods + tmpio = Yahns::TmpIO.new(Dir.tmpdir) + ary = [ "hello\n".freeze, "world\n".freeze ].freeze + tmpio.kgio_trywritev(ary) + a.trysendfile(tmpio, 0, 12) + assert_equal "hello\nworld\n", b.read(12) + ensure + b.close + a.close + tmpio.close + end +end -- EW