Permalink
Browse files

Serialise the FIN and RSV bits of frames correctly.

  • Loading branch information...
1 parent eb20069 commit ef862fd3413d345ab2a3322c7fd10cfb93b9f76b @jcoglan jcoglan committed Dec 5, 2014
Showing with 8 additions and 1 deletion.
  1. +2 −0 examples/tcp_server.rb
  2. +6 −1 lib/websocket/driver/hybi.rb
@@ -2,10 +2,12 @@
require 'bundler/setup'
require 'eventmachine'
require 'websocket/driver'
+require 'permessage_deflate'
module Connection
def initialize
@driver = WebSocket::Driver.server(self)
+ @driver.add_extension(PermessageDeflate)
@driver.on(:connect) { |e| @driver.start if WebSocket::Driver.websocket? @driver.env }
@driver.on(:message) { |e| @driver.frame(e.data) }
@@ -196,9 +196,14 @@ def send_frame(frame, run_extensions = false)
length = frame.length
header = (length <= 125) ? 2 : (length <= 65535 ? 4 : 10)
offset = header + (frame.masked ? 4 : 0)
+ buffer = []
masked = frame.masked ? MASK : 0
- buffer = [FIN | frame.opcode]
+ buffer[0] = (frame.final ? FIN : 0) |
+ (frame.rsv1 ? RSV1 : 0) |
+ (frame.rsv2 ? RSV2 : 0) |
+ (frame.rsv3 ? RSV3 : 0) |
+ frame.opcode
if length <= 125
buffer[1] = masked | length

0 comments on commit ef862fd

Please sign in to comment.