rb-kqueue 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/README.md +9 -1
- data/Rakefile +2 -42
- data/lib/rb-kqueue.rb +1 -1
- data/lib/rb-kqueue/event.rb +1 -1
- data/lib/rb-kqueue/native.rb +2 -0
- data/lib/rb-kqueue/native/flags.rb +6 -4
- data/lib/rb-kqueue/queue.rb +14 -3
- data/lib/rb-kqueue/watcher/file.rb +1 -1
- data/rb-kqueue.gemspec +19 -51
- metadata +42 -17
data/.gitignore
CHANGED
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -4,7 +4,15 @@ This is a simple wrapper over the [kqueue](http://en.wikipedia.org/wiki/Kqueue)
|
|
4
4
|
BSD event notification interface (supported on FreeBSD, NetBSD, OpenBSD, and Darwin).
|
5
5
|
It uses the [FFI](http://wiki.github.com/ffi/ffi) gem to avoid having to compile a C extension.
|
6
6
|
|
7
|
-
[API documentation is available on rdoc.info](http://rdoc.info/projects/
|
7
|
+
[API documentation is available on rdoc.info](http://rdoc.info/projects/mat813/rb-kqueue).
|
8
|
+
|
9
|
+
## WARNING
|
10
|
+
|
11
|
+
This code is incomplete, and didn't work last I had a chance to test it.
|
12
|
+
I don't have time to continue working on it at the moment,
|
13
|
+
so I'm posting it online for posterity and in case anyone wants to take a crack at it.
|
14
|
+
|
15
|
+
If anyone wants commit rights, just email me at nex342@gmail.com.
|
8
16
|
|
9
17
|
## Usage
|
10
18
|
|
data/Rakefile
CHANGED
@@ -1,45 +1,5 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'jeweler'
|
6
|
-
Jeweler::Tasks.new do |gem|
|
7
|
-
gem.name = "rb-kqueue"
|
8
|
-
gem.summary = "A Ruby wrapper for BSD's kqueue, using FFI"
|
9
|
-
gem.description = gem.summary
|
10
|
-
gem.email = "nex342@gmail.com"
|
11
|
-
gem.homepage = "http://github.com/nex3/rb-kqueue"
|
12
|
-
gem.authors = ["Nathan Weizenbaum"]
|
13
|
-
gem.add_dependency "ffi", ">= 0.5.0"
|
14
|
-
gem.add_development_dependency "yard", ">= 0.4.0"
|
15
|
-
end
|
16
|
-
Jeweler::GemcutterTasks.new
|
17
|
-
rescue LoadError
|
18
|
-
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
19
|
-
end
|
20
|
-
|
21
|
-
module Jeweler::VersionHelper::PlaintextExtension
|
22
|
-
def write_with_kqueue
|
23
|
-
write_without_kqueue
|
24
|
-
filename = File.join(File.dirname(__FILE__), "lib/rb-kqueue.rb")
|
25
|
-
text = File.read(filename)
|
26
|
-
File.open(filename, 'w') do |f|
|
27
|
-
f.write text.gsub(/^( VERSION = ).*/, '\1' + [major, minor, patch].inspect)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
alias_method :write_without_kqueue, :write
|
31
|
-
alias_method :write, :write_with_kqueue
|
32
|
-
end
|
33
|
-
|
34
|
-
class Jeweler::Commands::Version::Base
|
35
|
-
def commit_version_with_kqueue
|
36
|
-
return unless self.repo
|
37
|
-
self.repo.add(File.join(File.dirname(__FILE__), "lib/rb-kqueue.rb"))
|
38
|
-
commit_version_without_kqueue
|
39
|
-
end
|
40
|
-
alias_method :commit_version_without_kqueue, :commit_version
|
41
|
-
alias_method :commit_version, :commit_version_with_kqueue
|
42
|
-
end
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
43
3
|
|
44
4
|
begin
|
45
5
|
require 'yard'
|
data/lib/rb-kqueue.rb
CHANGED
@@ -13,7 +13,7 @@ require 'rb-kqueue/queue'
|
|
13
13
|
# * {Watcher} -- A watcher for a single sort of event
|
14
14
|
# * {Event} -- A notification that an event has occurred
|
15
15
|
module KQueue
|
16
|
-
VERSION = [0,
|
16
|
+
VERSION = [0, 2, 0]
|
17
17
|
|
18
18
|
# Raise an exception for a native kqueue error.
|
19
19
|
#
|
data/lib/rb-kqueue/event.rb
CHANGED
@@ -67,7 +67,7 @@ module KQueue
|
|
67
67
|
@filter = KQueue::Native::Flags.from_flag("EVFILT", @native[:filter])
|
68
68
|
@flags = Native::Flags.from_mask("EV", @native[:flags])
|
69
69
|
|
70
|
-
KQueue.handle_error @native[:data] if @flags.
|
70
|
+
KQueue.handle_error @native[:data] if @flags.include?(:error)
|
71
71
|
end
|
72
72
|
|
73
73
|
# Runs the callback for this event.
|
data/lib/rb-kqueue/native.rb
CHANGED
@@ -82,10 +82,11 @@ module KQueue
|
|
82
82
|
# @return [Array<Symbol>]
|
83
83
|
def self.from_mask(prefix, mask)
|
84
84
|
re = /^#{Regexp.quote prefix}_/
|
85
|
-
constants.select do |
|
85
|
+
constants.select do |sym|
|
86
|
+
c = sym.to_s
|
86
87
|
next false unless c =~ re
|
87
88
|
const_get(c) & mask != 0
|
88
|
-
end.map {|c| c.sub("#{prefix}_", "").downcase.to_sym}
|
89
|
+
end.map {|c| c.to_s.sub("#{prefix}_", "").downcase.to_sym}
|
89
90
|
end
|
90
91
|
|
91
92
|
# Converts a flag to the integer that the C API expects.
|
@@ -104,9 +105,10 @@ module KQueue
|
|
104
105
|
# @return [Symbol]
|
105
106
|
def self.from_flag(prefix, flag)
|
106
107
|
re = /^#{Regexp.quote prefix}_/
|
107
|
-
constants.each do |
|
108
|
+
constants.each do |sym|
|
109
|
+
c = sym.to_s
|
108
110
|
next unless c =~ re
|
109
|
-
return c.sub("#{prefix}_", "").downcase.to_sym if const_get(c) == flag
|
111
|
+
return c.to_s.sub("#{prefix}_", "").downcase.to_sym if const_get(c) == flag
|
110
112
|
end
|
111
113
|
end
|
112
114
|
end
|
data/lib/rb-kqueue/queue.rb
CHANGED
@@ -269,7 +269,7 @@ module KQueue
|
|
269
269
|
# @return [Watcher] The Watcher for this event.
|
270
270
|
# @raise [SystemCallError] If something goes wrong when registering the Watcher.
|
271
271
|
def watch_process(pid, *flags, &callback)
|
272
|
-
Watcher::Process.new(self,
|
272
|
+
Watcher::Process.new(self, pid, flags, callback)
|
273
273
|
end
|
274
274
|
|
275
275
|
# Watches for signals to this process.
|
@@ -337,15 +337,26 @@ module KQueue
|
|
337
337
|
read_events.each {|event| event.callback!}
|
338
338
|
end
|
339
339
|
|
340
|
+
def poll
|
341
|
+
read_events(false).each {|event| event.callback!}
|
342
|
+
end
|
343
|
+
|
344
|
+
NULL_TIMEOUT = Native::TimeSpec.new.tap { |ts|
|
345
|
+
ts[:tv_sec] = 0
|
346
|
+
ts[:tv_nsec] = 0
|
347
|
+
}
|
348
|
+
|
340
349
|
# Blocks until there are one or more filesystem events
|
341
350
|
# that this notifier has watchers registered for.
|
342
351
|
# Once there are events, returns their {Event} objects.
|
343
352
|
#
|
344
353
|
# @private
|
345
|
-
def read_events
|
354
|
+
def read_events(blocking = true)
|
346
355
|
size = 1024
|
347
356
|
eventlist = FFI::MemoryPointer.new(Native::KEvent, size)
|
348
|
-
|
357
|
+
|
358
|
+
timeout = blocking ? nil : NULL_TIMEOUT
|
359
|
+
res = Native.kevent(@fd, nil, 0, eventlist, size, timeout)
|
349
360
|
|
350
361
|
KQueue.handle_error if res < 0
|
351
362
|
(0...res).map {|i| KQueue::Event.new(Native::KEvent.new(eventlist[i]), self)}
|
data/rb-kqueue.gemspec
CHANGED
@@ -3,59 +3,27 @@
|
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = %q{rb-kqueue}
|
8
|
+
gem.version = "0.2.0"
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"README.md"
|
17
|
-
]
|
18
|
-
s.files = [
|
19
|
-
".gitignore",
|
20
|
-
".yardopts",
|
21
|
-
"MIT-LICENSE",
|
22
|
-
"README.md",
|
23
|
-
"Rakefile",
|
24
|
-
"VERSION",
|
25
|
-
"lib/rb-kqueue.rb",
|
26
|
-
"lib/rb-kqueue/event.rb",
|
27
|
-
"lib/rb-kqueue/native.rb",
|
28
|
-
"lib/rb-kqueue/native/flags.rb",
|
29
|
-
"lib/rb-kqueue/queue.rb",
|
30
|
-
"lib/rb-kqueue/watcher.rb",
|
31
|
-
"lib/rb-kqueue/watcher/file.rb",
|
32
|
-
"lib/rb-kqueue/watcher/process.rb",
|
33
|
-
"lib/rb-kqueue/watcher/read_write.rb",
|
34
|
-
"lib/rb-kqueue/watcher/signal.rb",
|
35
|
-
"lib/rb-kqueue/watcher/socket_read_write.rb",
|
36
|
-
"lib/rb-kqueue/watcher/timer.rb",
|
37
|
-
"rb-kqueue.gemspec"
|
38
|
-
]
|
39
|
-
s.homepage = %q{http://github.com/nex3/rb-kqueue}
|
40
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
41
|
-
s.require_paths = ["lib"]
|
42
|
-
s.rubygems_version = %q{1.3.5}
|
43
|
-
s.summary = %q{A Ruby wrapper for BSD's kqueue, using FFI}
|
10
|
+
gem.authors = ["Mathieu Arnold", "Nathan Weizenbaum"]
|
11
|
+
gem.email = %q{mat@mat.cc nex342@gmail.com}
|
12
|
+
gem.date = %q{2012-12-03}
|
13
|
+
gem.description = %q{A Ruby wrapper for BSD's kqueue, using FFI}
|
14
|
+
gem.extra_rdoc_files = %w(README.md)
|
44
15
|
|
45
|
-
|
46
|
-
|
47
|
-
|
16
|
+
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)/})
|
48
19
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
s.add_dependency(%q<ffi>, [">= 0.5.0"])
|
58
|
-
s.add_dependency(%q<yard>, [">= 0.4.0"])
|
59
|
-
end
|
20
|
+
gem.homepage = %q{http://github.com/mat813/rb-kqueue}
|
21
|
+
gem.rdoc_options = ["--charset=UTF-8"]
|
22
|
+
gem.require_paths = ["lib"]
|
23
|
+
gem.rubygems_version = %q{1.3.5}
|
24
|
+
gem.summary = %q{A Ruby wrapper for BSD's kqueue, using FFI}
|
25
|
+
|
26
|
+
gem.add_runtime_dependency(%q<ffi>, [">= 0.5.0"])
|
27
|
+
gem.add_development_dependency(%q<yard>, [">= 0.4.0"])
|
60
28
|
end
|
61
29
|
|
metadata
CHANGED
@@ -1,39 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb-kqueue
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
13
|
+
- Mathieu Arnold
|
7
14
|
- Nathan Weizenbaum
|
8
15
|
autorequire:
|
9
16
|
bindir: bin
|
10
17
|
cert_chain: []
|
11
18
|
|
12
|
-
date:
|
13
|
-
default_executable:
|
19
|
+
date: 2012-12-03 00:00:00 Z
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: ffi
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 11
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 5
|
33
|
+
- 0
|
23
34
|
version: 0.5.0
|
24
|
-
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
25
37
|
- !ruby/object:Gem::Dependency
|
26
38
|
name: yard
|
27
|
-
|
28
|
-
|
29
|
-
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
30
42
|
requirements:
|
31
43
|
- - ">="
|
32
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 15
|
46
|
+
segments:
|
47
|
+
- 0
|
48
|
+
- 4
|
49
|
+
- 0
|
33
50
|
version: 0.4.0
|
34
|
-
|
51
|
+
type: :development
|
52
|
+
version_requirements: *id002
|
35
53
|
description: A Ruby wrapper for BSD's kqueue, using FFI
|
36
|
-
email: nex342@gmail.com
|
54
|
+
email: mat@mat.cc nex342@gmail.com
|
37
55
|
executables: []
|
38
56
|
|
39
57
|
extensions: []
|
@@ -43,6 +61,7 @@ extra_rdoc_files:
|
|
43
61
|
files:
|
44
62
|
- .gitignore
|
45
63
|
- .yardopts
|
64
|
+
- Gemfile
|
46
65
|
- MIT-LICENSE
|
47
66
|
- README.md
|
48
67
|
- Rakefile
|
@@ -60,8 +79,7 @@ files:
|
|
60
79
|
- lib/rb-kqueue/watcher/socket_read_write.rb
|
61
80
|
- lib/rb-kqueue/watcher/timer.rb
|
62
81
|
- rb-kqueue.gemspec
|
63
|
-
|
64
|
-
homepage: http://github.com/nex3/rb-kqueue
|
82
|
+
homepage: http://github.com/mat813/rb-kqueue
|
65
83
|
licenses: []
|
66
84
|
|
67
85
|
post_install_message:
|
@@ -70,23 +88,30 @@ rdoc_options:
|
|
70
88
|
require_paths:
|
71
89
|
- lib
|
72
90
|
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
73
92
|
requirements:
|
74
93
|
- - ">="
|
75
94
|
- !ruby/object:Gem::Version
|
95
|
+
hash: 3
|
96
|
+
segments:
|
97
|
+
- 0
|
76
98
|
version: "0"
|
77
|
-
version:
|
78
99
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
79
101
|
requirements:
|
80
102
|
- - ">="
|
81
103
|
- !ruby/object:Gem::Version
|
104
|
+
hash: 3
|
105
|
+
segments:
|
106
|
+
- 0
|
82
107
|
version: "0"
|
83
|
-
version:
|
84
108
|
requirements: []
|
85
109
|
|
86
110
|
rubyforge_project:
|
87
|
-
rubygems_version: 1.
|
111
|
+
rubygems_version: 1.8.24
|
88
112
|
signing_key:
|
89
113
|
specification_version: 3
|
90
114
|
summary: A Ruby wrapper for BSD's kqueue, using FFI
|
91
115
|
test_files: []
|
92
116
|
|
117
|
+
has_rdoc:
|