rb-kqueue 0.2.1 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 78c0252826cd5dbb42baf397441e76a75ccc43c0
4
- data.tar.gz: 2e1dc0fe3c9df91b5ebede02074380391aacddf1
2
+ SHA256:
3
+ metadata.gz: 0f24844743c7766edc2ddfa6c7c125a5ff7419eac128d6695fcb8da70c07d66b
4
+ data.tar.gz: '008dd0f2124471e3a190cb80458774076d6ed5f1cbba1dc020f8e6a0f3250eb8'
5
5
  SHA512:
6
- metadata.gz: 4b18a3176de712e04ae937c12c91fac319cb05b47286cc2aa4b7dd0244e937d8c86de8ad6db6768c6eadba56e7161544289eb7c666687acbbda7c2cee36e9d28
7
- data.tar.gz: 43e9c02219fd75c0060a14a2c9340788a8a48ef2adab351532a492803bbaed8dc8070c91907657a94c7daab75f23f756f077b3dd32f1347b5cd7274ba2889529
6
+ metadata.gz: d86c4ef6d17773c5ca1b6567ea9be15b7c2b179bac98253d7c2d230dea89d6ba8c0c20badd335e3944843eb1902b077fb0690eb392ba0b6cf357c8362521676d
7
+ data.tar.gz: bbdde67f0d98268d46c7b4c8a13fe0497a017671efdfbab0c7754f577c2a58aa4e8397603f033ad316fb4f28633a6fe78e1ee21c1e3bb71c2c62fc4b6ba0fa7b
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ rb-kqueue
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.6.5
data/lib/rb-kqueue.rb CHANGED
@@ -4,8 +4,11 @@ require 'rb-kqueue/watcher'
4
4
  require 'rb-kqueue/watcher/file'
5
5
  require 'rb-kqueue/watcher/read_write'
6
6
  require 'rb-kqueue/watcher/process'
7
+ require 'rb-kqueue/watcher/signal'
8
+ require 'rb-kqueue/watcher/timer'
7
9
  require 'rb-kqueue/event'
8
10
  require 'rb-kqueue/queue'
11
+ require 'rb-kqueue/version'
9
12
 
10
13
  # The root module of the library, which is laid out as so:
11
14
  #
@@ -13,8 +16,6 @@ require 'rb-kqueue/queue'
13
16
  # * {Watcher} -- A watcher for a single sort of event
14
17
  # * {Event} -- A notification that an event has occurred
15
18
  module KQueue
16
- VERSION = [0, 2, 1]
17
-
18
19
  # Raise an exception for a native kqueue error.
19
20
  #
20
21
  # @param errno [Fixnum] The errno identifying the sort of error.
@@ -3,6 +3,11 @@ module KQueue
3
3
  # Each {Watcher} can fire many events,
4
4
  # which are passed to that Watcher's callback.
5
5
  class Event
6
+
7
+ # Exception raised on an attempt to construct an {Event}
8
+ # from a native event with unexpected field values.
9
+ class UnexpectedEvent < Exception; end
10
+
6
11
  # Some integer data, the interpretation of which
7
12
  # is specific to each individual {Watcher}.
8
13
  # For specifics, see the individual Watcher subclasses.
@@ -64,7 +69,11 @@ module KQueue
64
69
  @native = native
65
70
  @queue = queue
66
71
  @data = @native[:data]
67
- @filter = KQueue::Native::Flags.from_flag("EVFILT", @native[:filter])
72
+ begin
73
+ @filter = KQueue::Native::Flags.from_flag("EVFILT", @native[:filter])
74
+ rescue Native::Flags::FlagNotFound
75
+ raise UnexpectedEvent
76
+ end
68
77
  @flags = Native::Flags.from_mask("EV", @native[:flags])
69
78
 
70
79
  KQueue.handle_error @native[:data] if @flags.include?(:error)
@@ -13,13 +13,39 @@ module KQueue
13
13
  #
14
14
  # @private
15
15
  class KEvent < FFI::Struct
