From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS47066 71.19.144.0/20 X-Spam-Status: No, score=-1.9 required=3.0 tests=AWL,BAYES_00, MSGID_FROM_MTA_HEADER shortcircuit=no autolearn=unavailable version=3.3.2 Path: news.gmane.org!not-for-mail From: Eric Wong Newsgroups: gmane.comp.lang.ruby.io-splice.general Subject: [PATCH 1/2] io/splice: deprecated potentially unsafe methods Date: Sun, 12 May 2013 20:02:55 +0000 Message-ID: <1368388976-20489-1-git-send-email-normalperson@yhbt.net> References: <1368388976-20489-1-git-send-email-normalperson@yhbt.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1368388993 23256 80.91.229.3 (12 May 2013 20:03:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 12 May 2013 20:03:13 +0000 (UTC) To: ruby.io.splice@librelist.org Original-X-From: ruby.io.splice@librelist.org Sun May 12 22:03:13 2013 Return-path: Envelope-to: gclrig-ruby.io.splice@m.gmane.org In-Reply-To: <1368388976-20489-1-git-send-email-normalperson@yhbt.net> List-Archive: List-Help: List-Id: List-Post: List-Subscribe: List-Unsubscribe: Precedence: list Original-Sender: ruby.io.splice@librelist.org Xref: news.gmane.org gmane.comp.lang.ruby.io-splice.general:44 Archived-At: Received: from zedshaw2.xen.prgmr.com ([71.19.156.177]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UbcUC-0005k3-2z for gclrig-ruby.io.splice@m.gmane.org; Sun, 12 May 2013 22:03:12 +0200 Received: from zedshaw2.xen.prgmr.com (unknown [IPv6:::1]) by zedshaw2.xen.prgmr.com (Postfix) with ESMTP id BA95773E11 for ; Sun, 12 May 2013 20:03:22 +0000 (UTC) In retrospect, these methods are too infrequently useful and causes problems too easily to be worth supporting. --- lib/io/splice.rb | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/io/splice.rb b/lib/io/splice.rb index 65d8ed4..9b17aa3 100644 --- a/lib/io/splice.rb +++ b/lib/io/splice.rb @@ -3,6 +3,14 @@ require 'io/wait' module IO::Splice + @warned = false + + def self.__deprecated + return if @warned + warn("IO::Splice.{copy_stream,full} are deprecated " \ + "and to be removed in io_splice 5.x") + @warned = true + end # The maximum default capacity of the pipe in bytes. # Under stock Linux, this is 65536 bytes as of 2.6.11, and 4096 before @@ -36,10 +44,19 @@ def self.need_open?(obj) # :nodoc: # Otherwise the copy will be until EOF is reached on the +src+. # +src+ and +dst+ must be IO objects or respond to +to_io+ # - # This is nearly a drop-in replacement for IO.copy_stream (in Ruby 1.9) - # but does not take into account userspace I/O buffers nor IO-like - # objects with no underlying file descriptor (e.g. StringIO). + # Unlike IO.copy_stream, this does not take into account + # userspace I/O buffers nor IO-like objects with no underlying + # file descriptor (e.g. StringIO). + # + # This is unsafe for socket-to-socket copies unless there is an + # active (blocking) reader on the other end. + # + # This method is deprecated and will be removed in a future, as it is + # potentially unsafe for socket-to-socket operations and difficult-to-use. + # IO.copy_stream on Linux 2.6.33 and later allows using sendfile for + # file-to-file copies, so this offers no advantage. def self.copy_stream(src, dst, len = nil, src_offset = nil) + __deprecated close = [] need_open?(src) and close << (src = File.open(src)) need_open?(dst) and close << (dst = File.open(dst, "w")) @@ -90,6 +107,7 @@ def self.copy_stream(src, dst, len = nil, src_offset = nil) # # This method is safe for splicing a pipe +src+ into any type of +dst+ IO. def self.full(src, dst, len, src_offset) + __deprecated IO.splice(src, src_offset, dst, nil, len, F_MOVE | WAITALL) end -- 1.8.2.1.367.gc875ca7