@@ -22,31 +22,42 @@ import (
22
22
"fmt"
23
23
"net"
24
24
"time"
25
+
26
+ "github.com/Microsoft/go-winio"
25
27
)
26
28
27
29
const (
28
- tcpProtocol = "tcp"
30
+ tcpProtocol = "tcp"
31
+ npipeProtocol = "npipe"
29
32
)
30
33
31
34
func CreateListener (endpoint string ) (net.Listener , error ) {
32
35
protocol , addr , err := parseEndpoint (endpoint )
33
36
if err != nil {
34
37
return nil , err
35
38
}
36
- if protocol != tcpProtocol {
37
- return nil , fmt .Errorf ("only support tcp endpoint" )
39
+ switch protocol {
40
+ case tcpProtocol :
41
+ return net .Listen (protocol , addr )
42
+ case npipeProtocol :
43
+ return winio .ListenPipe (addr , nil )
44
+ default :
45
+ return nil , fmt .Errorf ("only support tcp or npipe endpoint" )
38
46
}
39
-
40
- return net .Listen (protocol , addr )
41
47
}
42
48
43
49
func GetAddressAndDialer (endpoint string ) (string , func (addr string , timeout time.Duration ) (net.Conn , error ), error ) {
44
50
protocol , addr , err := parseEndpoint (endpoint )
45
51
if err != nil {
46
52
return "" , nil , err
47
53
}
48
- if protocol != tcpProtocol {
49
- return "" , nil , fmt .Errorf ("only support tcp endpoint" )
54
+ switch protocol {
55
+ case tcpProtocol :
56
+ return addr , dial , nil
57
+ case npipeProtocol :
58
+ return addr , dialPipe , nil
59
+ default :
60
+ return "" , nil , fmt .Errorf ("only support tcp or npipe endpoint" )
50
61
}
51
62
52
63
return addr , dial , nil
@@ -55,3 +66,7 @@ func GetAddressAndDialer(endpoint string) (string, func(addr string, timeout tim
55
66
func dial (addr string , timeout time.Duration ) (net.Conn , error ) {
56
67
return net .DialTimeout (tcpProtocol , addr , timeout )
57
68
}
69
+
70
+ func dialPipe (addr string , timeout time.Duration ) (net.Conn , error ) {
71
+ return winio .DialPipe (addr , & timeout )
72
+ }
0 commit comments