Commit Graph

202 Commits

Author SHA1 Message Date
James Coglan 6ef3c9cbb8 Rewrite the Ruby StreamReader class to use the same algorithm as the C/Java version. This radically reduces the amount of allocation Ruby has to do as it generates fewer new string objects. 2017-03-14 21:19:57 +00:00
James Coglan f95895f729 Check for hitting the max message size and max read buffer capacity without using additions that could overflow. 2017-03-07 09:42:23 +00:00
James Coglan 4564736fde Bring close frame handling into line between parser implementations. 2017-03-06 21:12:27 +00:00
James Coglan 2a0ebd9844 Remove an autoload for a nonexistent module. 2017-03-04 12:42:16 +00:00
James Coglan 866aee9319 Add a 'native' option for opting in to using the native parser and unparser. 2017-03-03 22:21:38 +00:00
James Coglan 79134ffade Adjust formatting in construction of first byte in Unparser. 2017-03-01 09:11:53 +00:00
James Coglan 000f0b81fc Due to JRuby's limitation of only accepting 3 arguments on @JRubyMethod methods, we need to pack a few of the arguments to Unparser#frame() into an array. 2017-03-01 00:44:39 +00:00
James Coglan 17749524ec Silence warnings emitted under -W2. 2017-01-11 22:37:52 +00:00
James Coglan 60e4027c59 Extract the parsing/unparsing code from Hybi into Ruby classes that match the C API, drop the Native driver and allow Hybi to take options for which parsers to use. 2017-01-06 09:11:37 +00:00
James Coglan 914dadb973 Port the frame serializer to C. 2017-01-05 21:38:26 +00:00
James Coglan ede6490add Refer to error messages as 'reasons' so as not to confuse them with WebSocket message structs. 2016-12-31 15:48:47 +00:00
James Coglan cee5700a02 Catch errors with close frames with invalid UTF-8. 2016-12-29 02:10:51 +00:00
James Coglan 97b497a520 Drop the old native extension and replace it with the new all-C parser. Replace the old masking code with a Ruby version, so that the Hybi class is pure Ruby. 2016-12-29 01:09:12 +00:00
James Coglan 0eb64913ca Capture errors raise by emit() and re-raise them after the parser has finished running. 2016-12-29 00:56:55 +00:00
James Coglan 524aa3f356 Add handling of close frames. 2016-12-29 00:34:36 +00:00
James Coglan 8eaae3a149 Implement hooks for ping/pong. 2016-12-28 18:04:27 +00:00
James Coglan 78c5aea489 Check for valid UTF-8 after the message has gone through extensions, e.g. a deflate-encoded payload will not be valid UTF-8. 2016-12-28 16:35:45 +00:00
James Coglan 721644495b Implement the require_masking flag properly. 2016-12-28 16:14:52 +00:00
James Coglan ae62fc6322 Begin emitting native parser errors back to the driver, starting by handling invalid opcodes. 2016-12-28 15:25:44 +00:00
James Coglan 4e747733a3 Begin wiring the C parser up to a Ruby driver. Driver::Native is currently a hollowed-out copy of Driver::Hybi with the parsing code removed. 2016-12-27 12:26:59 +00:00
James Coglan 9ce857b3d4 Revise uses of encoding APIs.
When originally implemented, we still supported Ruby 1.8, which
necessitated checking for encoding methods and using a regex to validate
UTF-8. These checks are now gone.

We tagged many strings as binary when not strictly necessary, either
because we were just going to iterate their bytes or because we were
going to hand them off to the caller which should just write them
directly to a socket. Strings used as buffers to accumulate streaming
input are still tagged as binary to avoid encoding
collision/conversion.

The places where we do need to tag as UTF-8 (i.e. just before emitting
to the application) remain, but copy the string if necessary. This
allows us to work with frozen strings.

