sleepy_penguin 3.5.0
[sleepy_penguin.git] / lib / sleepy_penguin.rb
bloba69c64956ced7e59b51bc9bdab96040efd0a290d
1 # -*- encoding: binary -*-
2 require 'sleepy_penguin_ext'
4 # We need to serialize Inotify#take for Rubinius since that has no GVL
5 # to protect the internal array
6 if defined?(SleepyPenguin::Inotify) &&
7    defined?(Rubinius) && Rubinius.respond_to?(:synchronize)
8   class SleepyPenguin::Inotify
9     # :stopdoc:
10     alias __take take
11     undef_method :take
12     def take(*args)
13       Rubinius.synchronize(@inotify_tmp) { __take(*args) }
14     end
15     # :startdoc
16   end
17 end
19 module SleepyPenguin
20   require_relative 'sleepy_penguin/splice' if respond_to?(:__splice)
21   require_relative 'sleepy_penguin/cfr' if respond_to?(:__cfr)
22   require_relative 'sleepy_penguin/epoll' if const_defined?(:Epoll)
23   require_relative 'sleepy_penguin/kqueue' if const_defined?(:Kqueue)
25   # Copies +len+ bytes from +src+ to +dst+, where +src+ refers to
26   # an open, mmap(2)-able File and +dst+ refers to a Socket.
27   # An optional +offset+ keyword may be specified for the +src+ File.
28   # Using +offset+ will not adjust the offset of the underlying file
29   # handle itself; in other words: this allows concurrent threads to
30   # use linux_sendfile to write data from one open file to multiple
31   # sockets.
32   #
33   # Returns the number of bytes written on success, or :wait_writable
34   # if the +dst+ Socket is non-blocking and the operation would block.
35   # A return value of zero bytes indicates EOF is reached on the +src+
36   # file.
37   #
38   # Newer OSes may be more flexible in whether or not +dst+ or +src+
39   # is a regular file or socket, respectively.
40   #
41   # This method was added in sleepy_penguin 3.5.0.
42   def self.linux_sendfile(dst, src, len, offset: nil)
43     __lsf(dst, src, offset, len)
44   end
45 end