File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 5
5
"context"
6
6
"fmt"
7
7
"io"
8
+ "os"
8
9
"runtime"
9
10
"sync"
10
11
"sync/atomic"
@@ -353,6 +354,12 @@ func (c *Conn) writePong(p []byte) error {
353
354
354
355
// Close closes the WebSocket connection with the given status code and reason.
355
356
// It will write a WebSocket close frame with a timeout of 5 seconds.
357
+ // The connection can only be closed once. Additional calls to Close
358
+ // are no-ops.
359
+ // The maximum length of reason must be 125 bytes otherwise an internal
360
+ // error will be sent to the peer. For this reason, you should avoid
361
+ // sending a dynamic reason.
362
+ // Close will unblock all goroutines interacting with the connection.
356
363
func (c * Conn ) Close (code StatusCode , reason string ) error {
357
364
err := c .exportedClose (code , reason )
358
365
if err != nil {
@@ -372,17 +379,14 @@ func (c *Conn) exportedClose(code StatusCode, reason string) error {
372
379
// Definitely worth seeing what popular browsers do later.
373
380
p , err := ce .bytes ()
374
381
if err != nil {
382
+ fmt .Fprintf (os .Stderr , "failed to marshal close frame: %v\n " , err )
375
383
ce = CloseError {
376
384
Code : StatusInternalError ,
377
385
}
378
386
p , _ = ce .bytes ()
379
387
}
380
388
381
- cerr := c .writeClose (p , ce )
382
- if err != nil {
383
- return err
384
- }
385
- return cerr
389
+ return c .writeClose (p , ce )
386
390
}
387
391
388
392
func (c * Conn ) writeClose (p []byte , cerr CloseError ) error {
You can’t perform that action at this time.
0 commit comments