connhook

package
v1.18.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2024 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 3 more Imports: 2 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHookListener

func NewHookListener(l net.Listener, hooks ...Hook) net.Listener

Types

type Conn

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

Conn 包装net.Conn 目的:拦截Close操作,用于listener计数的Release以及activeConns的删除

func (*Conn) Close

func (c *Conn) Close() error

Close 包装net.Conn.Close, 用于连接计数

type Hook

type Hook interface {
	// OnAccept call when net.Conn accept
	OnAccept(conn net.Conn)
	// OnRelease call when net.Conn release
	OnRelease(conn net.Conn)
	// OnClose call when net.Listener close
	OnClose()
}

Hook Hook

type HookListener

type HookListener struct {
	// contains filtered or unexported fields
}

HookListener net.Listener can add hook

func (*HookListener) Accept

func (l *HookListener) Accept() (net.Conn, error)

Accept waits for and returns the next connection to the listener.

func (*HookListener) Addr

func (l *HookListener) Addr() net.Addr

Addr returns the listener's network address.

func (*HookListener) Close

func (l *HookListener) Close() error

Close closes the listener. Any blocked Accept operations will be unblocked and return errors.

Jump to

Keyboard shortcuts

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