16
- layout(
17
- :ident, :uintptr_t,
18
- :filter, :int16,
19
- :flags, :uint16,
20
- :fflags, :uint32,
21
- :data, :intptr_t,
22
- :udata, :pointer)
16
+ if FFI::Platform::IS_FREEBSD
17
+ layout(
18
+ :ident, :uintptr_t,
19
+ :filter, :short,
20
+ :flags, :u_short,
21
+ :fflags, :u_int,
22
+ :data, :intptr_t,
23
+ :udata, :pointer)
24
+ elsif FFI::Platform::IS_NETBSD
25
+ layout(
26
+ :ident, :uintptr_t,
27
+ :filter, :uint32_t,
28
+ :flags, :uint32_t,
29
+ :fflags, :uint32_t,
30
+ :data, :int64_t,
31
+ :udata, :pointer)
32
+ elsif FFI::Platform::IS_OPENBSD
33
+ layout(
34
+ :ident, :__uintptr_t,
35
+ :filter, :short,
36
+ :flags, :u_short,
37
+ :fflags, :u_int,
38
+ :data, :quad_t,
39
+ :udata, :pointer)
40
+ else
41
+ layout(
42
+ :ident, :uintptr_t,
43
+ :filter, :int16,
44
+ :flags, :uint16,
45
+ :fflags, :uint32,
46
+ :data, :intptr_t,
47
+ :udata, :pointer)
48
+ end
23
49
  end
24
50
 
25
51
  # The C struct describing a timeout.
@@ -6,17 +6,50 @@ module KQueue
6
6
  # @private
7
7
  module Flags
8
8
  # Filters
9
- EVFILT_READ = -1
10
- EVFILT_WRITE = -2
11
- EVFILT_AIO = -3 # Attached to aio requests
12
- EVFILT_VNODE = -4 # Attached to vnodes
13
- EVFILT_PROC = -5 # Attached to struct proc
14
- EVFILT_SIGNAL = -6 # Attached to struct proc
15
- EVFILT_TIMER = -7 # Timers
16
- EVFILT_MACHPORT = -8 # Mach portsets
17
- EVFILT_FS = -9 # Filesystem events
18
- EVFILT_USER = -10 # User events
19
- EVFILT_SESSION = -11 # Audit session events
9
+ if FFI::Platform::IS_FREEBSD
10
+ EVFILT_READ = -1
11
+ EVFILT_WRITE = -2
12
+ EVFILT_AIO = -3 # Attached to aio requests
13
+ EVFILT_VNODE = -4 # Attached to vnodes
14
+ EVFILT_PROC = -5 # Attached to struct proc
15
+ EVFILT_SIGNAL = -6 # Attached to struct proc
16
+ EVFILT_TIMER = -7 # Timers
17
+ EVFILT_PROCDESC = -8 # Attached to process descriptors
18
+ EVFILT_FS = -9 # Filesystem events
19
+ EVFILT_LIO = -10 # Attached to lio requests
20
+ EVFILT_USER = -11 # User events
21
+ EVFILT_SENDFILE = -12 # Attached to sendfile requests
22
+ EVFILT_SYSCOUNT = 12
23
+ elsif FFI::Platform::IS_NETBSD
24
+ EVFILT_READ = 0
25
+ EVFILT_WRITE = 1
26
+ EVFILT_AIO = 2 # Attached to aio requests
27
+ EVFILT_VNODE = 3 # Attached to vnodes
28
+ EVFILT_PROC = 4 # Attached to struct proc
29
+ EVFILT_SIGNAL = 5 # Attached to struct proc
30
+ EVFILT_TIMER = 6 # Arbitrary timer (in ms)
31
+ EVFILT_SYSCOUNT = 7 # Number of filters
32
+ elsif FFI::Platform::IS_OPENBSD
33
+ EVFILT_READ = -1
34
+ EVFILT_WRITE = -2
35
+ EVFILT_AIO = -3 # Attached to aio requests
36
+ EVFILT_VNODE = -4 # Attached to vnodes
37
+ EVFILT_PROC = -5 # Attached to struct proc
38
+ EVFILT_SIGNAL = -6 # Attached to struct proc
39
+ EVFILT_TIMER = -7 # Timers
40
+ else
41
+ EVFILT_READ = -1
42
+ EVFILT_WRITE = -2
43
+ EVFILT_AIO = -3 # Attached to aio requests
44
+ EVFILT_VNODE = -4 # Attached to vnodes
45
+ EVFILT_PROC = -5 # Attached to struct proc
46
+ EVFILT_SIGNAL = -6 # Attached to struct proc
47
+ EVFILT_TIMER = -7 # Timers
48
+ EVFILT_MACHPORT = -8 # Mach portsets
49
+ EVFILT_FS = -9 # Filesystem events
50
+ EVFILT_USER = -10 # User events
51
+ EVFILT_SESSION = -11 # Audit session events
52
+ end
20
53
 
21
54
 
22
55
  # Actions
@@ -64,6 +97,9 @@ module KQueue
64
97
  NOTE_TIMER_NSECONDS = 0x00000004 # data is nanoseconds
65
98
  NOTE_TIMER_ABSOLUTE = 0x00000008 # absolute timeout
66
99
 
