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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 641bbc3cadfe10190a32eba8504b498fd2bbd080
4
- data.tar.gz: 715eb149abbe8e475ce89ef8556d4e05586231a7
3
+ metadata.gz: 98b9142f247f9e2022ff5626f8b0a3ab352a182d
4
+ data.tar.gz: 7bbce8c9207ecde3c9defa17e59bee69cef2b51f
5
5
  SHA512:
6
- metadata.gz: a20f7fbb5814018a5faa5b882e80d3701db747ca8b7808933a1cb707a7df2095ddf788067196ddd98ab202607b37dd2fd3c71802e11c022b8be0913b2552381d
7
- data.tar.gz: 37db65ca33059d3af8b9a2c5d06cf44e2cc7ffbc8abdb5c8dae76feebe3928bb87ab17fc28ee0512cec591e618104f362fee065d9cc082e6a33cc8466ea2d281
6
+ metadata.gz: 63e99f053868723800d97737be978438f92080b7ef80e50a0b83cea7544b940c7f53ba373a90951427a07b7f64c1fe98cbd8a7d6a4aab519b82b7253b4969e43
7
+ data.tar.gz: 7982ff410c1ca3cb3b48871c50ea52532f2bfaf25d0f5226d8e7a3d1ba11411057c4482d7cdfdcbdeff298f44407ec55571ecbcbc468b3d20c577188fe6ed613
data/.travis.yml CHANGED
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - "1.9.2"
4
- - "1.9.3"
5
- - "2.0.0"
6
- - jruby-19mode # JRuby in 1.9 mode
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - jruby-19mode
7
6
  - rbx-19mode
@@ -1,3 +1,3 @@
1
1
  class Tubesock
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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
- class HijackNotAvailable < RuntimeError
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
- @close_handlers.each(&:call)
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 !@socket.closed?
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.0
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-18 00:00:00.000000000 Z
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.2
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