Documentation
¶
Overview ¶
Package netconn provides connection deadlines, keepalive, and address helpers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyTCPKeepAlive ¶
ApplyTCPKeepAlive enables SO_KEEPALIVE on a freshly accepted control connection and sets the idle period before probes begin. A non-positive period disables keepalive. Connections that are not *net.TCPConn (e.g. test fakes) are left untouched.
func HostFromAddr ¶
HostFromAddr returns the host portion of a "host:port" address string, without the port. It returns the input unchanged when it carries no port and "" for an empty input. It backs both RemoteIP (net.Addr) and the HTTP endpoint's client-IP extraction from http.Request.RemoteAddr.
Types ¶
type ExpiringListener ¶ added in v1.0.53
ExpiringListener closes its listener after a fixed lifetime and invokes its on-close callback exactly once. Each timer owns only its own listener.
func NewExpiringListener ¶ added in v1.0.53
func NewExpiringListener(ln net.Listener, lifetime time.Duration, onClose func()) *ExpiringListener
NewExpiringListener starts the lifetime immediately. onClose must be non-nil and is called after the underlying listener closes, even if Close fails.
func (*ExpiringListener) Close ¶ added in v1.0.53
func (l *ExpiringListener) Close() error
Close stops expiration, closes the listener, and calls onClose once.
func (*ExpiringListener) Deadline ¶ added in v1.0.53
func (l *ExpiringListener) Deadline() time.Time
Deadline returns the fixed expiration time established at construction.
func (*ExpiringListener) SetDeadline ¶ added in v1.0.53
func (l *ExpiringListener) SetDeadline(deadline time.Time) error
SetDeadline forwards an accept deadline when the underlying listener supports it. It does not change the fixed expiration time returned by Deadline.
type IdleConn ¶
IdleConn wraps a net.Conn and resets the read and/or write deadlines before each Read/Write so that a connection is closed when no data has moved in the configured direction within the configured idle timeout. A timeout of zero in either direction disables the corresponding deadline; the two directions are independent so callers can apply an idle deadline only on the side they actually use.
func (*IdleConn) SetReadTimeout ¶
SetReadTimeout configures the per-Read idle deadline. A zero or negative value disables it.
func (*IdleConn) SetWriteTimeout ¶
SetWriteTimeout configures the per-Write idle deadline. A zero or negative value disables it.