mirror of
https://github.com/docker/compose.git
synced 2026-08-04 14:47:40 +00:00
Allow server to start on tcp port or if windows, named pipe rather than unix socket. could not yet make it work on named pipe from js client (connects but error)
This commit is contained in:
parent
23d2eacf84
commit
ecfffc6feb
6 changed files with 55 additions and 5 deletions
|
|
@ -30,6 +30,8 @@ package server
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
"google.golang.org/grpc"
|
||||
|
|
@ -57,6 +59,15 @@ func New() *grpc.Server {
|
|||
return s
|
||||
}
|
||||
|
||||
|
||||
//CreateListener creates a listener either on tcp://, or local listener, supporting unix:// for unix socket or npipe:// for named pipes on windows
|
||||
func CreateListener(address string) (net.Listener, error) {
|
||||
if strings.HasPrefix(address, "tcp://") {
|
||||
return net.Listen("tcp", strings.TrimPrefix(address, "tcp://"))
|
||||
}
|
||||
return createLocalListener(address)
|
||||
}
|
||||
|
||||
func unary(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
|
||||
return grpc_prometheus.UnaryServerInterceptor(ctx, req, info, handler)
|
||||
}
|
||||
|
|
|
|||
16
server/socket_unix.go
Normal file
16
server/socket_unix.go
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// +build !windows
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func createLocalListener(address string) (net.Listener, error) {
|
||||
if !strings.HasPrefix(address, "unix://") {
|
||||
return nil, errors.New("Cannot parse address, must start with unix:// or tcp:// : " + address)
|
||||
}
|
||||
return net.Listen("unix", strings.TrimPrefix(address, "unix://"))
|
||||
}
|
||||
22
server/socket_windows.go
Normal file
22
server/socket_windows.go
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// +build windows
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
"github.com/Microsoft/go-winio"
|
||||
)
|
||||
|
||||
func createLocalListener(address string) (net.Listener, error) {
|
||||
if !strings.HasPrefix(address, "npipe://") {
|
||||
return nil, errors.New("Cannot parse address, must start with npipe:// or tcp:// : " + address)
|
||||
}
|
||||
return winio.ListenPipe(strings.TrimPrefix(address, "npipe://"), &winio.PipeConfig{
|
||||
MessageMode: true, // Use message mode so that CloseWrite() is supported
|
||||
InputBufferSize: 65536, // Use 64KB buffers to improve performance
|
||||
OutputBufferSize: 65536,
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue