mirror of
https://github.com/linka-cloud/grpc.git
synced 2026-01-08 19:14:03 +00:00
feat(server/client): add windows pipe, pipe peer credentials support
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
11
service/listen.go
Normal file
11
service/listen.go
Normal file
@@ -0,0 +1,11 @@
|
||||
//go:build !windows
|
||||
|
||||
package service
|
||||
|
||||
import (
|
||||
"net"
|
||||
)
|
||||
|
||||
func listen(network, address string) (net.Listener, error) {
|
||||
return net.Listen(network, address)
|
||||
}
|
||||
14
service/listen_windows.go
Normal file
14
service/listen_windows.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/Microsoft/go-winio"
|
||||
)
|
||||
|
||||
func listen(network, address string) (net.Listener, error) {
|
||||
if network == "pipe" {
|
||||
return winio.ListenPipe(address, nil)
|
||||
}
|
||||
return net.Listen(network, address)
|
||||
}
|
||||
@@ -139,7 +139,7 @@ func newService(opts ...Option) (*service, error) {
|
||||
grpc.StreamInterceptor(si),
|
||||
grpc.UnaryInterceptor(ui),
|
||||
}
|
||||
if _, ok := s.opts.lis.(*net.UnixListener); ok || strings.HasPrefix(s.opts.address, "unix://") {
|
||||
if _, ok := s.opts.lis.(*net.UnixListener); ok || strings.HasPrefix(s.opts.address, "unix://") || strings.HasPrefix(s.opts.address, `\\.\pipe\`) {
|
||||
gopts = append(gopts, grpc.Creds(peercreds.New()))
|
||||
}
|
||||
s.server = grpc.NewServer(append(gopts, s.opts.serverOpts...)...)
|
||||
@@ -179,9 +179,12 @@ func (s *service) start() (*errgroup.Group, error) {
|
||||
network = "unix"
|
||||
s.opts.address = strings.TrimPrefix(s.opts.address, "unix://")
|
||||
}
|
||||
if strings.HasPrefix(s.opts.address, `\\.\pipe\`) {
|
||||
network = "pipe"
|
||||
}
|
||||
|
||||
if s.opts.lis == nil {
|
||||
lis, err := net.Listen(network, s.opts.address)
|
||||
lis, err := listen(network, s.opts.address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user