sockerr

package
v0.3.18 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package sockerr classifies socket errors portably. On Windows, Winsock reports WSAE* codes (WSAECONNREFUSED is 10061), while the syscall.E* constants there are invented values that never match a real socket error; errors.Is(err, syscall.ECONNREFUSED) is therefore always false on Windows. Every check here matches the POSIX errno and, on Windows, its Winsock code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnFromContext

func ConnFromContext(ctx context.Context) net.Conn

ConnFromContext returns the innermost underlying net.Conn stored by WithConn, unwrapping TLS and listener peek wrappers.

func EnableFastDeadPeer

func EnableFastDeadPeer(ctx context.Context, timeout time.Duration)

EnableFastDeadPeer configures aggressive TCP keepalive probes and a bounded unacknowledged-retransmit timeout on the request's underlying TCP socket, if available. Non-TCP or in-memory test connections are left untouched.

func EnableFastDeadPeerConn

func EnableFastDeadPeerConn(c net.Conn, timeout time.Duration)

EnableFastDeadPeerConn applies fast dead-peer detection to c when c unwraps to a *net.TCPConn.

func IsAddrInUse

func IsAddrInUse(err error) bool

IsAddrInUse reports a bind to an address already in use (EADDRINUSE).

func IsConnAborted

func IsConnAborted(err error) bool

IsConnAborted reports a connection aborted locally (ECONNABORTED).

func IsConnRefused

func IsConnRefused(err error) bool

IsConnRefused reports an explicit connection refusal (ECONNREFUSED).

func IsConnReset

func IsConnReset(err error) bool

IsConnReset reports a connection reset by the peer (ECONNRESET).

func IsDescriptorExhausted

func IsDescriptorExhausted(err error) bool

IsDescriptorExhausted reports a process or system descriptor limit (EMFILE, ENFILE).

func IsUnreachable

func IsUnreachable(err error) bool

IsUnreachable reports a missing network or host route (ENETUNREACH, EHOSTUNREACH).

func TCPSendBacklog

func TCPSendBacklog(ctx context.Context) (int, bool)

TCPSendBacklog returns the number of unsent bytes currently queued in the kernel TCP send buffer for the request's connection, when supported by the host OS. A non-zero backlog while writing indicates real network backpressure rather than an idle socket.

func TCPSendBacklogConn

func TCPSendBacklogConn(c net.Conn) (int, bool)

TCPSendBacklogConn returns the unsent bytes queued in c's kernel TCP send buffer when c unwraps to a *net.TCPConn and the platform exposes it.

func WithConn

func WithConn(ctx context.Context, c net.Conn) context.Context

WithConn stores the accepted network connection on an HTTP request context so long-lived streams (SSE, WebSocket) can arm TCP keepalive and retransmit timeouts that surface a silent dead peer in seconds instead of minutes.

Types

This section is empty.

Jump to

Keyboard shortcuts

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