Finally, strings passed in via the Driver#text method should be
*transcoded* to UTF-8 if necessary, not merely tagged. The Ruby
String#encode method produces a new string so this should also be safe
with frozen strings.
2016-05-19 21:08:22 +01:00
James Coglan 115d82bebb Silence all -W2 warnings. 2016-05-18 22:42:16 +01:00
James Coglan 15ba7410c6 Remove some unused variables from Hybi#send_frame. 2016-05-18 22:33:33 +01:00
James Coglan 4ae198b1d3 Throw a more helpful error if a client driver is created with an invalid URL. 2015-10-17 21:37:13 +01:00
James Coglan c63220194c Close the connection if a draft-76 client sends a Sec-WebSocket-Key header where the numeric value is a non-integer multiple of the number of spaces. 2015-10-02 21:32:35 +01:00
Akira Matsuda 5ce5c98339 "warning: instance variable @delegate not initialized" 2015-07-21 16:41:50 +09:00
James Coglan bc7d29cb52 Emit a protocol error when a closing frame has a 1-byte payload. 2015-07-17 22:02:51 +01:00
James Coglan 59940290c9 Emit close code 1000 if the closing frame does not contain one. 2015-07-16 08:19:05 +01:00
James Coglan be2e5ed9ce A few stylistic tweaks. 2015-07-11 14:24:19 +01:00
James Coglan d4245ed3f4 Rather than implementing integer (un)packing ourselves, use the Array#pack and String#unpack methods. 2015-07-10 20:05:19 +01:00
James Coglan 7128d1b030 Standardise the words used to refer to chunks of parser input. 2015-07-10 09:37:03 +01:00
James Coglan 75fe55eaba Adjust how on() calls add_listener(). This is necessary because faye-websocket overrides add_listener with one argument, so users with faye-websocket locked at < 0.10 will see errors. 2015-07-10 09:22:16 +01:00
James Coglan f1fd96e093 Emit an error event *after* setting the ready state to 3. 2015-07-08 20:13:50 +01:00
James Coglan fed81a5a88 Small format changes to StreamReader. 2015-07-07 21:24:13 +01:00
James Coglan 91653036ce Parse the mask flag and length in the order they appear in the protocol. 2015-07-07 20:49:29 +01:00
James Coglan e39fa15c07 Revert variable names in Draft75#parse to what they were in 0.5. 2015-07-07 20:45:55 +01:00
James Coglan 50ca31b4c8 Remove empty Driver#shutdown method. 2015-07-07 20:40:53 +01:00
James Coglan 9523937428 Initialize StreamReader in the base constructor. 2015-07-07 20:38:26 +01:00
James Coglan 91df761990 Hybi#shutdown doesn't really need to take a block, it can just take a flag to say whether to emit an error. 2015-07-07 20:33:22 +01:00
James Coglan dcfd35fde8 Remove some excessive whitespace. 2015-07-07 20:32:47 +01:00
James Coglan 582a3b0541 Merge pull request #29 from ioquatix/buffered-input
Use StreamReader for both hybi and draft75.
2015-07-06 20:49:24 +01:00
James Coglan fe6163c336 Perform state changes in #shutdown before calling frame(), which might fail when calling @socket.write. 2015-07-06 20:50:18 +01:00
James Coglan 9b561b6e12 The 'rescue' clause for errors from outgoing extensions should be in #frame, not #send_frame. 2015-07-06 20:48:44 +01:00
Samuel Williams 425e15da83 Use StreamReader for both hybi and draft75. 2015-07-06 10:29:18 +09:00
James Coglan fa11841bfa Don't catch errors from event listeners. Instead, make sure that in all parsing methods in Hybi, @stage is set before any user called is invoked so the parser is in the right state before code that might raise is called. 2015-07-05 18:52:53 +01:00
James Coglan f11d5905d2 Merge pull request #28 from ioquatix/strem-reader-refactoring
Improve performance of StreamReader by reducing the number of buffer reallocations done.
2015-07-05 16:26:32 +01:00
James Coglan 83d317add2 Rescue from Exception when calling event listeners, and use the name 'error' for caught exceptions. 2015-07-05 15:31:36 +01:00
Samuel Williams 46f5ac8c6b Improve performance of StreamReader by reducing the number of buffer reallocations done. 2015-07-05 23:24:35 +09:00
James Coglan 585eded63d Remove unnecessary code to remove whitespace from Base64 output. 2015-07-04 21:13:06 +01:00
James Coglan 8eccf044b0 Change stage in the Base.shutdown() method to that all parsers stop processing input. 2015-07-04 21:06:50 +01:00