100
+ # Exception raised when a function fails to find a flag satisfying
101
+ # its given query.
102
+ class FlagNotFound < Exception; end
67
103
 
68
104
  # Converts a list of flags to the bitmask that the C API expects.
69
105
  #
@@ -110,6 +146,7 @@ module KQueue
110
146
  next unless c =~ re
111
147
  return c.to_s.sub("#{prefix}_", "").downcase.to_sym if const_get(c) == flag
112
148
  end
149
+ raise FlagNotFound
113
150
  end
114
151
  end
115
152
  end
@@ -359,7 +359,13 @@ module KQueue
359
359
  res = Native.kevent(@fd, nil, 0, eventlist, size, timeout)
360
360
 
361
361
  KQueue.handle_error if res < 0
362
- (0...res).map {|i| KQueue::Event.new(Native::KEvent.new(eventlist[i]), self)}
362
+ (0...res).map do |i|
363
+ begin
364
+ KQueue::Event.new(Native::KEvent.new(eventlist[i]), self)
365
+ rescue KQueue::Event::UnexpectedEvent
366
+ nil
367
+ end
368
+ end.compact
363
369
  end
364
370
  end
365
371
  end
@@ -0,0 +1,3 @@
1
+ module KQueue
2
+ VERSION = [0, 2, 6]
3
+ end
@@ -19,9 +19,9 @@ module KQueue
19
19
  def initialize(queue, signal, callback)
20
20
  if signal.is_a?(String)
21
21
  @name = signal
22
- @number = Signal.list[signal]
22
+ @number = ::Signal.list[signal]
23
23
  else
24
- @name = Signal.list.find {|_, n| n == signal}.first
24
+ @name = ::Signal.list.find {|_, n| n == signal}.first
25
25
  @number = signal
26
26
  end
27
27
 
data/rb-kqueue.gemspec CHANGED
@@ -1,29 +1,25 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
1
+ require File.expand_path('../lib/rb-kqueue/version', __FILE__)
5
2
 
6
3
  Gem::Specification.new do |gem|
7
4
  gem.name = %q{rb-kqueue}
8
- gem.version = "0.2.1"
5
+ gem.version = KQueue::VERSION.join(".")
9
6
 
10
7
  gem.authors = ["Mathieu Arnold", "Nathan Weizenbaum"]
11
8
  gem.email = %q{mat@mat.cc nex342@gmail.com}
