connstate

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnState

type ConnState uint32
const (
	// StateOK means the connection is normal.
	StateOK ConnState = iota
	// StateRemoteClosed means the remote side has closed the connection.
	StateRemoteClosed
	// StateClosed means the connection has been closed by local side.
	StateClosed
)

type ConnStater

type ConnStater interface {
	Close() error
	State() ConnState
}

ConnStater is the interface to get the ConnState of a connection. Must call Close to release it if you're going to close the connection.

func ListenConnState

func ListenConnState(conn net.Conn, opts ...Option) (ConnStater, error)

ListenConnState returns a ConnStater for the given connection. Conn must be a syscall.Conn.

type OnRemoteClosed added in v0.1.9

type OnRemoteClosed func()

OnRemoteClosed is a callback function type that will be invoked when the remote side of the connection is closed.

type Option added in v0.1.9

type Option func(stater *connStater)

func WithOnRemoteClosed added in v0.1.9

func WithOnRemoteClosed(fn OnRemoteClosed) Option

WithOnRemoteClosed sets a callback function that will be called when the remote side closes the connection. The callback is invoked only once, when the state transitions from StateOK to StateRemoteClosed.

Jump to

Keyboard shortcuts

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