Commit Graph

45 Commits

Author SHA1 Message Date
Gary Burd 2257eda00b Fix compile error on Go < 1.6 2017-01-19 11:27:08 -08:00
Gary Burd b0dc45572b Change default and add API for compression level
Change the default compression level to 1. This level is faster and uses
less memory.

Add Conn.SetCompressionLevel API to allow applications to tune
compression on a per message basis.
2017-01-19 11:00:23 -08:00
Gary Burd bb547c6c5c Improve SetXHandler documentation 2017-01-15 13:09:21 -08:00
Gary Burd adf16b3178 Add safe maskBytes
Fixes #200.
2016-12-31 20:13:41 -08:00
Gary Burd 6c51b25bc8 Compression improvements
- Remove unnecessary error return from compressNoContextTakeover.
- Simplify use of sync.Pool.
- Fix formatting in compression documentation.
2016-12-27 17:05:16 -05:00
Cyrus Katrak 2db2f66488 pool flate readers 2016-12-19 07:28:05 -08:00
Gary Burd 0868951cdb Improve WriteMessage fast path
Restructure to avoid messageWriter allocation.
2016-12-07 16:21:58 -08:00
Gary Burd 9fbf129ff2 Add Conn.[Set]CloseHandler 2016-11-02 13:04:59 -07:00
Gary Burd 80a0029a65 Improve write error handling
- Do not fail NextWriter when close of previous writer fails.
- Replace closeSent field with mutex protected writeErr. Set writeErr on
  any error writing to underlying network connection. Check and return
  writeErr before attempting to write to network connection. Check
  writeErr in NextWriter so application can detect failed connection
  before attempting to write.
- Do not close underlying network connection on error.
- Move message writing state and method flushFrame from Conn to
  messageWriter. This makes error code paths (and the code in general)
  easier to understand.
- Add messageWriter field err to latch errors in messageWriter.

Bonus: Improve test coverage.
2016-11-02 09:59:14 -07:00
Gary Burd 77f110791c Improve mask performance 2016-10-21 11:11:39 -07:00
Cyrus Katrak c09b72d2ee per message compression; only no context modes 2016-10-14 12:08:39 -07:00
Gary Burd a87eae1d6f Add hooks to support RFC 7692 (per-message compression extension)
Add newCompressionWriter and newDecompressionReader fields to Conn. When
not nil, these functions are used to create a compression/decompression
wrapper around an underlying message writer/reader.

Add code to set and check for RSV1 frame header bit.

Add functions compressNoContextTakeover and decompressNoContextTakeover
for creating no context takeover wrappers around an underlying message
writer/reader.

Work remaining:

- Add fields to Dialer and Upgrader for specifying compression options.
- Add compression negotiation to Dialer and Upgrader.
- Add function to enable/disable write compression:

    // EnableWriteCompression enables and disables write compression of
    // subsequent text and binary messages. This function is a noop if
    // compression was not negotiated with the peer.
    func (c *Conn) EnableWriteCompression(enable bool) {
            c.enableWriteCompression = enable
    }
2016-06-29 17:03:55 -07:00
Gary Burd 3ddc984058 Merge pull request #136 from reeze/add-handler-getter
Add Ping/Pong handler Getter functions
2016-05-31 22:17:19 -07:00
Reeze Xia c9ce64ea05 Add Ping/Pong handler getter methods 2016-06-01 11:26:10 +08:00
Gary Burd be01041b66 Reduce memory allocations in NextReader, NextWriter
Redo 8b209f6317 with support for old
versions of Go.
2016-05-31 05:44:45 -07:00
Gary Burd 50d660d6ac Revert "Reduce memory allocations in NextReader, NextWriter"
This reverts commit 8b209f6317.
2016-05-30 01:53:33 -07:00
Gary Burd 8b209f6317 Reduce memory allocations in NextReader, NextWriter 2016-05-26 14:07:24 -07:00
Gary Burd 1f512fc3f0 Handle invalid close frames
Send protocol error if close code or payload are invalid.

Fixes Autobahn tests 7.5.1, 7.9.*.
2016-04-28 09:34:18 -07:00
Tarmigan Casebolt ae46df13e9 Fix Read() to return errUnexpectedEOF when EOF is received before all bytes in the frame have been read 2016-04-24 22:30:05 -07:00
Gary Burd 0e2713e645 Address common gotchas with package
Update documentation to explicitly state that applications must break out of a
read loop on error.

