ionian 0.6.8 → 0.6.9
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 +4 -4
- data/doc/Ionian/Extension/IO.html +253 -89
- data/doc/Ionian/Extension/Socket.html +9 -9
- data/doc/Ionian/Extension.html +3 -3
- data/doc/Ionian/Server.html +3 -3
- data/doc/Ionian/Socket.html +464 -149
- data/doc/Ionian.html +3 -3
- data/doc/_index.html +4 -4
- data/doc/class_list.html +5 -1
- data/doc/file.README.html +25 -24
- data/doc/file.license.html +4 -4
- data/doc/file_list.html +5 -1
- data/doc/frames.html +1 -1
- data/doc/index.html +25 -24
- data/doc/js/full_list.js +4 -1
- data/doc/method_list.html +5 -1
- data/doc/top-level-namespace.html +3 -3
- data/lib/ionian/extension/io.rb +44 -29
- data/lib/ionian/extension/socket.rb +6 -6
- data/lib/ionian/socket.rb +79 -27
- data/license.txt +1 -1
- metadata +32 -4
data/lib/ionian/socket.rb
CHANGED
@@ -22,24 +22,55 @@ module Ionian
|
|
22
22
|
|
23
23
|
# Creates a new socket or wraps an existing socket.
|
24
24
|
#
|
25
|
-
#
|
26
|
-
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
|
25
|
+
#
|
26
|
+
# @param existing_socket [Socket] An instantiated socket to be wrapped in
|
27
|
+
# and returned as an {Ionian::Socket} (for example, TCPSocket). A new
|
28
|
+
# socket will be created if this parameter is nil.
|
29
|
+
#
|
30
|
+
#
|
31
|
+
# @param kwargs [Hash] :host is mandatory.
|
32
|
+
#
|
33
|
+
# @option kwargs [String] :host IP or hostname to connect to.
|
34
|
+
# Can contain the port in the format "host:port".
|
35
|
+
#
|
36
|
+
# @option kwargs [Fixnum] :port (23) Connection's port number. Unused by the
|
37
|
+
# :unix protocol.
|
38
|
+
#
|
39
|
+
# @option kwargs [:tcp, :udp, :unix] :protocol (:tcp) Type of socket to create.
|
40
|
+
# :udp will be automatically selected for addresses in the multicast
|
41
|
+
# range, or if the broadcast flag is set.
|
42
|
+
#
|
43
|
+
# @option kwargs [Boolean] :persistent (true) The socket remains open after
|
44
|
+
# data is sent if this is true. The socket closes after data is sent and
|
45
|
+
# a packet is received if this is false.
|
46
|
+
#
|
47
|
+
# @option kwargs [Boolean] :bind_port (:port) Local UDP port to bind to for
|
48
|
+
# receiving data, if different than the remote port being connected to.
|
49
|
+
#
|
50
|
+
# @option kwargs [Boolean] :broadcast (false) Enable the SO_BROADCAST flag.
|
51
|
+
# Sets protocol to :udp implicitly.
|
52
|
+
#
|
53
|
+
# @option kwargs [Boolean] :reuse_addr (false) Enable the SO_REUSEADDR flag.
|
54
|
+
# Allows local address reuse.
|
55
|
+
#
|
56
|
+
# @option kwargs [Boolean] :no_delay (false) Enable the TCP_NODELAY flag.
|
57
|
+
# Disables Nagle algorithm.
|
58
|
+
#
|
59
|
+
# @option kwargs [Boolean] :cork (false) Enable the TCP_CORK flag.
|
60
|
+
# Buffers multiple writes into one segment.
|
61
|
+
#
|
62
|
+
# @option kwargs [Boolean] :linger (false) Enable the SO_LINGER flag.
|
63
|
+
# When #close is called, waits for the send buffer to empty before closing
|
64
|
+
# the socket.
|
65
|
+
#
|
66
|
+
# @option kwargs [Regexp, String] :expression Overrides the
|
67
|
+
# {Ionian::Extension::IO#read_match} regular expression for received data.
|
68
|
+
#
|
69
|
+
#
|
70
|
+
# @yieldparam socket [Ionian::Socket] This socket is yielded to the block.
|
71
|
+
# Socket flushes and closes when exiting the block.
|
72
|
+
#
|
73
|
+
def initialize existing_socket = nil, **kwargs, &block
|
43
74
|
@socket = existing_socket
|
44
75
|
|
45
76
|
@ionian_listeners = []
|
@@ -67,7 +98,7 @@ module Ionian
|
|
67
98
|
@protocol = :unix
|
68
99
|
end
|
69
100
|
|
70
|
-
@persistent
|
101
|
+
@persistent = true # Existing sockets are always persistent.
|
71
102
|
|
72
103
|
@socket.expression = @expression if @expression
|
73
104
|
|
@@ -81,12 +112,15 @@ module Ionian
|
|
81
112
|
|
82
113
|
@host = host_port_ary[0]
|
83
114
|
@port = kwargs.fetch :port, host_port_ary[1].to_i || 23
|
84
|
-
@bind_port = kwargs.fetch :bind_port,
|
115
|
+
@bind_port = kwargs.fetch :bind_port, @port
|
116
|
+
|
117
|
+
@broadcast = kwargs.fetch :broadcast, false
|
85
118
|
|
86
119
|
# Automatically select UDP for the multicast range. Otherwise default to TCP.
|
87
120
|
default_protocol = :tcp
|
88
121
|
default_protocol = :udp if Ionian::Extension::Socket.multicast? @host
|
89
122
|
default_protocol = :unix if @host.start_with? '/'
|
123
|
+
default_protocol = :udp if @broadcast
|
90
124
|
|
91
125
|
@protocol = kwargs.fetch :protocol, default_protocol
|
92
126
|
@persistent = kwargs.fetch :persistent, true
|
@@ -107,6 +141,14 @@ module Ionian
|
|
107
141
|
|
108
142
|
create_socket if @persistent
|
109
143
|
end
|
144
|
+
|
145
|
+
if block
|
146
|
+
block.call self
|
147
|
+
unless self.closed?
|
148
|
+
self.flush
|
149
|
+
self.close
|
150
|
+
end
|
151
|
+
end
|
110
152
|
end
|
111
153
|
|
112
154
|
# Returns the regular expression used to match incoming data.
|
@@ -126,13 +168,18 @@ module Ionian
|
|
126
168
|
end
|
127
169
|
|
128
170
|
# Send a command (data) to the socket.
|
129
|
-
#
|
130
|
-
#
|
131
|
-
#
|
132
|
-
|
171
|
+
#
|
172
|
+
# @param [Hash] kwargs Pass through to {Ionian::Extension::IO#read_match}.
|
173
|
+
#
|
174
|
+
# @return [Array<MatchData>] An array of received matches.
|
175
|
+
#
|
176
|
+
# @yieldparam match [MatchData] Received match.
|
177
|
+
#
|
178
|
+
# @see Ionian::Extension::IO#read_match
|
179
|
+
def cmd data, **kwargs, &block
|
133
180
|
create_socket unless @persistent
|
134
181
|
|
135
|
-
write
|
182
|
+
write data
|
136
183
|
@socket.flush
|
137
184
|
|
138
185
|
matches = @socket.read_match(kwargs) { |match| yield match if block_given? }
|
@@ -241,7 +288,11 @@ module Ionian
|
|
241
288
|
@socket.extend Ionian::Extension::Socket
|
242
289
|
|
243
290
|
@socket.reuse_addr = true if
|
244
|
-
@reuse_addr or
|
291
|
+
@reuse_addr or
|
292
|
+
@broadcast or
|
293
|
+
Ionian::Extension::Socket.multicast? @host
|
294
|
+
|
295
|
+
@socket.broadcast = true if @broadcast
|
245
296
|
|
246
297
|
@socket.bind ::Socket::INADDR_ANY, @bind_port
|
247
298
|
@socket.connect @host, @port
|
@@ -254,7 +305,8 @@ module Ionian
|
|
254
305
|
|
255
306
|
end
|
256
307
|
|
257
|
-
|
308
|
+
# Windows complains at SO_LINGER, so only set it if it was specified.
|
309
|
+
@socket.linger = @linger if @linger
|
258
310
|
|
259
311
|
@socket.expression = @expression if @expression
|
260
312
|
|
data/license.txt
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ionian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex McLain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: rb-readline
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -66,6 +66,34 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 3.1.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 3.1.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-its
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.0.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.0.1
|
69
97
|
- !ruby/object:Gem::Dependency
|
70
98
|
name: fivemat
|
71
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
156
|
requirements:
|
129
157
|
- - ">="
|
130
158
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
159
|
+
version: 2.0.0
|
132
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
161
|
requirements:
|
134
162
|
- - ">="
|