netpipe

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package netpipe 提供两个连接之间的双向转发。

Index

Constants

This section is empty.

Variables

View Source
var ErrNoData = errors.New("连接建立后双方都没有发送数据")

ErrNoData 表示连接建立后双方在限定时间内都没有发送任何数据。

Functions

func Join

func Join(ctx context.Context, a, b net.Conn) (aToB, bToA int64)

Join 在 a 与 b 之间双向复制数据,直到两个方向都结束或 ctx 取消。 返回 a→b 与 b→a 的字节数。调用方负责在返回后关闭连接。

func ReadableNow added in v0.6.8

func ReadableNow(raw syscall.RawConn) bool

ReadableNow 不阻塞地判断套接字此刻是否可读(有数据、对端已关闭或有待报告的错误),不取走数据。

func WaitFirstData added in v0.6.8

func WaitFirstData(ctx context.Context, a, b net.Conn, d time.Duration) error

WaitFirstData 等到 a、b 任一端可读(收到数据或对端关闭),最长 d;都没有动静时返回 ErrNoData。 不取走任何数据,返回后照常用 Join 转发。用于丢弃只建立连接、不发送任何数据的空连接: 正常协议总有一方在连接后立即发言(HTTP、TLS 由客户端先发,SSH、FTP、MySQL 由服务端先发)。 ctx 取消时立即返回 ctx 的错误。连接不支持 SyscallConn 时无法不取数据地等待,直接返回 nil(不限制)。

func WaitReadable added in v0.6.8

func WaitReadable(raw syscall.RawConn) error

WaitReadable 阻塞到套接字有数据可读(UDP 有数据报、TCP 有数据或对端已关闭),或读截止时间到、连接关闭、收到套接字错误, 不取走数据。raw 为 UDP 或 TCP 连接的 SyscallConn。 Go 的网络轮询是边沿触发的,等待前必须先确认缓冲区里确实没有数据:用 MSG_PEEK 偷看 1 字节, 返回 EAGAIN 才交给轮询器等待,否则会漏掉等待开始前已经到达的数据。 偷看拿到的套接字错误(如 UDP 目标端口不可达)会被内核清除,原样返回,与直接 Read 得到的错误一致。

Types

This section is empty.

Jump to

Keyboard shortcuts

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