| 307 | const maxCloseReason = maxControlPayload - 2 |
| 308 | |
| 309 | func (ce CloseError) bytesErr() ([]byte, error) { |
| 310 | if len(ce.Reason) > maxCloseReason { |
| 311 | return nil, fmt.Errorf("reason string max is %v but got %q with length %v", maxCloseReason, ce.Reason, len(ce.Reason)) |
| 312 | } |
| 313 | |
| 314 | if !validWireCloseCode(ce.Code) { |
| 315 | return nil, fmt.Errorf("status code %v cannot be set", ce.Code) |
| 316 | } |
| 317 | |
| 318 | buf := make([]byte, 2+len(ce.Reason)) |
| 319 | binary.BigEndian.PutUint16(buf, uint16(ce.Code)) |
| 320 | copy(buf[2:], ce.Reason) |
| 321 | return buf, nil |
| 322 | } |
| 323 | |
| 324 | func (c *Conn) casClosing() bool { |
| 325 | return c.closing.Swap(true) |