12
- gem.date = %q{2012-12-03}
13
9
  gem.description = %q{A Ruby wrapper for BSD's kqueue, using FFI}
14
10
  gem.extra_rdoc_files = %w(README.md)
11
+ gem.licenses = ['MIT']
15
12
 
16
13
  gem.files = `git ls-files`.split(/\n/)
17
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
16
 
20
17
  gem.homepage = %q{http://github.com/mat813/rb-kqueue}
21
18
  gem.rdoc_options = ["--charset=UTF-8"]
22
19
  gem.require_paths = ["lib"]
23
- gem.rubygems_version = %q{1.3.5}
24
20
  gem.summary = %q{A Ruby wrapper for BSD's kqueue, using FFI}
25
21
 
26
22
  gem.add_runtime_dependency(%q<ffi>, [">= 0.5.0"])
27
23
  gem.add_development_dependency(%q<yard>, [">= 0.4.0"])
24
+ gem.add_development_dependency(%q<rspec>, [">= 3.3.0"])
28
25
  end
29
-
@@ -0,0 +1,32 @@
1
+ require_relative '../lib/rb-kqueue'
2
+ require 'tempfile'
3
+ require 'pathname'
4
+
5
+ RSpec.describe KQueue::Queue do
6
+ describe '#watch_file' do
7
+ let(:file_touched) { false }
8
+ let(:queue) { KQueue::Queue.new }
9
+ let(:file) { Tempfile.new 'rb-kqueue_test', Pathname(__dir__).parent.join('tmp') }
10
+
11
+ context 'file is watched for writes' do
12
+ before do
13
+ queue.watch_file file.path, :write do
14
+ file_touched = !file_touched
15
+ end
16
+ queue.process
17
+ end
18
+
19
+ context 'file is written to' do
20
+ it 'executes the defined block' do
21
+ expect { file.write 'test' }.to change { file_touched }.from(false).to true
22
+ end
23
+ end
24
+ end
25
+
26
+ context 'file is watched for reads' do
27
+ end
28
+
29
+ context 'file is not watched' do
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,96 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Allows RSpec to persist some state between runs in order to support
54
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
55
+ # you configure your source control system to ignore this file.
56
+ config.example_status_persistence_file_path = "spec/examples.txt"
57
+
58
+ # Limits the available syntax to the non-monkey patched syntax that is
59
+ # recommended. For more details, see:
60
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
61
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
62
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
63
+ config.disable_monkey_patching!
64
+
65
+ # This setting enables warnings. It's recommended, but in some cases may
66
+ # be too noisy due to issues in dependencies.
67
+ config.warnings = true
68
+
69
+ # Many RSpec users commonly either run the entire suite or an individual
70
+ # file, and it's useful to allow more verbose output when running an
71
+ # individual spec file.
72
+ if config.files_to_run.one?
73
+ # Use the documentation formatter for detailed output,
74
+ # unless a formatter has already been configured
75
+ # (e.g. via a command-line flag).
76
+ config.default_formatter = 'doc'
77
+ end
78
+
79
+ # Print the 10 slowest examples and example groups at the
80
+ # end of the spec run, to help surface which specs are running
81
+ # particularly slow.
82
+ config.profile_examples = 10
83
+
84
+ # Run specs in random order to surface order dependencies. If you find an
85
+ # order dependency and want to debug it, you can fix the order by providing
86
+ # the seed, which is printed after each run.
87
+ # --seed 1234
88
+ config.order = :random
89
+
90
+ # Seed global randomization in this process using the `--seed` CLI option.
91
+ # Setting this allows you to use `--seed` to deterministically reproduce
92
+ # test failures related to randomization by passing the same `--seed` value
93
+ # as the one that triggered the failure.
94
+ Kernel.srand config.seed
95
+ =end
96
+ end
metadata CHANGED
@@ -1,44 +1,58 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb-kqueue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathieu Arnold
8
8
  - Nathan Weizenbaum
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-03 00:00:00.000000000 Z
12
+ date: 2021-04-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
20
  version: 0.5.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: 0.5.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: yard
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
34
  version: 0.4.0
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
41
  version: 0.4.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 3.3.0
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: 3.3.0
42
56
  description: A Ruby wrapper for BSD's kqueue, using FFI
43
57
  email: mat@mat.cc nex342@gmail.com
44
58
  executables: []
@@ -46,18 +60,21 @@ extensions: []
46
60
  extra_rdoc_files:
47
61
  - README.md
48
62
  files:
49
- - .gitignore
50
- - .yardopts
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".ruby-gemset"
66
+ - ".ruby-version"
67
+ - ".yardopts"
51
68
  - Gemfile
52
69
  - MIT-LICENSE
53
70
  - README.md
54
71
  - Rakefile
55
- - VERSION
56
72
  - lib/rb-kqueue.rb
57
73
  - lib/rb-kqueue/event.rb
58
74
  - lib/rb-kqueue/native.rb
59
75
  - lib/rb-kqueue/native/flags.rb
60
76
  - lib/rb-kqueue/queue.rb
77
+ - lib/rb-kqueue/version.rb
61
78
  - lib/rb-kqueue/watcher.rb
62
79
  - lib/rb-kqueue/watcher/file.rb
63
80
  - lib/rb-kqueue/watcher/process.rb
@@ -66,28 +83,32 @@ files:
66
83
  - lib/rb-kqueue/watcher/socket_read_write.rb
67
84
  - lib/rb-kqueue/watcher/timer.rb
68
85
  - rb-kqueue.gemspec
86
+ - spec/kqueue_queue_spec.rb
87
+ - spec/spec_helper.rb
69
88
  homepage: http://github.com/mat813/rb-kqueue
70
- licenses: []
89
+ licenses:
90
+ - MIT
71
91
  metadata: {}
72
- post_install_message:
92
+ post_install_message:
73
93
  rdoc_options:
74
- - --charset=UTF-8
94
+ - "--charset=UTF-8"
75
95
  require_paths:
76
96
  - lib
77
97
  required_ruby_version: !ruby/object:Gem::Requirement
78
98
  requirements:
79
- - - '>='
99
+ - - ">="
80
100
  - !ruby/object:Gem::Version
81
101
  version: '0'
82
102
  required_rubygems_version: !ruby/object:Gem::Requirement
83
103
  requirements:
84
- - - '>='
104
+ - - ">="
85
105
  - !ruby/object:Gem::Version
86
106
  version: '0'
87
107
  requirements: []
88
- rubyforge_project:
89
- rubygems_version: 2.2.1
90
- signing_key:
108
+ rubygems_version: 3.0.9
109
+ signing_key:
91
110
  specification_version: 4
92
111
  summary: A Ruby wrapper for BSD's kqueue, using FFI
93
- test_files: []
112
+ test_files:
113
+ - spec/kqueue_queue_spec.rb
114
+ - spec/spec_helper.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.0