about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-05-12 19:59:45 +0000
committerEric Wong <normalperson@yhbt.net>2013-05-12 19:59:45 +0000
commitefcffd8befaf12cd2bf8ff6dc6cb339a768c7ea6 (patch)
tree8586d2892df2f33d7c3f109f559bb1bff0fd9962
parentb9979f380f1dc8bbde89c16b0fa25a67f9bc1830 (diff)
downloadruby_io_splice-efcffd8befaf12cd2bf8ff6dc6cb339a768c7ea6.tar.gz
In retrospect, these methods are too infrequently useful and
causes problems too easily to be worth supporting.
-rw-r--r--lib/io/splice.rb24
1 files 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_splice_ext'
 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 @@ module IO::Splice
   # 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 @@ module IO::Splice
   #
   # 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