MCPcopy
hub / github.com/coder/websocket / ping

Method ping

conn.go:233–259  ·  view source on GitHub ↗
(ctx context.Context, p string)

Source from the content-addressed store, hash-verified

231}
232
233func (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
261type mu struct {
262 c *Conn

Callers 1

PingMethod · 0.95

Calls 2

writeControlMethod · 0.95
LockMethod · 0.45

Tested by

no test coverage detected