websocket 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.0.3
4
+
5
+ - improve pure ruby implementation performance by ~30%
6
+ - add support for native extension
7
+
3
8
  ## 1.0.2
4
9
 
5
10
  - allow configuration of max frame size via WebSocket.max_frame_size option
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # WebSocket Ruby
2
2
 
3
- - Travis CI build: [![](http://travis-ci.org/imanel/websocket-ruby.png)](http://travis-ci.org/imanel/websocket-ruby)
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)
@@ -1,10 +1,15 @@
1
1
  {
2
- "options": {"failByDrop": false},
3
- "outdir": "./autobahn/server",
2
+ "options": {"failByDrop": false},
3
+ "outdir": "./autobahn/server",
4
4
 
5
- "servers": [{"agent": "WebSocket-Ruby v1.0.2", "url": "ws://localhost:9001", "options": {"version": 18}}],
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
- "cases": ["*"],
8
- "exclude-cases": [],
9
- "exclude-agent-cases": {}
12
+ "cases": ["*"],
13
+ "exclude-cases": [],
14
+ "exclude-agent-cases": {}
10
15
  }
@@ -25,3 +25,9 @@ module WebSocket
25
25
  end
26
26
 
27
27
  end
28
+
29
+ # Try loading websocket-native if available
30
+ begin
31
+ require "websocket-native"
32
+ rescue LoadError
33
+ end
@@ -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 = Data.new(self[0..3])
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.force_encoding('ASCII-8BIT') if data.respond_to?(:force_encoding)
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 getbyte_with_masking(index)
39
- if @masking_key
40
- masked_char = getbyte_without_masking(index)
41
- masked_char ? masked_char ^ @masking_key.getbyte(index % 4) : nil
42
- else
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
@@ -1,3 +1,3 @@
1
1
  module WebSocket
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
@@ -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('valid_incoming_frame') unless RUBY_PLATFORM == "java"
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('valid_incoming_frame') unless RUBY_PLATFORM == "java"
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('valid_incoming_frame') unless RUBY_PLATFORM == "java"
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('valid_incoming_frame') unless RUBY_PLATFORM == "java"
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('valid_incoming_frame') unless RUBY_PLATFORM == "java"
56
+ it_should_behave_like 'valid_incoming_frame'
57
57
  end
58
58
 
59
59
  end
@@ -2,3 +2,9 @@ require 'rspec'
2
2
 
3
3
  require 'websocket'
4
4
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
5
+
6
+ RSpec.configure do |config|
7
+ config.before(:suite) do
8
+ WebSocket.max_frame_size = 100 * 1024 # 100kb
9
+ end
10
+ end
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.2
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-18 00:00:00.000000000 Z
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: 221385565863631789
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: 221385565863631789
133
+ hash: 159948745568353421
134
134
  requirements: []
135
135
  rubyforge_project:
136
136
  rubygems_version: 1.8.24