websocket 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/README.md +7 -1
- data/autobahn-server.json +11 -6
- data/lib/websocket.rb +6 -0
- data/lib/websocket/frame/data.rb +9 -15
- data/lib/websocket/version.rb +1 -1
- data/spec/frame/incoming_03_spec.rb +1 -1
- data/spec/frame/incoming_04_spec.rb +1 -1
- data/spec/frame/incoming_05_spec.rb +1 -1
- data/spec/frame/incoming_07_spec.rb +1 -1
- data/spec/frame/incoming_75_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -0
- metadata +4 -4
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# WebSocket Ruby
|
2
2
|
|
3
|
-
- Travis CI build: [![](
|
3
|
+
- Travis CI build: [![](https://travis-ci.org/imanel/websocket-ruby.png)](http://travis-ci.org/imanel/websocket-ruby)
|
4
4
|
- Autobahn tests: [server](http://imanel.github.com/websocket-ruby/autobahn/server/), client
|
5
5
|
|
6
6
|
Universal Ruby library to handle WebSocket protocol. It foucses on providing abstraction layer over [WebSocket API](http://dev.w3.org/html5/websockets/) instead of providing server or client functionality.
|
@@ -104,6 +104,12 @@ frame.next # "world!""
|
|
104
104
|
|
105
105
|
For examples on how to use WebSocket Ruby see examples directory in the repository. Provided examples are fully working servers - they are passing full autobahn compatibility suit.
|
106
106
|
|
107
|
+
## Native extension
|
108
|
+
|
109
|
+
WebSocket gem is written in pure Ruby, without any dependencies or native extensions and still is one of the fastest implementations of WebSocket API. However, if you want to increase it's speed even further, I created additional gem with dedicated native extensions for both C and Java. Those extensions provide 20-30% increate in speed(more accurate comparision can be found in autobahn test results)
|
110
|
+
|
111
|
+
In order to use native extension just install [websocket-native](http://github.com/imanel/websocket-ruby-native) gem or add it to Gemfile - WebSocket will automatically detect and load it.
|
112
|
+
|
107
113
|
## License
|
108
114
|
|
109
115
|
(The MIT License)
|
data/autobahn-server.json
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
{
|
2
|
-
|
3
|
-
|
2
|
+
"options": {"failByDrop": false},
|
3
|
+
"outdir": "./autobahn/server",
|
4
4
|
|
5
|
-
|
5
|
+
"servers": [
|
6
|
+
{"agent": "WebSocket-Ruby<br>(1.0.3 Pure)", "url": "ws://localhost:9001", "options": {"version": 18}},
|
7
|
+
{"agent": "WebSocket-Ruby<br>(1.0.3 Native)", "url": "ws://localhost:9002", "options": {"version": 18}},
|
8
|
+
{"agent": "Faye-WebSocket<br>(0.4.6 Thin)", "url": "ws://localhost:7000", "options": {"version": 18}},
|
9
|
+
{"agent": "EM-WebSocket<br>(0.3.8)", "url": "ws://localhost:8080", "options": {"version": 18}}
|
10
|
+
],
|
6
11
|
|
7
|
-
|
8
|
-
|
9
|
-
|
12
|
+
"cases": ["*"],
|
13
|
+
"exclude-cases": [],
|
14
|
+
"exclude-agent-cases": {}
|
10
15
|
}
|
data/lib/websocket.rb
CHANGED
data/lib/websocket/frame/data.rb
CHANGED
@@ -12,7 +12,7 @@ module WebSocket
|
|
12
12
|
|
13
13
|
def set_mask
|
14
14
|
raise "Too short" if bytesize < 4 # TODO - change
|
15
|
-
@masking_key =
|
15
|
+
@masking_key = self[0..3].bytes.to_a
|
16
16
|
end
|
17
17
|
|
18
18
|
def unset_mask
|
@@ -20,11 +20,8 @@ module WebSocket
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def getbytes(start_index, count)
|
23
|
-
data =
|
24
|
-
data.
|
25
|
-
count.times do |i|
|
26
|
-
data << getbyte(start_index + i)
|
27
|
-
end
|
23
|
+
data = self[start_index, count]
|
24
|
+
data = mask(data.bytes.to_a, @masking_key).pack('C*') if @masking_key
|
28
25
|
data
|
29
26
|
end
|
30
27
|
|
@@ -35,18 +32,15 @@ module WebSocket
|
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
38
|
-
def
|
39
|
-
if
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
getbyte_without_masking(index)
|
35
|
+
def mask(payload, mask)
|
36
|
+
return mask_native(payload, mask) if respond_to?(:mask_native)
|
37
|
+
result = []
|
38
|
+
payload.each_with_index do |byte, i|
|
39
|
+
result[i] = byte ^ mask[i % 4]
|
44
40
|
end
|
41
|
+
result
|
45
42
|
end
|
46
43
|
|
47
|
-
alias_method :getbyte_without_masking, :getbyte
|
48
|
-
alias_method :getbyte, :getbyte_with_masking
|
49
|
-
|
50
44
|
end
|
51
45
|
end
|
52
46
|
end
|
data/lib/websocket/version.rb
CHANGED
@@ -103,7 +103,7 @@ describe 'Incoming frame draft 03' do
|
|
103
103
|
let(:decoded_text) { nil }
|
104
104
|
let(:error) { :frame_too_long }
|
105
105
|
|
106
|
-
it_should_behave_like
|
106
|
+
it_should_behave_like 'valid_incoming_frame'
|
107
107
|
end
|
108
108
|
|
109
109
|
context "should raise error with continuation frame without more frame earlier" do
|
@@ -103,7 +103,7 @@ describe 'Incoming frame draft 04' do
|
|
103
103
|
let(:decoded_text) { nil }
|
104
104
|
let(:error) { :frame_too_long }
|
105
105
|
|
106
|
-
it_should_behave_like
|
106
|
+
it_should_behave_like 'valid_incoming_frame'
|
107
107
|
end
|
108
108
|
|
109
109
|
context "should raise error with continuation frame without more frame earlier" do
|
@@ -119,7 +119,7 @@ describe 'Incoming frame draft 05' do
|
|
119
119
|
let(:decoded_text) { nil }
|
120
120
|
let(:error) { :frame_too_long }
|
121
121
|
|
122
|
-
it_should_behave_like
|
122
|
+
it_should_behave_like 'valid_incoming_frame'
|
123
123
|
end
|
124
124
|
|
125
125
|
context "should raise error with continuation frame without more frame earlier" do
|
@@ -119,7 +119,7 @@ describe 'Incoming frame draft 07' do
|
|
119
119
|
let(:decoded_text) { nil }
|
120
120
|
let(:error) { :frame_too_long }
|
121
121
|
|
122
|
-
it_should_behave_like
|
122
|
+
it_should_behave_like 'valid_incoming_frame'
|
123
123
|
end
|
124
124
|
|
125
125
|
context "should raise error with continuation frame without more frame earlier" do
|
@@ -53,7 +53,7 @@ describe 'Incoming frame draft 75' do
|
|
53
53
|
let(:encoded_text) { "\x00" + "a" * WebSocket.max_frame_size + "\xFF" }
|
54
54
|
let(:error) { :frame_too_long }
|
55
55
|
|
56
|
-
it_should_behave_like
|
56
|
+
it_should_behave_like 'valid_incoming_frame'
|
57
57
|
end
|
58
58
|
|
59
59
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: websocket
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
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-11-
|
12
|
+
date: 2012-11-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -121,7 +121,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
121
|
version: '0'
|
122
122
|
segments:
|
123
123
|
- 0
|
124
|
-
hash:
|
124
|
+
hash: 159948745568353421
|
125
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
126
126
|
none: false
|
127
127
|
requirements:
|
@@ -130,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
segments:
|
132
132
|
- 0
|
133
|
-
hash:
|
133
|
+
hash: 159948745568353421
|
134
134
|
requirements: []
|
135
135
|
rubyforge_project:
|
136
136
|
rubygems_version: 1.8.24
|