(ctx context.Context, p string)
| 231 | } |
| 232 | |
| 233 | func (c *Conn) ping(ctx context.Context, p string) error { |
| 234 | pong := make(chan struct{}, 1) |
| 235 | |
| 236 | c.activePingsMu.Lock() |
| 237 | c.activePings[p] = pong |
| 238 | c.activePingsMu.Unlock() |
| 239 | |
| 240 | defer func() { |
| 241 | c.activePingsMu.Lock() |
| 242 | delete(c.activePings, p) |
| 243 | c.activePingsMu.Unlock() |
| 244 | }() |
| 245 | |
| 246 | err := c.writeControl(ctx, opPing, []byte(p)) |
| 247 | if err != nil { |
| 248 | return err |
| 249 | } |
| 250 | |
| 251 | select { |
| 252 | case <-c.closed: |
| 253 | return net.ErrClosed |
| 254 | case <-ctx.Done(): |
| 255 | return fmt.Errorf("failed to wait for pong: %w", ctx.Err()) |
| 256 | case <-pong: |
| 257 | return nil |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | type mu struct { |
| 262 | c *Conn |
no test coverage detected