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