Detect application read loops spinning on a failed connection and panic.

Detect concurrent writes and panic. The detection is best-effort.

Update documentation to state that connections respond to close frames.
2016-02-16 15:03:54 -08:00
Luca Tabone bf696496cb When sending a Close frame in response, the endpoint typically echos the status code it received. 2016-02-16 21:31:16 +01:00
Gary Burd 234959944d Add text description to close errors 2016-01-28 08:48:56 -08:00
Gary Burd 615f23bc98 Add IsUnexpectedCloseError 2016-01-19 13:06:29 -08:00
Gary Burd a2d85bcbfc Add IsCloseError, improve doc about errors 2016-01-19 09:20:21 -08:00
Gary Burd f71d4a996f Return write errors from default pong handler
Fixes issue #86.
2015-10-15 10:18:08 -07:00
Gary Burd 39cd638460 Document ping and pong handler argument
Closes #76
2015-09-15 11:02:48 -07:00
Gary Burd b6ab76f1fe Provide all close frame data to application
- Export closeError.
- Do not convert normal closure and going away to io.EOF.
2015-08-11 10:14:32 -07:00
Jie Li db3e79986d Fix typo in comment 2015-04-18 13:58:37 +08:00
Gary Burd ea78a26f80 Don't hide Timeout on errors from underying net conn. 2014-11-06 16:56:58 -08:00
Gary Burd 7d2ea39ebc Cleanup buffer size calculations. 2014-11-05 12:26:52 -08:00
Attila Oláh 6af932933a fix typo in conn.go 2014-11-03 16:48:34 +01:00
Gary Burd 47f93dfaed Improve errors.
- Use new closeError type for reporting close frames to the application.
- Use closeError with code 1006 when the peer closes connection without
  sending a close frame. The error io.ErrUnexpectedEOF was used
  previously. This change helps developers distinguish abnormal closure
  and an unexpected EOF in the JSON parser.
2014-10-31 14:52:20 -07:00
Gary Burd bda3d7d128 Fix mask key. 2014-07-23 20:32:33 -07:00
Gary Burd 10afcadf69 Cleanup EOF handling.
- Modify data message reader to return io.ErrUnexpectedEOF if a close
  message is received before the final frame of the message.
- Modify NextReader to return io.ErrUnexpectedEOF if underlying
  connection returns io.EOF before a close message.
2014-07-10 19:36:51 -07:00
Gary Burd 0e7b5f878f Do not mask bytes when reading on the client.
- The bytes were masked with zero, a nop.
- Add test for control messages.
2014-07-05 13:56:34 -07:00
Gary Burd efd7f76a14 Cleanup read operations.
- Use io.ReadFull instead of similar function in package.
- Return from Read with partial data. Don't attempt to fill buffer.
- Do not return net.Error with Temporary() == true
2014-06-06 09:48:50 -07:00
Gary Burd f4076986b6 Improve Set{Read,Write}Deadline doc.
The new doc is inspired by the crypto/tls doc.
2014-06-05 15:19:54 -07:00
Gary Burd f867cb5c72 Cleanup issues reported by golint. 2014-04-20 07:20:03 -07:00
Gary Burd 15aed3b4a4 Relicense to the Gorilla WebSocket Authors. 2014-04-18 14:25:11 -07:00
Simon Eisenmann ccad3db007 Added helper function UnderlyingConn to retrieve net.Conn from Conn objects. 2014-03-18 15:26:10 +01:00
Gary Burd 707d1f6c6b Cleanup issues reported by golint. 2013-12-23 12:08:49 -08:00
Gary Burd 67d178946a Implement net.Error on timeout errors.
Fixes #10.
2013-12-23 12:01:25 -08:00
Gary Burd b118f62ec0 Add subprotocol negotiation to Dialer. 2013-12-14 08:06:24 -08:00
Gary Burd 1627eef2a3 Improve documentation. 2013-10-27 08:34:33 -07:00
Gary Burd 273ecadfca Initial commit 2013-10-16 16:30:59 -07:00