mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 13:41:23 +08:00
26 lines
402 B
Go
26 lines
402 B
Go
|
package callback
|
||
|
|
||
|
import (
|
||
|
C "github.com/Dreamacro/clash/constant"
|
||
|
)
|
||
|
|
||
|
type FirstWriteCallBackConn struct {
|
||
|
C.Conn
|
||
|
Callback func(error)
|
||
|
written bool
|
||
|
}
|
||
|
|
||
|
func (c *FirstWriteCallBackConn) Write(b []byte) (n int, err error) {
|
||
|
defer func() {
|
||
|
if !c.written {
|
||
|
c.written = true
|
||
|
c.Callback(err)
|
||
|
}
|
||
|
}()
|
||
|
return c.Conn.Write(b)
|
||
|
}
|
||
|
|
||
|
func (c *FirstWriteCallBackConn) Upstream() any {
|
||
|
return c.Conn
|
||
|
}
|