tubesock 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -4
- data/lib/tubesock/version.rb +1 -1
- data/lib/tubesock.rb +25 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98b9142f247f9e2022ff5626f8b0a3ab352a182d
|
4
|
+
data.tar.gz: 7bbce8c9207ecde3c9defa17e59bee69cef2b51f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 63e99f053868723800d97737be978438f92080b7ef80e50a0b83cea7544b940c7f53ba373a90951427a07b7f64c1fe98cbd8a7d6a4aab519b82b7253b4969e43
|
7
|
+
data.tar.gz: 7982ff410c1ca3cb3b48871c50ea52532f2bfaf25d0f5226d8e7a3d1ba11411057c4482d7cdfdcbdeff298f44407ec55571ecbcbc468b3d20c577188fe6ed613
|
data/.travis.yml
CHANGED
data/lib/tubesock/version.rb
CHANGED
data/lib/tubesock.rb
CHANGED
@@ -5,8 +5,7 @@ require "websocket"
|
|
5
5
|
# Easily interact with WebSocket connections over Rack.
|
6
6
|
# TODO: Example with pure Rack
|
7
7
|
class Tubesock
|
8
|
-
|
9
|
-
end
|
8
|
+
HijackNotAvailable = Class.new RuntimeError
|
10
9
|
|
11
10
|
def initialize(socket, version)
|
12
11
|
@socket = socket
|
@@ -57,21 +56,40 @@ class Tubesock
|
|
57
56
|
end
|
58
57
|
|
59
58
|
def listen
|
59
|
+
keepalive
|
60
60
|
Thread.new do
|
61
61
|
Thread.current.abort_on_exception = true
|
62
62
|
@open_handlers.each(&:call)
|
63
63
|
each_frame do |data|
|
64
64
|
@message_handlers.each{|h| h.call(data) }
|
65
65
|
end
|
66
|
-
|
67
|
-
@socket.close
|
66
|
+
close
|
68
67
|
end
|
69
68
|
end
|
70
69
|
|
70
|
+
def close
|
71
|
+
@close_handlers.each(&:call)
|
72
|
+
@socket.close unless @socket.closed?
|
73
|
+
end
|
74
|
+
|
75
|
+
def keepalive
|
76
|
+
Thread.new do
|
77
|
+
Thread.current.abort_on_exception = true
|
78
|
+
loop do
|
79
|
+
sleep 5
|
80
|
+
ping
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def ping
|
86
|
+
send_data "tubesock-ping", :ping
|
87
|
+
end
|
88
|
+
|
71
89
|
private
|
72
90
|
def each_frame
|
73
91
|
framebuffer = WebSocket::Frame::Incoming::Server.new(version: @version)
|
74
|
-
while
|
92
|
+
while IO.select([@socket])
|
75
93
|
data, addrinfo = @socket.recvfrom(2000)
|
76
94
|
break if data.empty?
|
77
95
|
framebuffer << data
|
@@ -80,5 +98,7 @@ class Tubesock
|
|
80
98
|
yield frame.data
|
81
99
|
end
|
82
100
|
end
|
101
|
+
rescue Errno::ECONNRESET
|
102
|
+
nil # client disconnected
|
83
103
|
end
|
84
104
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tubesock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Gauthier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
147
|
version: '0'
|
148
148
|
requirements: []
|
149
149
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.0.
|
150
|
+
rubygems_version: 2.0.3
|
151
151
|
signing_key:
|
152
152
|
specification_version: 4
|
153
153
|
summary: Handle websocket connections via Rack and Rails 4 using concurrency
|