sing/common/network/duplex.go
2024-06-24 09:42:23 +08:00

27 lines
422 B
Go

package network
import (
"github.com/sagernet/sing/common"
)
type ReadCloser interface {
CloseRead() error
}
type WriteCloser interface {
CloseWrite() error
}
func CloseRead(reader any) error {
if c, ok := common.Cast[ReadCloser](reader); ok {
return c.CloseRead()
}
return nil
}
func CloseWrite(writer any) error {
if c, ok := common.Cast[WriteCloser](writer); ok {
return c.CloseWrite()
}
return nil
}