close stops the recvLoop.
()
| 374 | |
| 375 | // close stops the recvLoop. |
| 376 | func (c *candidateBase) close() error { |
| 377 | // If conn has never been started will be nil |
| 378 | if c.Done() == nil { |
| 379 | return nil |
| 380 | } |
| 381 | |
| 382 | // Assert that conn has not already been closed |
| 383 | select { |
| 384 | case <-c.Done(): |
| 385 | return nil |
| 386 | default: |
| 387 | } |
| 388 | |
| 389 | var firstErr error |
| 390 | |
| 391 | // Unblock recvLoop |
| 392 | close(c.closeCh) |
| 393 | if err := c.conn.SetDeadline(time.Now()); err != nil { |
| 394 | firstErr = err |
| 395 | } |
| 396 | |
| 397 | // Close the conn |
| 398 | if err := c.conn.Close(); err != nil && firstErr == nil { |
| 399 | firstErr = err |
| 400 | } |
| 401 | |
| 402 | if firstErr != nil { |
| 403 | return firstErr |
| 404 | } |
| 405 | |
| 406 | // Wait until the recvLoop is closed |
| 407 | <-c.closedCh |
| 408 | |
| 409 | return nil |
| 410 | } |
| 411 | |
| 412 | func (c *candidateBase) writeTo(raw []byte, dst Candidate) (int, error) { |
| 413 | n, err := c.conn.WriteTo(raw, dst.addr()) |
nothing calls this directly
no test coverage detected