clash/common/net/earlyconn.go
wwqgtxx 974332c0cc
Some checks failed
Build / build (map[goarch:amd64 goos:android ndk:x86_64-linux-android34 output:amd64]) (push) Has been cancelled
Build / build (map[goarch:arm goarm:7 goos:linux output:armv7]) (push) Has been cancelled
Build / build (map[goarch:arm goarm:7 goos:windows output:armv7]) (push) Has been cancelled
Build / build (map[goarch:arm goos:android ndk:armv7a-linux-androideabi34 output:armv7]) (push) Has been cancelled
Build / build (map[goarch:arm64 goos:android ndk:aarch64-linux-android34 output:arm64-v8]) (push) Has been cancelled
Build / build (map[goarch:arm64 goos:darwin goversion:1.20 output:arm64-go120]) (push) Has been cancelled
Build / build (map[goarch:arm64 goos:darwin output:arm64]) (push) Has been cancelled
Build / build (map[goarch:arm64 goos:freebsd output:arm64]) (push) Has been cancelled
Build / build (map[goarch:arm64 goos:linux output:arm64]) (push) Has been cancelled
Build / build (map[goarch:arm64 goos:windows output:arm64]) (push) Has been cancelled
Build / build (map[goarch:mips goos:linux mips:hardfloat output:mips-hardfloat]) (push) Has been cancelled
Build / build (map[goarch:mips goos:linux mips:softfloat output:mips-softfloat]) (push) Has been cancelled
Build / build (map[goarch:mips64 goos:linux output:mips64]) (push) Has been cancelled
Build / build (map[goarch:mips64le goos:linux output:mips64le]) (push) Has been cancelled
Build / build (map[goarch:mipsle goos:linux mips:hardfloat output:mipsle-hardfloat]) (push) Has been cancelled
Build / build (map[abi:1 goarch:loong64 goos:linux output:loong64-abi1]) (push) Has been cancelled
Build / build (map[abi:2 goarch:loong64 goos:linux output:loong64-abi2]) (push) Has been cancelled
Build / build (map[goamd64:v1 goarch:amd64 goos:darwin goversion:1.20 output:amd64-compatible-go120]) (push) Has been cancelled
Build / build (map[goamd64:v1 goarch:amd64 goos:darwin output:amd64-compatible]) (push) Has been cancelled
Build / build (map[goamd64:v1 goarch:amd64 goos:freebsd output:amd64-compatible]) (push) Has been cancelled
Build / build (map[goamd64:v1 goarch:amd64 goos:linux goversion:1.20 output:amd64-compatible-go120 test:test]) (push) Has been cancelled
Build / build (map[goamd64:v1 goarch:amd64 goos:linux output:amd64-compatible test:test]) (push) Has been cancelled
Build / build (map[goamd64:v1 goarch:amd64 goos:windows goversion:1.20 output:amd64-compatible-go120]) (push) Has been cancelled
Build / build (map[goamd64:v1 goarch:amd64 goos:windows output:amd64-compatible]) (push) Has been cancelled
Build / build (map[goamd64:v3 goarch:amd64 goos:darwin goversion:1.20 output:amd64-go120]) (push) Has been cancelled
Build / build (map[goamd64:v3 goarch:amd64 goos:darwin output:amd64]) (push) Has been cancelled
Build / build (map[goamd64:v3 goarch:amd64 goos:freebsd output:amd64]) (push) Has been cancelled
Build / build (map[goamd64:v3 goarch:amd64 goos:linux goversion:1.20 output:amd64-go120]) (push) Has been cancelled
Build / build (map[goamd64:v3 goarch:amd64 goos:linux output:amd64]) (push) Has been cancelled
Build / build (map[goamd64:v3 goarch:amd64 goos:windows goversion:1.20 output:amd64-go120]) (push) Has been cancelled
Build / build (map[goamd64:v3 goarch:amd64 goos:windows output:amd64]) (push) Has been cancelled
Build / build (map[goarch:386 goos:android ndk:i686-linux-android34 output:386]) (push) Has been cancelled
Build / build (map[goarch:386 goos:freebsd output:386]) (push) Has been cancelled
Build / build (map[goarch:386 goos:linux goversion:1.20 output:386-go120]) (push) Has been cancelled
Build / build (map[goarch:386 goos:linux output:386]) (push) Has been cancelled
Build / build (map[goarch:386 goos:windows goversion:1.20 output:386-go120]) (push) Has been cancelled
Build / build (map[goarch:386 goos:windows output:386]) (push) Has been cancelled
Build / build (map[goarch:mipsle goos:linux mips:softfloat output:mipsle-softfloat]) (push) Has been cancelled
Build / build (map[goarch:riscv64 goos:linux output:riscv64]) (push) Has been cancelled
Build / build (map[goarch:s390x goos:linux output:s390x]) (push) Has been cancelled
Trigger CMFA Update / trigger-CMFA-update (push) Has been cancelled
Build / Upload-Prerelease (push) Has been cancelled
Build / Upload-Release (push) Has been cancelled
Build / Docker (push) Has been cancelled
chore: rebuild sync.Once visit code
2024-03-05 10:57:25 +08:00

66 lines
1.3 KiB
Go

package net
import (
"net"
"sync"
"github.com/metacubex/mihomo/common/buf"
"github.com/metacubex/mihomo/common/once"
)
type earlyConn struct {
ExtendedConn // only expose standard N.ExtendedConn function to outside
resFunc func() error
resOnce sync.Once
resErr error
}
func (conn *earlyConn) Response() error {
conn.resOnce.Do(func() {
conn.resErr = conn.resFunc()
})
return conn.resErr
}
func (conn *earlyConn) Read(b []byte) (n int, err error) {
err = conn.Response()
if err != nil {
return 0, err
}
return conn.ExtendedConn.Read(b)
}
func (conn *earlyConn) ReadBuffer(buffer *buf.Buffer) (err error) {
err = conn.Response()
if err != nil {
return err
}
return conn.ExtendedConn.ReadBuffer(buffer)
}
func (conn *earlyConn) Upstream() any {
return conn.ExtendedConn
}
func (conn *earlyConn) Success() bool {
return once.Done(&conn.resOnce) && conn.resErr == nil
}
func (conn *earlyConn) ReaderReplaceable() bool {
return conn.Success()
}
func (conn *earlyConn) ReaderPossiblyReplaceable() bool {
return !conn.Success()
}
func (conn *earlyConn) WriterReplaceable() bool {
return true
}
var _ ExtendedConn = (*earlyConn)(nil)
func NewEarlyConn(c net.Conn, f func() error) net.Conn {
return &earlyConn{ExtendedConn: NewExtendedConn(c), resFunc: f}
}