-
Notifications
You must be signed in to change notification settings - Fork 40
/
connect_windows.go
executable file
·78 lines (54 loc) · 1.32 KB
/
connect_windows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package ipc
import (
"errors"
"strings"
"time"
"github.com/Microsoft/go-winio"
)
// Server function
// Create the named pipe (if it doesn't already exist) and start listening for a client to connect.
// when a client connects and connection is accepted the read function is called on a go routine.
func (s *Server) run() error {
var pipeBase = `\\.\pipe\`
var config *winio.PipeConfig
if s.unMask {
config = &winio.PipeConfig{SecurityDescriptor: "D:P(A;;GA;;;AU)"}
}
listen, err := winio.ListenPipe(pipeBase+s.name, config)
if err != nil {
return err
}
s.listen = listen
s.status = Listening
go s.acceptLoop()
return nil
}
// Client function
// dial - attempts to connect to a named pipe created by the server
func (c *Client) dial() error {
var pipeBase = `\\.\pipe\`
startTime := time.Now()
for {
if c.timeout != 0 {
if time.Since(startTime).Seconds() > c.timeout {
c.status = Closed
return errors.New("timed out trying to connect")
}
}
pn, err := winio.DialPipe(pipeBase+c.Name, nil)
if err != nil {
if strings.Contains(err.Error(), "the system cannot find the file specified.") == true {
} else {
return err
}
} else {
c.conn = pn
err = c.handshake()
if err != nil {
return err
}
return nil
}
time.Sleep(c.retryTimer * time.Second)
}
}