sleepy_penguin.git  about / heads / tags
Linux I/O events for Ruby
blob a69c64956ced7e59b51bc9bdab96040efd0a290d 1671 bytes (raw)
$ git show HEAD:lib/sleepy_penguin.rb	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 
# -*- encoding: binary -*-
require 'sleepy_penguin_ext'

# We need to serialize Inotify#take for Rubinius since that has no GVL
# to protect the internal array
if defined?(SleepyPenguin::Inotify) &&
   defined?(Rubinius) && Rubinius.respond_to?(:synchronize)
  class SleepyPenguin::Inotify
    # :stopdoc:
    alias __take take
    undef_method :take
    def take(*args)
      Rubinius.synchronize(@inotify_tmp) { __take(*args) }
    end
    # :startdoc
  end
end

module SleepyPenguin
  require_relative 'sleepy_penguin/splice' if respond_to?(:__splice)
  require_relative 'sleepy_penguin/cfr' if respond_to?(:__cfr)
  require_relative 'sleepy_penguin/epoll' if const_defined?(:Epoll)
  require_relative 'sleepy_penguin/kqueue' if const_defined?(:Kqueue)

  # Copies +len+ bytes from +src+ to +dst+, where +src+ refers to
  # an open, mmap(2)-able File and +dst+ refers to a Socket.
  # An optional +offset+ keyword may be specified for the +src+ File.
  # Using +offset+ will not adjust the offset of the underlying file
  # handle itself; in other words: this allows concurrent threads to
  # use linux_sendfile to write data from one open file to multiple
  # sockets.
  #
  # Returns the number of bytes written on success, or :wait_writable
  # if the +dst+ Socket is non-blocking and the operation would block.
  # A return value of zero bytes indicates EOF is reached on the +src+
  # file.
  #
  # Newer OSes may be more flexible in whether or not +dst+ or +src+
  # is a regular file or socket, respectively.
  #
  # This method was added in sleepy_penguin 3.5.0.
  def self.linux_sendfile(dst, src, len, offset: nil)
    __lsf(dst, src, offset, len)
  end
end

git clone https://yhbt.net/sleepy_penguin.git