(code StatusCode, reason string)
| 168 | } |
| 169 | |
| 170 | func (c *Conn) writeClose(code StatusCode, reason string) error { |
| 171 | ce := CloseError{ |
| 172 | Code: code, |
| 173 | Reason: reason, |
| 174 | } |
| 175 | |
| 176 | var p []byte |
| 177 | var err error |
| 178 | if ce.Code != StatusNoStatusRcvd { |
| 179 | p, err = ce.bytes() |
| 180 | if err != nil { |
| 181 | return err |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) |
| 186 | defer cancel() |
| 187 | |
| 188 | err = c.writeControl(ctx, opClose, p) |
| 189 | // If the connection closed as we're writing we ignore the error as we might |
| 190 | // have written the close frame, the peer responded and then someone else read it |
| 191 | // and closed the connection. |
| 192 | if err != nil && !errors.Is(err, net.ErrClosed) { |
| 193 | return err |
| 194 | } |
| 195 | return nil |
| 196 | } |
| 197 | |
| 198 | func (c *Conn) waitCloseHandshake() error { |
| 199 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) |
no test coverage detected