ws_client 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ws_client.rb +3 -46
- data/lib/ws_client/version.rb +1 -1
- data/ws_client.gemspec +0 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2d53418c6bbb54f0c051e616d3256a5fe5e9bce
|
4
|
+
data.tar.gz: 6af2067a5ce411a5c65c7349505dae6ff02f7a4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e079fd73f3b812caf77c2ce22f7998ffa4d450ba5c3428b1e65beda2ebf8047eeedae590bae681609627280aed7725f30a075ecb07a5917382387f79efa94113
|
7
|
+
data.tar.gz: 77b177a3c60dde80db51f4719db75614b6b31fc8f5c3a55ef113c0b956c08cd8dfc13ecc1d38e94df0d5f8ad21b2732935ea51f3c3f44119a811f5da63926224
|
data/lib/ws_client.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'thread'
|
2
|
-
require 'event_emitter'
|
3
2
|
require 'websocket'
|
4
3
|
require 'socket'
|
5
4
|
require 'openssl'
|
@@ -15,7 +14,6 @@ module WsClient
|
|
15
14
|
end
|
16
15
|
|
17
16
|
class Client
|
18
|
-
include EventEmitter
|
19
17
|
attr_reader :url, :handshake, :message_queue, :connect_options
|
20
18
|
|
21
19
|
MS_2 = (1/500.0)
|
@@ -54,13 +52,11 @@ module WsClient
|
|
54
52
|
@socket.connect
|
55
53
|
end
|
56
54
|
|
57
|
-
@pipe_broken = false
|
58
55
|
@closed = false
|
59
56
|
|
60
57
|
handshake
|
61
58
|
rescue OpenSSL::SSL::SSLError, EOFError
|
62
59
|
# Re-use the socket cleanup logic if we have a connect failure.
|
63
|
-
@pipe_broken = true
|
64
60
|
close
|
65
61
|
raise
|
66
62
|
end
|
@@ -88,8 +84,7 @@ module WsClient
|
|
88
84
|
def close
|
89
85
|
return if @closed
|
90
86
|
|
91
|
-
write_data nil, :type => :close
|
92
|
-
emit :close
|
87
|
+
write_data nil, :type => :close rescue nil
|
93
88
|
ensure
|
94
89
|
@closed = true
|
95
90
|
@socket.close if @socket
|
@@ -133,8 +128,6 @@ module WsClient
|
|
133
128
|
retry
|
134
129
|
end
|
135
130
|
end
|
136
|
-
|
137
|
-
emit :open if @handshaked
|
138
131
|
end
|
139
132
|
|
140
133
|
def pull_next_message_off_of_socket(socket, timeout = 10, last_frame = nil)
|
@@ -170,7 +163,7 @@ module WsClient
|
|
170
163
|
retry
|
171
164
|
rescue => e
|
172
165
|
close
|
173
|
-
|
166
|
+
raise
|
174
167
|
end
|
175
168
|
end
|
176
169
|
end
|
@@ -191,45 +184,9 @@ module WsClient
|
|
191
184
|
rescue IO::WaitWritable, Errno::EINTR
|
192
185
|
IO.select(nil, [@socket])
|
193
186
|
retry
|
194
|
-
rescue Errno::EPIPE => e
|
195
|
-
@pipe_broken = true
|
196
|
-
close
|
197
187
|
rescue => e
|
198
188
|
close
|
199
|
-
|
200
|
-
end
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
class AsyncClient < ::WsClient::Client
|
206
|
-
def close
|
207
|
-
return if @closed
|
208
|
-
|
209
|
-
write_data nil, :type => :close if !@pipe_broken
|
210
|
-
emit :close
|
211
|
-
ensure
|
212
|
-
@closed = true
|
213
|
-
@socket.close if @socket
|
214
|
-
@tcp_socket.close if @tcp_socket
|
215
|
-
@socket = nil
|
216
|
-
@tcp_socket = nil
|
217
|
-
Thread.kill @thread if @thread
|
218
|
-
end
|
219
|
-
|
220
|
-
def send_data(data, opt={:type => :text})
|
221
|
-
@thread ||= poll # utilize the polling interface, could probably be split into another class
|
222
|
-
write_data(data, opt)
|
223
|
-
end
|
224
|
-
|
225
|
-
def poll
|
226
|
-
return Thread.new(@socket) do |socket|
|
227
|
-
while !@closed do
|
228
|
-
pull_next_message_off_of_socket(socket)
|
229
|
-
|
230
|
-
message_queue.length.times do
|
231
|
-
emit :message, message_queue.pop
|
232
|
-
end
|
189
|
+
raise
|
233
190
|
end
|
234
191
|
end
|
235
192
|
end
|
data/lib/ws_client/version.rb
CHANGED
data/ws_client.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ws_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Dewitt
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-10-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -81,20 +81,6 @@ dependencies:
|
|
81
81
|
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: event_emitter
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - ">="
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '0'
|
91
|
-
type: :runtime
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - ">="
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '0'
|
98
84
|
description: " Simple websocket client in ruby "
|
99
85
|
email:
|
100
86
|
- brandonsdewitt+rubygems@gmail.com
|