ping: Add timeout to destinations

This commit is contained in:
世界 2025-08-24 17:46:03 +08:00
parent 8f6cc9f62e
commit 737ebf01c4
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
6 changed files with 81 additions and 19 deletions

View file

@ -29,6 +29,7 @@ type Conn struct {
conn net.Conn
destination netip.Addr
source atomic.TypedValue[netip.Addr]
closed atomic.Bool
}
func Connect(ctx context.Context, logger logger.ContextLogger, privileged bool, controlFunc control.Func, destination netip.Addr) (*Conn, error) {
@ -230,5 +231,10 @@ func (c *Conn) SetReadDeadline(t time.Time) error {
}
func (c *Conn) Close() error {
defer c.closed.Store(true)
return c.conn.Close()
}
func (c *Conn) IsClosed() bool {
return c.closed.Load()
}