ichannel 5.0.1 → 5.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/.gitattributes ADDED
@@ -0,0 +1 @@
1
+ * text eol=lf
data/ChangeLog.txt CHANGED
@@ -1,32 +1,46 @@
1
+ == HEAD
2
+
3
+ == v5.1.0
4
+ * Remove restriction on size of message.
5
+
6
+ IChannel#get can read a message of any size(before hand it was limited to
7
+ 1MB in size). Thanks to @quezacoatl.
8
+
9
+ * IChannel#readable? no longer blocks.
10
+
11
+ IChannel#readable? no longer blocks for 0.1 seconds on IO.select call.
12
+ Thanks to quezacoatl(https://github.com/quezacoatl) for the initial
13
+ implementation.
14
+
1
15
  == v5.0.0
2
16
  * Remove IChannel#empty?
3
17
 
4
- I think the #readable? method is all you need, and is a much more
5
- accurate description of what the method is asking. We cannot determine
6
- if the channel is really empty, but we can ask if it is readable at the
7
- time you ask.
18
+ I think the #readable? method is all you need, and is a much more
19
+ accurate description of what the method is asking. We cannot determine
20
+ if the channel is really empty, but we can ask if it is readable at the
21
+ time you ask.
8
22
 
9
23
  == v4.1.0
10
24
  * Add IChannel#readable?
11
25
 
12
- A method that can tell you whether or not a read would block.
13
- When it returns true, a read shouldn't block, on the other hand
14
- if it were false it'd likely block by the time you call #get.
26
+ A method that can tell you whether or not a read would block.
27
+ When it returns true, a read shouldn't block, on the other hand
28
+ if it were false it'd likely block by the time you call #get.
15
29
 
16
30
  == v4.0.0
17
31
  * Modify IChannel#empty?
18
32
 
19
- It now returns true in case the underlying UNIXSocket being used as a
20
- reader is closed.
33
+ It now returns true in case the underlying UNIXSocket being used as a
34
+ reader is closed.
21
35
 
22
36
  == v3.1.0
23
37
  * Add IChannel#empty?.
24
38
 
25
- IChannel#empty? returns true when the channel is empty(nothing to read).
39
+ IChannel#empty? returns true when the channel is empty(nothing to read).
26
40
 
27
41
  * Micro speed improvement on #write!, & #recv! operations.
28
42
 
29
- By passing nil instead of creating two empty arrays for every read/write
30
- operation we should see a very small improvement in their performance.
43
+ By passing nil instead of creating two empty arrays for every read/write
44
+ operation we should see a very small improvement in their performance.
31
45
 
32
46
  * Add ChangeLog.txt
@@ -1,3 +1,3 @@
1
1
  class IChannel
2
- VERSION = "5.0.1"
2
+ VERSION = "5.1.0"
3
3
  end
data/lib/ichannel.rb CHANGED
@@ -1,12 +1,16 @@
1
1
  require 'socket'
2
2
  class IChannel
3
+ SEP = '_$_'
4
+ if respond_to? :private_constant
5
+ private_constant :SEP
6
+ end
3
7
  #
4
8
  # @param [#dump,#load] serializer
5
9
  # Any object that implements dump, & load.
6
- #
7
- def initialize(serializer)
10
+ #
11
+ def initialize(serializer)
8
12
  @reader, @writer = UNIXSocket.pair Socket::SOCK_DGRAM
9
- @serializer = serializer
13
+ @serializer = serializer
10
14
  end
11
15
 
12
16
  #
@@ -35,7 +39,7 @@ class IChannel
35
39
  #
36
40
  # Add an object to the channel.
37
41
  #
38
- # @raise [IOError]
42
+ # @raise [IOError]
39
43
  # When the channel is closed.
40
44
  #
41
45
  # @param [Object] object
@@ -50,19 +54,19 @@ class IChannel
50
54
  # Add an object to the channel.
51
55
  #
52
56
  # Unlike {#write}, which waits indefinitely until the channel becomes writable,
53
- # this method will raise an IOError when _timeout_ seconds elapse and
57
+ # this method will raise an IOError when _timeout_ seconds elapse and
54
58
  # the channel remains unwritable.
55
59
  #
56
- # @param
60
+ # @param
57
61
  # (see IChannel#write)
58
62
  #
59
63
  # @param [Numeric] timeout
60
64
  # The number of seconds to wait for the channel to become writable.
61
65
  #
62
- # @raise (see IChannel#write)
66
+ # @raise (see IChannel#write)
63
67
  #
64
68
  # @raise [IOError]
65
- # When _timeout_ seconds elapse & the channel remains unwritable.
69
+ # When _timeout_ seconds elapse & the channel remains unwritable.
66
70
  #
67
71
  def write!(object, timeout = 0.1)
68
72
  if @writer.closed?
@@ -70,7 +74,8 @@ class IChannel
70
74
  end
71
75
  _, writable, _ = IO.select nil, [@writer], nil, timeout
72
76
  if writable
73
- writable[0].syswrite @serializer.dump(object)
77
+ msg = @serializer.dump(object)
78
+ writable[0].syswrite "#{msg}#{SEP}"
74
79
  else
75
80
  raise IOError, 'The channel cannot be written to.'
76
81
  end
@@ -85,7 +90,7 @@ class IChannel
85
90
  #
86
91
  # @return [Object]
87
92
  # The object read from the channel.
88
- #
93
+ #
89
94
  def recv
90
95
  recv!(nil)
91
96
  end
@@ -94,19 +99,19 @@ class IChannel
94
99
  #
95
100
  # Receive an object from the channel.
96
101
  #
97
- # Unlike {#recv}, which waits indefinitely until the channel becomes readable,
98
- # this method will raise an IOError when _timeout_ seconds elapse and the
102
+ # Unlike {#recv}, which waits indefinitely until the channel becomes readable,
103
+ # this method will raise an IOError when _timeout_ seconds elapse and the
99
104
  # channel remains unreadable.
100
105
  #
101
106
  # @param [Numeric] timeout
102
107
  # The number of seconds to wait for the channel to become readable.
103
- #
108
+ #
104
109
  # @raise [IOError]
105
110
  # (see IChannel#recv)
106
- #
111
+ #
107
112
  # @raise [IOError]
108
113
  # When _timeout_ seconds elapse & the channel remains unreadable.
109
- #
114
+ #
110
115
  # @return [Object]
111
116
  # The object read from the channel.
112
117
  #
@@ -116,7 +121,7 @@ class IChannel
116
121
  end
117
122
  readable, _ = IO.select [@reader], nil, nil, timeout
118
123
  if readable
119
- msg = readable[0].sysread 1024
124
+ msg = readable[0].readline(SEP).chomp SEP
120
125
  @serializer.load msg
121
126
  else
122
127
  raise IOError, 'The channel cannot be read from.'
@@ -129,10 +134,10 @@ class IChannel
129
134
  # Returns true when the channel is readable.
130
135
  #
131
136
  def readable?
132
- if @reader.closed?
137
+ if @reader.closed?
133
138
  false
134
139
  else
135
- readable = IO.select [@reader], nil, nil, 0.1
140
+ readable, _ = IO.select [@reader], nil, nil, 0
136
141
  !! readable
137
142
  end
138
143
  end
data/test/setup.rb CHANGED
@@ -1,4 +1,5 @@
1
- require 'ichannel'
1
+ require_relative '../lib/ichannel'
2
+
2
3
  require 'yaml'
3
4
  require 'json'
4
5
  require 'test/unit'
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: 5.0.1
4
+ version: 5.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: 2012-12-01 00:00:00.000000000 Z
12
+ date: 2013-01-01 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! "A modern and easy-to-use interprocess communication \n primitive."
15
15
  email:
@@ -18,6 +18,7 @@ executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - .gitattributes
21
22
  - .gitignore
22
23
  - .travis.yml
23
24
  - .yardopts
@@ -45,7 +46,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
45
46
  version: '0'
46
47
  segments:
47
48
  - 0
48
- hash: -1662608867092836857
49
+ hash: 2123576931550022235
49
50
  required_rubygems_version: !ruby/object:Gem::Requirement
50
51
  none: false
51
52
  requirements:
@@ -54,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
55
  version: '0'
55
56
  segments:
56
57
  - 0
57
- hash: -1662608867092836857
58
+ hash: 2123576931550022235
58
59
  requirements: []
59
60
  rubyforge_project:
60
61
  rubygems_version: 1.8.23