netconn

package
v1.0.73 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

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

func ApplyTCPKeepAlive(nc net.Conn, period time.Duration)

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

func HostFromAddr(addr string) string

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.

func RemoteIP

func RemoteIP(addr net.Addr) string

RemoteIP extracts the IP portion of a net.Addr. If the address contains a host:port pair (as is the case for TCP) only the host is returned; otherwise the full string form of the address is returned. Returns "" for a nil addr.

Types

type ExpiringListener added in v1.0.53

type ExpiringListener struct {
	net.Listener
	// contains filtered or unexported fields
}

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

type IdleConn struct {
	net.Conn
	// contains filtered or unexported fields
}

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) Read

func (c *IdleConn) Read(b []byte) (int, error)

func (*IdleConn) SetReadTimeout

func (c *IdleConn) SetReadTimeout(d time.Duration)

SetReadTimeout configures the per-Read idle deadline. A zero or negative value disables it.

func (*IdleConn) SetWriteTimeout

func (c *IdleConn) SetWriteTimeout(d time.Duration)

SetWriteTimeout configures the per-Write idle deadline. A zero or negative value disables it.

func (*IdleConn) Write

func (c *IdleConn) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址