ichannel 8.0.0 → 8.1.0
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.
- data/ChangeLog.txt +6 -2
- data/README.md +4 -2
- data/lib/ichannel/redis.rb +20 -0
- data/lib/ichannel/unix_socket.rb +161 -143
- data/lib/ichannel/version.rb +1 -1
- data/release-notes.txt +3 -0
- data/test/ichannel_redis_test.rb +8 -0
- data/test/ichannel_unix_test.rb +8 -0
- data/test/uniform_ichannel_test.rb +3 -1
- metadata +5 -4
data/ChangeLog.txt
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
== v8.1.0
|
2
|
+
- add Redis#{unix_socket,redis?}, UNIXSocket#{unix_socket?, redis?}
|
3
|
+
Predicates indicating if you have a redis or unix socket channel.
|
4
|
+
|
1
5
|
== v8.0.0
|
2
6
|
- Redis#write! does not time out.
|
3
7
|
A write to redis is not wrapped in Timeout.timeout() anymore
|
@@ -7,8 +11,8 @@
|
|
7
11
|
Redis#get!, UNIXSocket#get!, UNIXSocket#write! raise
|
8
12
|
IChannel::TimeoutError instead of Timeout::Error.
|
9
13
|
|
10
|
-
- Remove
|
11
|
-
'timeout' from
|
14
|
+
- Remove use of timeout.rb from lib/
|
15
|
+
retire 'timeout.rb' from stdlib
|
12
16
|
|
13
17
|
== v7.1.0
|
14
18
|
- Redis#last_msg, UNIXSocket#last_msg return last read value
|
data/README.md
CHANGED
@@ -115,8 +115,10 @@ And to finish:
|
|
115
115
|
|
116
116
|
__SEE ALSO__
|
117
117
|
|
118
|
-
- [ifuture](https://github.com/
|
119
|
-
|
118
|
+
- [ifuture](https://github.com/havenwood/ifuture)
|
119
|
+
An implementation of the future pattern that leverages
|
120
|
+
`Kernel#fork` and ichannel.
|
121
|
+
credit [@havenwood](https://github.com/havenwood).
|
120
122
|
|
121
123
|
__LICENSE__
|
122
124
|
|
data/lib/ichannel/redis.rb
CHANGED
@@ -144,4 +144,24 @@ class IChannel::Redis
|
|
144
144
|
def readable?
|
145
145
|
!closed? && !empty?
|
146
146
|
end
|
147
|
+
|
148
|
+
#
|
149
|
+
# @return [Boolean]
|
150
|
+
# Returns false.
|
151
|
+
#
|
152
|
+
# @see UNIXSocket#unix_socket?
|
153
|
+
#
|
154
|
+
def unix_socket?
|
155
|
+
false
|
156
|
+
end
|
157
|
+
|
158
|
+
#
|
159
|
+
# @return [Boolean]
|
160
|
+
# Returns true.
|
161
|
+
#
|
162
|
+
# @see UNIXSocket#redis?
|
163
|
+
#
|
164
|
+
def redis?
|
165
|
+
true
|
166
|
+
end
|
147
167
|
end
|
data/lib/ichannel/unix_socket.rb
CHANGED
@@ -1,160 +1,178 @@
|
|
1
1
|
require 'socket'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
end
|
2
|
+
class IChannel::UNIXSocket
|
3
|
+
SEP = '_$_'
|
4
|
+
if respond_to? :private_constant
|
5
|
+
private_constant :SEP
|
6
|
+
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
8
|
+
#
|
9
|
+
# @param [#dump,#load] serializer
|
10
|
+
# Any object that implements dump, & load.
|
11
|
+
#
|
12
|
+
# @return [IChannel::UNIXSocket]
|
13
|
+
#
|
14
|
+
def initialize(serializer = Marshal, adapter_options)
|
15
|
+
@serializer = serializer
|
16
|
+
@last_msg = nil
|
17
|
+
@reader, @writer = ::UNIXSocket.pair :STREAM
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
#
|
21
|
+
# @return [Boolean]
|
22
|
+
# Returns true when the channel is closed.
|
23
|
+
#
|
24
|
+
def closed?
|
25
|
+
@reader.closed? && @writer.closed?
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
28
|
+
#
|
29
|
+
# Close the channel.
|
30
|
+
#
|
31
|
+
# @return [Boolean]
|
32
|
+
# Returns true when the channel has been closed.
|
33
|
+
#
|
34
|
+
def close
|
35
|
+
unless closed?
|
36
|
+
@reader.close
|
37
|
+
@writer.close
|
38
|
+
true
|
41
39
|
end
|
40
|
+
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
42
|
+
#
|
43
|
+
# Add an object to the channel.
|
44
|
+
#
|
45
|
+
# @raise [IOError]
|
46
|
+
# When the channel is closed.
|
47
|
+
#
|
48
|
+
# @param [Object] object
|
49
|
+
# An object to add.
|
50
|
+
#
|
51
|
+
def write(object)
|
52
|
+
write!(object, nil)
|
53
|
+
end
|
54
|
+
alias_method :put, :write
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
76
|
-
_, writable, _ = IO.select nil, [@writer], nil, timeout
|
77
|
-
if writable
|
78
|
-
msg = @serializer.dump(object)
|
79
|
-
writable[0].syswrite "#{msg}#{SEP}"
|
80
|
-
else
|
81
|
-
raise IOError, 'The channel cannot be written to.'
|
82
|
-
end
|
56
|
+
#
|
57
|
+
# Add an object to the channel.
|
58
|
+
#
|
59
|
+
# @param
|
60
|
+
# (see IChannel#write)
|
61
|
+
#
|
62
|
+
# @param [Numeric] timeout
|
63
|
+
# The number of seconds to wait for the channel to become writable.
|
64
|
+
#
|
65
|
+
# @raise
|
66
|
+
# (see IChannel#write)
|
67
|
+
#
|
68
|
+
# @raise [IOError]
|
69
|
+
# When _timeout_ seconds elapse and the channel cannot be written to.
|
70
|
+
#
|
71
|
+
def write!(object, timeout = 0.1)
|
72
|
+
if @writer.closed?
|
73
|
+
raise IOError, 'The channel cannot be written to (closed).'
|
83
74
|
end
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
# @return [Object]
|
91
|
-
# Returns the last message to be written to the channel.
|
92
|
-
#
|
93
|
-
def last_msg
|
94
|
-
while readable?
|
95
|
-
@last_msg = get
|
96
|
-
end
|
97
|
-
@last_msg
|
75
|
+
_, writable, _ = IO.select nil, [@writer], nil, timeout
|
76
|
+
if writable
|
77
|
+
msg = @serializer.dump(object)
|
78
|
+
writable[0].syswrite "#{msg}#{SEP}"
|
79
|
+
else
|
80
|
+
raise IOError, 'The channel cannot be written to.'
|
98
81
|
end
|
82
|
+
end
|
83
|
+
alias_method :put!, :write!
|
99
84
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
recv!(nil)
|
85
|
+
#
|
86
|
+
# Reads the last message written to the channel by reading until the channel
|
87
|
+
# is empty. The last message is cached and reset to nil on call to {#close}.
|
88
|
+
#
|
89
|
+
# @return [Object]
|
90
|
+
# Returns the last message to be written to the channel.
|
91
|
+
#
|
92
|
+
def last_msg
|
93
|
+
while readable?
|
94
|
+
@last_msg = get
|
111
95
|
end
|
112
|
-
|
96
|
+
@last_msg
|
97
|
+
end
|
113
98
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
99
|
+
#
|
100
|
+
# Receive an object from the channel.
|
101
|
+
#
|
102
|
+
# @raise [IOError]
|
103
|
+
# When the channel is closed.
|
104
|
+
#
|
105
|
+
# @return [Object]
|
106
|
+
# The object read from the channel.
|
107
|
+
#
|
108
|
+
def recv
|
109
|
+
recv!(nil)
|
110
|
+
end
|
111
|
+
alias_method :get, :recv
|
112
|
+
|
113
|
+
#
|
114
|
+
# Receive an object from the channel.
|
115
|
+
#
|
116
|
+
# Unlike {#recv}, which waits indefinitely until the channel becomes readable,
|
117
|
+
# this method will raise an IOError when _timeout_ seconds elapse and the
|
118
|
+
# channel remains unreadable.
|
119
|
+
#
|
120
|
+
# @param [Numeric] timeout
|
121
|
+
# The number of seconds to wait for the channel to become readable.
|
122
|
+
#
|
123
|
+
# @raise [IOError]
|
124
|
+
# (see IChannel#recv)
|
125
|
+
#
|
126
|
+
# @raise [IChannel::TimeoutError]
|
127
|
+
# When _timeout_ seconds elapse & the channel remains unreadable.
|
128
|
+
#
|
129
|
+
# @return [Object]
|
130
|
+
# The object read from the channel.
|
131
|
+
#
|
132
|
+
def recv!(timeout = 0.1)
|
133
|
+
if @reader.closed?
|
134
|
+
raise IOError, 'The channel cannot be read from (closed).'
|
135
|
+
end
|
136
|
+
readable, _ = IO.select [@reader], nil, nil, timeout
|
137
|
+
if readable
|
138
|
+
msg = readable[0].readline(SEP).chomp SEP
|
139
|
+
@last_msg = @serializer.load msg
|
140
|
+
else
|
141
|
+
raise IChannel::TimeoutError, 'Time out on read (waited for %s second(s))' % [timeout]
|
144
142
|
end
|
145
|
-
|
143
|
+
end
|
144
|
+
alias_method :get!, :recv!
|
146
145
|
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
end
|
146
|
+
#
|
147
|
+
# @return [Boolean]
|
148
|
+
# Returns true when the channel is readable.
|
149
|
+
#
|
150
|
+
def readable?
|
151
|
+
if closed?
|
152
|
+
false
|
153
|
+
else
|
154
|
+
readable, _ = IO.select [@reader], nil, nil, 0
|
155
|
+
!! readable
|
158
156
|
end
|
159
157
|
end
|
158
|
+
|
159
|
+
#
|
160
|
+
# @return [Boolean]
|
161
|
+
# Returns true.
|
162
|
+
#
|
163
|
+
# @see Redis#unix_socket?
|
164
|
+
#
|
165
|
+
def unix_socket?
|
166
|
+
true
|
167
|
+
end
|
168
|
+
|
169
|
+
#
|
170
|
+
# @return [Boolean]
|
171
|
+
# Returns false.
|
172
|
+
#
|
173
|
+
# @see Redis#redis?
|
174
|
+
#
|
175
|
+
def redis?
|
176
|
+
false
|
177
|
+
end
|
160
178
|
end
|
data/lib/ichannel/version.rb
CHANGED
data/release-notes.txt
ADDED
data/test/ichannel_redis_test.rb
CHANGED
@@ -22,4 +22,12 @@ class IChannelRedisTest < testcase
|
|
22
22
|
@channel.instance_variable_get(:@redis).del(key)
|
23
23
|
@channel.close
|
24
24
|
end
|
25
|
+
|
26
|
+
def test_redis?
|
27
|
+
assert_equal true, @channel.redis?
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_unix_socket?
|
31
|
+
assert_equal false, @channel.unix_socket?
|
32
|
+
end
|
25
33
|
end
|
data/test/ichannel_unix_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ichannel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.
|
4
|
+
version: 8.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: interprocess communication channel
|
15
15
|
email:
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/ichannel/redis.rb
|
35
35
|
- lib/ichannel/unix_socket.rb
|
36
36
|
- lib/ichannel/version.rb
|
37
|
+
- release-notes.txt
|
37
38
|
- test/ichannel_redis_test.rb
|
38
39
|
- test/ichannel_unix_test.rb
|
39
40
|
- test/setup.rb
|
@@ -52,7 +53,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
53
|
version: '0'
|
53
54
|
segments:
|
54
55
|
- 0
|
55
|
-
hash:
|
56
|
+
hash: -1427294118300470678
|
56
57
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
58
|
none: false
|
58
59
|
requirements:
|
@@ -61,7 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
62
|
version: '0'
|
62
63
|
segments:
|
63
64
|
- 0
|
64
|
-
hash:
|
65
|
+
hash: -1427294118300470678
|
65
66
|
requirements: []
|
66
67
|
rubyforge_project:
|
67
68
|
rubygems_version: 1.8.23
|