mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-10-20 08:14:24 +00:00
Fix gRPC transport half-close
This commit is contained in:
+14
-11
@@ -10,6 +10,8 @@ import (
|
||||
"github.com/sagernet/sing/common/baderror"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
var _ net.Conn = (*GRPCConn)(nil)
|
||||
@@ -21,15 +23,15 @@ type GRPCConn struct {
|
||||
closeOnce sync.Once
|
||||
}
|
||||
|
||||
func NewGRPCConn(service GunService, cancel context.CancelCauseFunc) *GRPCConn {
|
||||
//nolint:staticcheck
|
||||
if client, isClient := service.(GunService_TunClient); isClient {
|
||||
service = &clientConnWrapper{client}
|
||||
}
|
||||
return &GRPCConn{
|
||||
func NewGRPCConn(service GunService, cancel context.CancelCauseFunc) net.Conn {
|
||||
conn := &GRPCConn{
|
||||
GunService: service,
|
||||
cancel: cancel,
|
||||
}
|
||||
if client, isClient := service.(grpc.ClientStream); isClient {
|
||||
return &GRPCClientConn{GRPCConn: conn, client: client}
|
||||
}
|
||||
return conn
|
||||
}
|
||||
|
||||
func (c *GRPCConn) Read(b []byte) (n int, err error) {
|
||||
@@ -95,12 +97,13 @@ func (c *GRPCConn) Upstream() any {
|
||||
return c.GunService
|
||||
}
|
||||
|
||||
var _ N.WriteCloser = (*clientConnWrapper)(nil)
|
||||
var _ N.WriteCloser = (*GRPCClientConn)(nil)
|
||||
|
||||
type clientConnWrapper struct {
|
||||
GunService_TunClient
|
||||
type GRPCClientConn struct {
|
||||
*GRPCConn
|
||||
client grpc.ClientStream
|
||||
}
|
||||
|
||||
func (c *clientConnWrapper) CloseWrite() error {
|
||||
return c.CloseSend()
|
||||
func (c *GRPCClientConn) CloseWrite() error {
|
||||
return c.client.CloseSend()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user