Browse code

Windows: new hcsshim stdin/out/err handling

Signed-off-by: John Howard <jhoward@microsoft.com>

John Starks authored on 2015/07/19 09:15:02
Showing 16 changed files
... ...
@@ -8,22 +8,16 @@ import (
8 8
 
9 9
 	"github.com/Sirupsen/logrus"
10 10
 	"github.com/docker/docker/daemon/execdriver"
11
-	"github.com/docker/docker/pkg/stringid"
12 11
 	"github.com/microsoft/hcsshim"
13
-	"github.com/natefinch/npipe"
14 12
 )
15 13
 
16 14
 // Exec implements the exec driver Driver interface.
17 15
 func (d *Driver) Exec(c *execdriver.Command, processConfig *execdriver.ProcessConfig, pipes *execdriver.Pipes, startCallback execdriver.StartCallback) (int, error) {
18 16
 
19 17
 	var (
20
-		inListen, outListen, errListen     *npipe.PipeListener
21
-		term                               execdriver.Terminal
22
-		err                                error
23
-		randomID                           = stringid.GenerateNonCryptoID()
24
-		serverPipeFormat, clientPipeFormat string
25
-		pid                                uint32
26
-		exitCode                           int32
18
+		term     execdriver.Terminal
19
+		err      error
20
+		exitCode int32
27 21
 	)
28 22
 
29 23
 	active := d.activeContainers[c.ID]
... ...
@@ -39,64 +33,6 @@ func (d *Driver) Exec(c *execdriver.Command, processConfig *execdriver.ProcessCo
39 39
 	// Configure the environment for the process // Note NOT c.ProcessConfig.Tty
40 40
 	createProcessParms.Environment = setupEnvironmentVariables(processConfig.Env)
41 41
 
42
-	// We use another unique ID here for each exec instance otherwise it
43
-	// may conflict with the pipe name being used by RUN.
44
-
45
-	// We use a different pipe name between real and dummy mode in the HCS
46
-	if dummyMode {
47
-		clientPipeFormat = `\\.\pipe\docker-exec-%[1]s-%[2]s-%[3]s`
48
-		serverPipeFormat = clientPipeFormat
49
-	} else {
50
-		clientPipeFormat = `\\.\pipe\docker-exec-%[2]s-%[3]s`
51
-		serverPipeFormat = `\\.\Containers\%[1]s\Device\NamedPipe\docker-exec-%[2]s-%[3]s`
52
-	}
53
-
54
-	// Connect stdin
55
-	if pipes.Stdin != nil {
56
-		stdInPipe := fmt.Sprintf(serverPipeFormat, c.ID, randomID, "stdin")
57
-		createProcessParms.StdInPipe = fmt.Sprintf(clientPipeFormat, c.ID, randomID, "stdin")
58
-
59
-		// Listen on the named pipe
60
-		inListen, err = npipe.Listen(stdInPipe)
61
-		if err != nil {
62
-			logrus.Errorf("stdin failed to listen on %s %s ", stdInPipe, err)
63
-			return -1, err
64
-		}
65
-		defer inListen.Close()
66
-
67
-		// Launch a goroutine to do the accept. We do this so that we can
68
-		// cause an otherwise blocking goroutine to gracefully close when
69
-		// the caller (us) closes the listener
70
-		go stdinAccept(inListen, stdInPipe, pipes.Stdin)
71
-	}
72
-
73
-	// Connect stdout
74
-	stdOutPipe := fmt.Sprintf(serverPipeFormat, c.ID, randomID, "stdout")
75
-	createProcessParms.StdOutPipe = fmt.Sprintf(clientPipeFormat, c.ID, randomID, "stdout")
76
-
77
-	outListen, err = npipe.Listen(stdOutPipe)
78
-	if err != nil {
79
-		logrus.Errorf("stdout failed to listen on %s %s", stdOutPipe, err)
80
-		return -1, err
81
-	}
82
-	defer outListen.Close()
83
-	go stdouterrAccept(outListen, stdOutPipe, pipes.Stdout)
84
-
85
-	// No stderr on TTY. Note NOT c.ProcessConfig.Tty
86
-	if !processConfig.Tty {
87
-		// Connect stderr
88
-		stdErrPipe := fmt.Sprintf(serverPipeFormat, c.ID, randomID, "stderr")
89
-		createProcessParms.StdErrPipe = fmt.Sprintf(clientPipeFormat, c.ID, randomID, "stderr")
90
-
91
-		errListen, err = npipe.Listen(stdErrPipe)
92
-		if err != nil {
93
-			logrus.Errorf("Stderr failed to listen on %s %s", stdErrPipe, err)
94
-			return -1, err
95
-		}
96
-		defer errListen.Close()
97
-		go stdouterrAccept(errListen, stdErrPipe, pipes.Stderr)
98
-	}
99
-
100 42
 	// While this should get caught earlier, just in case, validate that we
101 43
 	// have something to run.
102 44
 	if processConfig.Entrypoint == "" {
... ...
@@ -114,13 +50,16 @@ func (d *Driver) Exec(c *execdriver.Command, processConfig *execdriver.ProcessCo
114 114
 	logrus.Debugln("commandLine: ", createProcessParms.CommandLine)
115 115
 
116 116
 	// Start the command running in the container.
117
-	pid, err = hcsshim.CreateProcessInComputeSystem(c.ID, createProcessParms)
118
-
117
+	pid, stdin, stdout, stderr, err := hcsshim.CreateProcessInComputeSystem(c.ID, pipes.Stdin != nil, true, !processConfig.Tty, createProcessParms)
119 118
 	if err != nil {
120 119
 		logrus.Errorf("CreateProcessInComputeSystem() failed %s", err)
121 120
 		return -1, err
122 121
 	}
123 122
 
123
+	// Now that the process has been launched, begin copying data to and from
124
+	// the named pipes for the std handles.
125
+	setupPipes(stdin, stdout, stderr, pipes)
126
+
124 127
 	// Note NOT c.ProcessConfig.Tty
125 128
 	if processConfig.Tty {
126 129
 		term = NewTtyConsole(c.ID, pid)
... ...
@@ -6,77 +6,49 @@ import (
6 6
 	"io"
7 7
 
8 8
 	"github.com/Sirupsen/logrus"
9
-	"github.com/natefinch/npipe"
9
+	"github.com/docker/docker/daemon/execdriver"
10 10
 )
11 11
 
12
-// stdinAccept runs as a go function. It waits for the container system
13
-// to accept our offer of a named pipe for stdin. Once accepted, if we are
14
-// running "attached" to the container (eg docker run -i), then we spin up
15
-// a further thread to copy anything from the client into the container.
16
-//
17
-// Important design note. This function is run as a go function for a very
18
-// good reason. The named pipe Accept call is blocking until one of two things
19
-// happen. Either someone connects to it, or it is forcibly closed. Let's
20
-// assume that no-one connects to it, the only way otherwise the Run()
21
-// method would continue is by closing it. However, as that would be the same
22
-// thread, it can't close it. Hence we run as another thread allowing Run()
23
-// to close the named pipe.
24
-func stdinAccept(inListen *npipe.PipeListener, pipeName string, copyfrom io.ReadCloser) {
12
+// General comment. Handling I/O for a container is very different to Linux.
13
+// We use a named pipe to HCS to copy I/O both in and out of the container,
14
+// very similar to how docker daemon communicates with a CLI.
25 15
 
26
-	// Wait for the pipe to be connected to by the shim
27
-	logrus.Debugln("stdinAccept: Waiting on ", pipeName)
28
-	stdinConn, err := inListen.Accept()
29
-	if err != nil {
30
-		logrus.Errorf("Failed to accept on pipe %s %s", pipeName, err)
31
-		return
32
-	}
33
-	logrus.Debugln("Connected to ", stdinConn.RemoteAddr())
16
+// startStdinCopy asynchronously copies an io.Reader to the container's
17
+// process's stdin pipe and closes the pipe when there is no more data to copy.
18
+func startStdinCopy(dst io.WriteCloser, src io.Reader) {
34 19
 
35 20
 	// Anything that comes from the client stdin should be copied
36 21
 	// across to the stdin named pipe of the container.
37
-	if copyfrom != nil {
38
-		go func() {
39
-			defer stdinConn.Close()
40
-			logrus.Debugln("Calling io.Copy on stdin")
41
-			bytes, err := io.Copy(stdinConn, copyfrom)
42
-			logrus.Debugf("Finished io.Copy on stdin bytes=%d err=%s pipe=%s", bytes, err, stdinConn.RemoteAddr())
43
-		}()
44
-	} else {
45
-		defer stdinConn.Close()
46
-	}
22
+	go func() {
23
+		defer dst.Close()
24
+		bytes, err := io.Copy(dst, src)
25
+		logrus.Debugf("Copied %d bytes from stdin err=%s", bytes, err)
26
+	}()
47 27
 }
48 28
 
49
-// stdouterrAccept runs as a go function. It waits for the container system to
50
-// accept our offer of a named pipe - in fact two of them - one for stdout
51
-// and one for stderr (we are called twice). Once the named pipe is accepted,
52
-// if we are running "attached" to the container (eg docker run -i), then we
53
-// spin up a further thread to copy anything from the containers output channels
54
-// to the client.
55
-func stdouterrAccept(outerrListen *npipe.PipeListener, pipeName string, copyto io.Writer) {
56
-
57
-	// Wait for the pipe to be connected to by the shim
58
-	logrus.Debugln("out/err: Waiting on ", pipeName)
59
-	outerrConn, err := outerrListen.Accept()
60
-	if err != nil {
61
-		logrus.Errorf("Failed to accept on pipe %s %s", pipeName, err)
62
-		return
63
-	}
64
-	logrus.Debugln("Connected to ", outerrConn.RemoteAddr())
65
-
29
+// startStdouterrCopy asynchronously copies data from the container's process's
30
+// stdout or stderr pipe to an io.Writer and closes the pipe when there is no
31
+// more data to copy.
32
+func startStdouterrCopy(dst io.Writer, src io.ReadCloser, name string) {
66 33
 	// Anything that comes from the container named pipe stdout/err should be copied
67 34
 	// across to the stdout/err of the client
68
-	if copyto != nil {
69
-		go func() {
70
-			defer outerrConn.Close()
71
-			logrus.Debugln("Calling io.Copy on ", pipeName)
72
-			bytes, err := io.Copy(copyto, outerrConn)
73
-			logrus.Debugf("Copied %d bytes from pipe=%s", bytes, outerrConn.RemoteAddr())
74
-			if err != nil {
75
-				// Not fatal, just debug log it
76
-				logrus.Debugf("Error hit during copy %s", err)
77
-			}
78
-		}()
79
-	} else {
80
-		defer outerrConn.Close()
35
+	go func() {
36
+		defer src.Close()
37
+		bytes, err := io.Copy(dst, src)
38
+		logrus.Debugf("Copied %d bytes from %s err=%s", bytes, name, err)
39
+	}()
40
+}
41
+
42
+// setupPipes starts the asynchronous copying of data to and from the named
43
+// pipes used byt he HCS for the std handles.
44
+func setupPipes(stdin io.WriteCloser, stdout, stderr io.ReadCloser, pipes *execdriver.Pipes) {
45
+	if stdin != nil {
46
+		startStdinCopy(stdin, pipes.Stdin)
47
+	}
48
+	if stdout != nil {
49
+		startStdouterrCopy(pipes.Stdout, stdout, "stdout")
50
+	}
51
+	if stderr != nil {
52
+		startStdouterrCopy(pipes.Stderr, stderr, "stderr")
81 53
 	}
82 54
 }
... ...
@@ -15,7 +15,6 @@ import (
15 15
 	"github.com/Sirupsen/logrus"
16 16
 	"github.com/docker/docker/daemon/execdriver"
17 17
 	"github.com/microsoft/hcsshim"
18
-	"github.com/natefinch/npipe"
19 18
 )
20 19
 
21 20
 // defaultContainerNAT is the default name of the container NAT device that is
... ...
@@ -60,23 +59,28 @@ type device struct {
60 60
 }
61 61
 
62 62
 type containerInit struct {
63
-	SystemType              string
64
-	Name                    string
65
-	IsDummy                 bool
66
-	VolumePath              string
67
-	Devices                 []device
68
-	IgnoreFlushesDuringBoot bool
69
-	LayerFolderPath         string
70
-	Layers                  []layer
63
+	SystemType              string   // HCS requires this to be hard-coded to "Container"
64
+	Name                    string   // Name of the container. We use the docker ID.
65
+	Owner                   string   // The management platform that created this container
66
+	IsDummy                 bool     // Used for development purposes.
67
+	VolumePath              string   // Windows volume path for scratch space
68
+	Devices                 []device // Devices used by the container
69
+	IgnoreFlushesDuringBoot bool     // Optimisation hint for container startup in Windows
70
+	LayerFolderPath         string   // Where the layer folders are located
71
+	Layers                  []layer  // List of storage layers
71 72
 }
72 73
 
74
+// defaultOwner is a tag passed to HCS to allow it to differentiate between
75
+// container creator management stacks. We hard code "docker" in the case
76
+// of docker.
77
+const defaultOwner = "docker"
78
+
73 79
 // Run implements the exec driver Driver interface
74 80
 func (d *Driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallback execdriver.StartCallback) (execdriver.ExitStatus, error) {
75 81
 
76 82
 	var (
77
-		term                           execdriver.Terminal
78
-		err                            error
79
-		inListen, outListen, errListen *npipe.PipeListener
83
+		term execdriver.Terminal
84
+		err  error
80 85
 	)
81 86
 
82 87
 	// Make sure the client isn't asking for options which aren't supported
... ...
@@ -88,6 +92,7 @@ func (d *Driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
88 88
 	cu := &containerInit{
89 89
 		SystemType:              "Container",
90 90
 		Name:                    c.ID,
91
+		Owner:                   defaultOwner,
91 92
 		IsDummy:                 dummyMode,
92 93
 		VolumePath:              c.Rootfs,
93 94
 		IgnoreFlushesDuringBoot: c.FirstStart,
... ...
@@ -224,16 +229,6 @@ func (d *Driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
224 224
 		}
225 225
 	}()
226 226
 
227
-	// We use a different pipe name between real and dummy mode in the HCS
228
-	var serverPipeFormat, clientPipeFormat string
229
-	if dummyMode {
230
-		clientPipeFormat = `\\.\pipe\docker-run-%[1]s-%[2]s`
231
-		serverPipeFormat = clientPipeFormat
232
-	} else {
233
-		clientPipeFormat = `\\.\pipe\docker-run-%[2]s`
234
-		serverPipeFormat = `\\.\Containers\%[1]s\Device\NamedPipe\docker-run-%[2]s`
235
-	}
236
-
237 227
 	createProcessParms := hcsshim.CreateProcessParams{
238 228
 		EmulateConsole:   c.ProcessConfig.Tty,
239 229
 		WorkingDirectory: c.WorkingDir,
... ...
@@ -243,51 +238,6 @@ func (d *Driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
243 243
 	// Configure the environment for the process
244 244
 	createProcessParms.Environment = setupEnvironmentVariables(c.ProcessConfig.Env)
245 245
 
246
-	// Connect stdin
247
-	if pipes.Stdin != nil {
248
-		stdInPipe := fmt.Sprintf(serverPipeFormat, c.ID, "stdin")
249
-		createProcessParms.StdInPipe = fmt.Sprintf(clientPipeFormat, c.ID, "stdin")
250
-
251
-		// Listen on the named pipe
252
-		inListen, err = npipe.Listen(stdInPipe)
253
-		if err != nil {
254
-			logrus.Errorf("stdin failed to listen on %s err=%s", stdInPipe, err)
255
-			return execdriver.ExitStatus{ExitCode: -1}, err
256
-		}
257
-		defer inListen.Close()
258
-
259
-		// Launch a goroutine to do the accept. We do this so that we can
260
-		// cause an otherwise blocking goroutine to gracefully close when
261
-		// the caller (us) closes the listener
262
-		go stdinAccept(inListen, stdInPipe, pipes.Stdin)
263
-	}
264
-
265
-	// Connect stdout
266
-	stdOutPipe := fmt.Sprintf(serverPipeFormat, c.ID, "stdout")
267
-	createProcessParms.StdOutPipe = fmt.Sprintf(clientPipeFormat, c.ID, "stdout")
268
-
269
-	outListen, err = npipe.Listen(stdOutPipe)
270
-	if err != nil {
271
-		logrus.Errorf("stdout failed to listen on %s err=%s", stdOutPipe, err)
272
-		return execdriver.ExitStatus{ExitCode: -1}, err
273
-	}
274
-	defer outListen.Close()
275
-	go stdouterrAccept(outListen, stdOutPipe, pipes.Stdout)
276
-
277
-	// No stderr on TTY.
278
-	if !c.ProcessConfig.Tty {
279
-		// Connect stderr
280
-		stdErrPipe := fmt.Sprintf(serverPipeFormat, c.ID, "stderr")
281
-		createProcessParms.StdErrPipe = fmt.Sprintf(clientPipeFormat, c.ID, "stderr")
282
-		errListen, err = npipe.Listen(stdErrPipe)
283
-		if err != nil {
284
-			logrus.Errorf("stderr failed to listen on %s err=%s", stdErrPipe, err)
285
-			return execdriver.ExitStatus{ExitCode: -1}, err
286
-		}
287
-		defer errListen.Close()
288
-		go stdouterrAccept(errListen, stdErrPipe, pipes.Stderr)
289
-	}
290
-
291 246
 	// This should get caught earlier, but just in case - validate that we
292 247
 	// have something to run
293 248
 	if c.ProcessConfig.Entrypoint == "" {
... ...
@@ -305,14 +255,16 @@ func (d *Driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, startCallba
305 305
 	logrus.Debugf("CommandLine: %s", createProcessParms.CommandLine)
306 306
 
307 307
 	// Start the command running in the container.
308
-	var pid uint32
309
-	pid, err = hcsshim.CreateProcessInComputeSystem(c.ID, createProcessParms)
310
-
308
+	pid, stdin, stdout, stderr, err := hcsshim.CreateProcessInComputeSystem(c.ID, pipes.Stdin != nil, true, !c.ProcessConfig.Tty, createProcessParms)
311 309
 	if err != nil {
312 310
 		logrus.Errorf("CreateProcessInComputeSystem() failed %s", err)
313 311
 		return execdriver.ExitStatus{ExitCode: -1}, err
314 312
 	}
315 313
 
314
+	// Now that the process has been launched, begin copying data to and from
315
+	// the named pipes for the std handles.
316
+	setupPipes(stdin, stdout, stderr, pipes)
317
+
316 318
 	//Save the PID as we'll need this in Kill()
317 319
 	logrus.Debugf("PID %d", pid)
318 320
 	c.ContainerPid = int(pid)
... ...
@@ -13,10 +13,9 @@ clone git github.com/go-check/check 64131543e7896d5bcc6bd5a76287eb75ea96c673
13 13
 clone git github.com/gorilla/context 14f550f51a
14 14
 clone git github.com/gorilla/mux e444e69cbd
15 15
 clone git github.com/kr/pty 5cf931ef8f
16
-clone git github.com/microsoft/hcsshim f674a70f1306dbe20b3a516bedd3285d85db60d9
17 16
 clone git github.com/mattn/go-sqlite3 b4142c444a8941d0d92b0b7103a24df9cd815e42
17
+clone git github.com/microsoft/hcsshim da093dac579302d7b413696b96dec0b5e1bce8d4
18 18
 clone git github.com/mistifyio/go-zfs v2.1.1
19
-clone git github.com/natefinch/npipe 0938d701e50e580f5925c773055eb6d6b32a0cbc
20 19
 clone git github.com/tchap/go-patricia v2.1.0
21 20
 clone git golang.org/x/net 3cffabab72adf04f8e3b01c5baf775361837b5fe https://github.com/golang/net.git
22 21
 clone hg code.google.com/p/gosqlite 74691fb6f837
... ...
@@ -3,6 +3,8 @@ package hcsshim
3 3
 import (
4 4
 	"encoding/json"
5 5
 	"fmt"
6
+	"io"
7
+	"runtime"
6 8
 	"syscall"
7 9
 	"unsafe"
8 10
 
... ...
@@ -12,30 +14,71 @@ import (
12 12
 // processParameters is use to both the input of CreateProcessInComputeSystem
13 13
 // and to convert the parameters to JSON for passing onto the HCS
14 14
 type CreateProcessParams struct {
15
-	ApplicationName                   string
16
-	CommandLine                       string
17
-	WorkingDirectory                  string
18
-	StdInPipe, StdOutPipe, StdErrPipe string
19
-	Environment                       map[string]string
20
-	EmulateConsole                    bool
21
-	ConsoleSize                       [2]int
15
+	ApplicationName  string
16
+	CommandLine      string
17
+	WorkingDirectory string
18
+	Environment      map[string]string
19
+	EmulateConsole   bool
20
+	ConsoleSize      [2]int
21
+}
22
+
23
+// pipe struct used for the stdin/stdout/stderr pipes
24
+type pipe struct {
25
+	handle syscall.Handle
26
+}
27
+
28
+func makePipe(h syscall.Handle) *pipe {
29
+	p := &pipe{h}
30
+	runtime.SetFinalizer(p, (*pipe).closeHandle)
31
+	return p
32
+}
33
+
34
+func (p *pipe) closeHandle() {
35
+	if p.handle != 0 {
36
+		syscall.CloseHandle(p.handle)
37
+		p.handle = 0
38
+	}
39
+}
40
+
41
+func (p *pipe) Close() error {
42
+	p.closeHandle()
43
+	runtime.SetFinalizer(p, nil)
44
+	return nil
45
+}
46
+
47
+func (p *pipe) Read(b []byte) (int, error) {
48
+	// syscall.Read returns 0, nil on ERROR_BROKEN_PIPE, but for
49
+	// our purposes this should indicate EOF. This may be a go bug.
50
+	var read uint32
51
+	err := syscall.ReadFile(p.handle, b, &read, nil)
52
+	if err != nil {
53
+		if err == syscall.ERROR_BROKEN_PIPE {
54
+			return 0, io.EOF
55
+		}
56
+		return 0, err
57
+	}
58
+	return int(read), nil
59
+}
60
+
61
+func (p *pipe) Write(b []byte) (int, error) {
62
+	return syscall.Write(p.handle, b)
22 63
 }
23 64
 
24 65
 // CreateProcessInComputeSystem starts a process in a container. This is invoked, for example,
25 66
 // as a result of docker run, docker exec, or RUN in Dockerfile. If successful,
26 67
 // it returns the PID of the process.
27
-func CreateProcessInComputeSystem(id string, params CreateProcessParams) (processid uint32, err error) {
68
+func CreateProcessInComputeSystem(id string, useStdin bool, useStdout bool, useStderr bool, params CreateProcessParams) (processid uint32, stdin io.WriteCloser, stdout io.ReadCloser, stderr io.ReadCloser, err error) {
28 69
 
29 70
 	title := "HCSShim::CreateProcessInComputeSystem"
30 71
 	logrus.Debugf(title+"id=%s params=%s", id, params)
31 72
 
32 73
 	// Load the DLL and get a handle to the procedure we need
33
-	dll, proc, err := loadAndFind(procCreateProcessInComputeSystem)
74
+	dll, proc, err := loadAndFind(procCreateProcessWithStdHandlesInComputeSystem)
34 75
 	if dll != nil {
35 76
 		defer dll.Release()
36 77
 	}
37 78
 	if err != nil {
38
-		return 0, err
79
+		return
39 80
 	}
40 81
 
41 82
 	// Convert id to uint16 pointer for calling the procedure
... ...
@@ -43,7 +86,7 @@ func CreateProcessInComputeSystem(id string, params CreateProcessParams) (proces
43 43
 	if err != nil {
44 44
 		err = fmt.Errorf(title+" - Failed conversion of id %s to pointer %s", id, err)
45 45
 		logrus.Error(err)
46
-		return 0, err
46
+		return
47 47
 	}
48 48
 
49 49
 	// If we are not emulating a console, ignore any console size passed to us
... ...
@@ -55,13 +98,13 @@ func CreateProcessInComputeSystem(id string, params CreateProcessParams) (proces
55 55
 	paramsJson, err := json.Marshal(params)
56 56
 	if err != nil {
57 57
 		err = fmt.Errorf(title+" - Failed to marshall params %v %s", params, err)
58
-		return 0, err
58
+		return
59 59
 	}
60 60
 
61 61
 	// Convert paramsJson to uint16 pointer for calling the procedure
62 62
 	paramsJsonp, err := syscall.UTF16PtrFromString(string(paramsJson))
63 63
 	if err != nil {
64
-		return 0, err
64
+		return
65 65
 	}
66 66
 
67 67
 	// Get a POINTER to variable to take the pid outparm
... ...
@@ -69,11 +112,26 @@ func CreateProcessInComputeSystem(id string, params CreateProcessParams) (proces
69 69
 
70 70
 	logrus.Debugf(title+" - Calling the procedure itself %s %s", id, paramsJson)
71 71
 
72
+	var stdinHandle, stdoutHandle, stderrHandle syscall.Handle
73
+	var stdinParam, stdoutParam, stderrParam uintptr
74
+	if useStdin {
75
+		stdinParam = uintptr(unsafe.Pointer(&stdinHandle))
76
+	}
77
+	if useStdout {
78
+		stdoutParam = uintptr(unsafe.Pointer(&stdoutHandle))
79
+	}
80
+	if useStderr {
81
+		stderrParam = uintptr(unsafe.Pointer(&stderrHandle))
82
+	}
83
+
72 84
 	// Call the procedure itself.
73 85
 	r1, _, _ := proc.Call(
74 86
 		uintptr(unsafe.Pointer(idp)),
75 87
 		uintptr(unsafe.Pointer(paramsJsonp)),
76
-		uintptr(unsafe.Pointer(pid)))
88
+		uintptr(unsafe.Pointer(pid)),
89
+		stdinParam,
90
+		stdoutParam,
91
+		stderrParam)
77 92
 
78 93
 	use(unsafe.Pointer(idp))
79 94
 	use(unsafe.Pointer(paramsJsonp))
... ...
@@ -81,9 +139,19 @@ func CreateProcessInComputeSystem(id string, params CreateProcessParams) (proces
81 81
 	if r1 != 0 {
82 82
 		err = fmt.Errorf(title+" - Win32 API call returned error r1=%d err=%s id=%s params=%v", r1, syscall.Errno(r1), id, params)
83 83
 		logrus.Error(err)
84
-		return 0, err
84
+		return
85
+	}
86
+
87
+	if useStdin {
88
+		stdin = makePipe(stdinHandle)
89
+	}
90
+	if useStdout {
91
+		stdout = makePipe(stdoutHandle)
92
+	}
93
+	if useStderr {
94
+		stderr = makePipe(stderrHandle)
85 95
 	}
86 96
 
87 97
 	logrus.Debugf(title+" - succeeded id=%s params=%s pid=%d", id, paramsJson, *pid)
88
-	return *pid, nil
98
+	return *pid, stdin, stdout, stderr, nil
89 99
 }
... ...
@@ -15,5 +15,5 @@ func NewGUID(source string) *GUID {
15 15
 }
16 16
 
17 17
 func (g *GUID) ToString() string {
18
-	return fmt.Sprintf("%x-%x-%x-%x-%x", g[0:4], g[4:6], g[6:8], g[8:10], g[10:])
18
+	return fmt.Sprintf("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x-%02x", g[3], g[2], g[1], g[0], g[5], g[4], g[7], g[6], g[8:10], g[10:])
19 19
 }
... ...
@@ -16,14 +16,14 @@ const (
16 16
 	shimDLLName = "vmcompute.dll"
17 17
 
18 18
 	// Container related functions in the shim DLL
19
-	procCreateComputeSystem             = "CreateComputeSystem"
20
-	procStartComputeSystem              = "StartComputeSystem"
21
-	procCreateProcessInComputeSystem    = "CreateProcessInComputeSystem"
22
-	procWaitForProcessInComputeSystem   = "WaitForProcessInComputeSystem"
23
-	procShutdownComputeSystem           = "ShutdownComputeSystem"
24
-	procTerminateComputeSystem          = "TerminateComputeSystem"
25
-	procTerminateProcessInComputeSystem = "TerminateProcessInComputeSystem"
26
-	procResizeConsoleInComputeSystem    = "ResizeConsoleInComputeSystem"
19
+	procCreateComputeSystem                        = "CreateComputeSystem"
20
+	procStartComputeSystem                         = "StartComputeSystem"
21
+	procCreateProcessWithStdHandlesInComputeSystem = "CreateProcessWithStdHandlesInComputeSystem"
22
+	procWaitForProcessInComputeSystem              = "WaitForProcessInComputeSystem"
23
+	procShutdownComputeSystem                      = "ShutdownComputeSystem"
24
+	procTerminateComputeSystem                     = "TerminateComputeSystem"
25
+	procTerminateProcessInComputeSystem            = "TerminateProcessInComputeSystem"
26
+	procResizeConsoleInComputeSystem               = "ResizeConsoleInComputeSystem"
27 27
 
28 28
 	// Storage related functions in the shim DLL
29 29
 	procLayerExists         = "LayerExists"
... ...
@@ -39,6 +39,7 @@ const (
39 39
 	procExportLayer         = "ExportLayer"
40 40
 	procImportLayer         = "ImportLayer"
41 41
 	procGetSharedBaseImages = "GetBaseImages"
42
+	procNameToGuid          = "NameToGuid"
42 43
 
43 44
 	// Name of the standard OLE dll
44 45
 	oleDLLName = "Ole32.dll"
... ...
@@ -4,6 +4,7 @@ package hcsshim
4 4
 // functionality.
5 5
 
6 6
 import (
7
+	"path/filepath"
7 8
 	"syscall"
8 9
 
9 10
 	"github.com/Sirupsen/logrus"
... ...
@@ -84,9 +85,14 @@ func layerPathsToDescriptors(parentLayerPaths []string) ([]WC_LAYER_DESCRIPTOR,
84 84
 	var layers []WC_LAYER_DESCRIPTOR
85 85
 
86 86
 	for i := 0; i < len(parentLayerPaths); i++ {
87
-		// Create a layer descriptor, using the folder path
87
+		// Create a layer descriptor, using the folder name
88 88
 		// as the source for a GUID LayerId
89
-		g := NewGUID(parentLayerPaths[i])
89
+		_, folderName := filepath.Split(parentLayerPaths[i])
90
+		g, err := NameToGuid(folderName)
91
+		if err != nil {
92
+			logrus.Debugf("Failed to convert name to guid %s", err)
93
+			return nil, err
94
+		}
90 95
 
91 96
 		p, err := syscall.UTF16PtrFromString(parentLayerPaths[i])
92 97
 		if err != nil {
... ...
@@ -95,7 +101,7 @@ func layerPathsToDescriptors(parentLayerPaths []string) ([]WC_LAYER_DESCRIPTOR,
95 95
 		}
96 96
 
97 97
 		layers = append(layers, WC_LAYER_DESCRIPTOR{
98
-			LayerId: *g,
98
+			LayerId: g,
99 99
 			Flags:   0,
100 100
 			Pathp:   p,
101 101
 		})
102 102
new file mode 100644
... ...
@@ -0,0 +1,46 @@
0
+package hcsshim
1
+
2
+import (
3
+	"fmt"
4
+	"syscall"
5
+	"unsafe"
6
+
7
+	"github.com/Sirupsen/logrus"
8
+)
9
+
10
+func NameToGuid(name string) (id GUID, err error) {
11
+	title := "hcsshim::NameToGuid "
12
+	logrus.Debugf(title+"Name %s", name)
13
+
14
+	// Load the DLL and get a handle to the procedure we need
15
+	dll, proc, err := loadAndFind(procNameToGuid)
16
+	if dll != nil {
17
+		defer dll.Release()
18
+	}
19
+	if err != nil {
20
+		return
21
+	}
22
+
23
+	// Convert name to uint16 pointer for calling the procedure
24
+	namep, err := syscall.UTF16PtrFromString(name)
25
+	if err != nil {
26
+		err = fmt.Errorf(title+" - Failed conversion of name %s to pointer %s", name, err)
27
+		logrus.Error(err)
28
+		return
29
+	}
30
+
31
+	// Call the procedure itself.
32
+	logrus.Debugf("Calling proc")
33
+	r1, _, _ := proc.Call(
34
+		uintptr(unsafe.Pointer(namep)),
35
+		uintptr(unsafe.Pointer(&id)))
36
+
37
+	if r1 != 0 {
38
+		err = fmt.Errorf(title+" - Win32 API call returned error r1=%d err=%s name=%s",
39
+			r1, syscall.Errno(r1), name)
40
+		logrus.Error(err)
41
+		return
42
+	}
43
+
44
+	return
45
+}
0 46
deleted file mode 100644
... ...
@@ -1,22 +0,0 @@
1
-# Compiled Object files, Static and Dynamic libs (Shared Objects)
2
-*.o
3
-*.a
4
-*.so
5
-
6
-# Folders
7
-_obj
8
-_test
9
-
10
-# Architecture specific extensions/prefixes
11
-*.[568vq]
12
-[568vq].out
13
-
14
-*.cgo1.go
15
-*.cgo2.c
16
-_cgo_defun.c
17
-_cgo_gotypes.go
18
-_cgo_export.*
19
-
20
-_testmain.go
21
-
22
-*.exe
23 1
deleted file mode 100644
... ...
@@ -1,8 +0,0 @@
1
-The MIT License (MIT)
2
-Copyright (c) 2013 npipe authors
3
-
4
-Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
-
6
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
-
8
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 1
\ No newline at end of file
10 2
deleted file mode 100644
... ...
@@ -1,308 +0,0 @@
1
-npipe  [![Build status](https://ci.appveyor.com/api/projects/status/00vuepirsot29qwi)](https://ci.appveyor.com/project/natefinch/npipe) [![GoDoc](https://godoc.org/gopkg.in/natefinch/npipe.v2?status.svg)](https://godoc.org/gopkg.in/natefinch/npipe.v2)
2
-=====
3
-Package npipe provides a pure Go wrapper around Windows named pipes.
4
-
5
-Windows named pipe documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365780
6
-
7
-Note that the code lives at https://github.com/natefinch/npipe (v2 branch)
8
-but should be imported as gopkg.in/natefinch/npipe.v2 (the package name is
9
-still npipe).
10
-
11
-npipe provides an interface based on stdlib's net package, with Dial, Listen,
12
-and Accept functions, as well as associated implementations of net.Conn and
13
-net.Listener.  It supports rpc over the connection.
14
-
15
-### Notes
16
-* Deadlines for reading/writing to the connection are only functional in Windows Vista/Server 2008 and above, due to limitations with the Windows API.
17
-
18
-* The pipes support byte mode only (no support for message mode)
19
-
20
-### Examples
21
-The Dial function connects a client to a named pipe:
22
-
23
-
24
-	conn, err := npipe.Dial(`\\.\pipe\mypipename`)
25
-	if err != nil {
26
-		<handle error>
27
-	}
28
-	fmt.Fprintf(conn, "Hi server!\n")
29
-	msg, err := bufio.NewReader(conn).ReadString('\n')
30
-	...
31
-
32
-The Listen function creates servers:
33
-
34
-
35
-	ln, err := npipe.Listen(`\\.\pipe\mypipename`)
36
-	if err != nil {
37
-		// handle error
38
-	}
39
-	for {
40
-		conn, err := ln.Accept()
41
-		if err != nil {
42
-			// handle error
43
-			continue
44
-		}
45
-		go handleConnection(conn)
46
-	}
47
-
48
-
49
-
50
-
51
-
52
-## Variables
53
-``` go
54
-var ErrClosed = PipeError{"Pipe has been closed.", false}
55
-```
56
-ErrClosed is the error returned by PipeListener.Accept when Close is called
57
-on the PipeListener.
58
-
59
-
60
-
61
-## type PipeAddr
62
-``` go
63
-type PipeAddr string
64
-```
65
-PipeAddr represents the address of a named pipe.
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-### func (PipeAddr) Network
78
-``` go
79
-func (a PipeAddr) Network() string
80
-```
81
-Network returns the address's network name, "pipe".
82
-
83
-
84
-
85
-### func (PipeAddr) String
86
-``` go
87
-func (a PipeAddr) String() string
88
-```
89
-String returns the address of the pipe
90
-
91
-
92
-
93
-## type PipeConn
94
-``` go
95
-type PipeConn struct {
96
-    // contains filtered or unexported fields
97
-}
98
-```
99
-PipeConn is the implementation of the net.Conn interface for named pipe connections.
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-### func Dial
110
-``` go
111
-func Dial(address string) (*PipeConn, error)
112
-```
113
-Dial connects to a named pipe with the given address. If the specified pipe is not available,
114
-it will wait indefinitely for the pipe to become available.
115
-
116
-The address must be of the form \\.\\pipe\<name> for local pipes and \\<computer>\pipe\<name>
117
-for remote pipes.
118
-
119
-Dial will return a PipeError if you pass in a badly formatted pipe name.
120
-
121
-Examples:
122
-
123
-
124
-	// local pipe
125
-	conn, err := Dial(`\\.\pipe\mypipename`)
126
-	
127
-	// remote pipe
128
-	conn, err := Dial(`\\othercomp\pipe\mypipename`)
129
-
130
-
131
-### func DialTimeout
132
-``` go
133
-func DialTimeout(address string, timeout time.Duration) (*PipeConn, error)
134
-```
135
-DialTimeout acts like Dial, but will time out after the duration of timeout
136
-
137
-
138
-
139
-
140
-### func (\*PipeConn) Close
141
-``` go
142
-func (c *PipeConn) Close() error
143
-```
144
-Close closes the connection.
145
-
146
-
147
-
148
-### func (\*PipeConn) LocalAddr
149
-``` go
150
-func (c *PipeConn) LocalAddr() net.Addr
151
-```
152
-LocalAddr returns the local network address.
153
-
154
-
155
-
156
-### func (\*PipeConn) Read
157
-``` go
158
-func (c *PipeConn) Read(b []byte) (int, error)
159
-```
160
-Read implements the net.Conn Read method.
161
-
162
-
163
-
164
-### func (\*PipeConn) RemoteAddr
165
-``` go
166
-func (c *PipeConn) RemoteAddr() net.Addr
167
-```
168
-RemoteAddr returns the remote network address.
169
-
170
-
171
-
172
-### func (\*PipeConn) SetDeadline
173
-``` go
174
-func (c *PipeConn) SetDeadline(t time.Time) error
175
-```
176
-SetDeadline implements the net.Conn SetDeadline method.
177
-Note that timeouts are only supported on Windows Vista/Server 2008 and above
178
-
179
-
180
-
181
-### func (\*PipeConn) SetReadDeadline
182
-``` go
183
-func (c *PipeConn) SetReadDeadline(t time.Time) error
184
-```
185
-SetReadDeadline implements the net.Conn SetReadDeadline method.
186
-Note that timeouts are only supported on Windows Vista/Server 2008 and above
187
-
188
-
189
-
190
-### func (\*PipeConn) SetWriteDeadline
191
-``` go
192
-func (c *PipeConn) SetWriteDeadline(t time.Time) error
193
-```
194
-SetWriteDeadline implements the net.Conn SetWriteDeadline method.
195
-Note that timeouts are only supported on Windows Vista/Server 2008 and above
196
-
197
-
198
-
199
-### func (\*PipeConn) Write
200
-``` go
201
-func (c *PipeConn) Write(b []byte) (int, error)
202
-```
203
-Write implements the net.Conn Write method.
204
-
205
-
206
-
207
-## type PipeError
208
-``` go
209
-type PipeError struct {
210
-    // contains filtered or unexported fields
211
-}
212
-```
213
-PipeError is an error related to a call to a pipe
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-### func (PipeError) Error
226
-``` go
227
-func (e PipeError) Error() string
228
-```
229
-Error implements the error interface
230
-
231
-
232
-
233
-### func (PipeError) Temporary
234
-``` go
235
-func (e PipeError) Temporary() bool
236
-```
237
-Temporary implements net.AddrError.Temporary()
238
-
239
-
240
-
241
-### func (PipeError) Timeout
242
-``` go
243
-func (e PipeError) Timeout() bool
244
-```
245
-Timeout implements net.AddrError.Timeout()
246
-
247
-
248
-
249
-## type PipeListener
250
-``` go
251
-type PipeListener struct {
252
-    // contains filtered or unexported fields
253
-}
254
-```
255
-PipeListener is a named pipe listener. Clients should typically
256
-use variables of type net.Listener instead of assuming named pipe.
257
-
258
-
259
-
260
-
261
-
262
-
263
-
264
-
265
-
266
-### func Listen
267
-``` go
268
-func Listen(address string) (*PipeListener, error)
269
-```
270
-Listen returns a new PipeListener that will listen on a pipe with the given
271
-address. The address must be of the form \\.\pipe\<name>
272
-
273
-Listen will return a PipeError for an incorrectly formatted pipe name.
274
-
275
-
276
-
277
-
278
-### func (\*PipeListener) Accept
279
-``` go
280
-func (l *PipeListener) Accept() (net.Conn, error)
281
-```
282
-Accept implements the Accept method in the net.Listener interface; it
283
-waits for the next call and returns a generic net.Conn.
284
-
285
-
286
-
287
-### func (\*PipeListener) AcceptPipe
288
-``` go
289
-func (l *PipeListener) AcceptPipe() (*PipeConn, error)
290
-```
291
-AcceptPipe accepts the next incoming call and returns the new connection.
292
-
293
-
294
-
295
-### func (\*PipeListener) Addr
296
-``` go
297
-func (l *PipeListener) Addr() net.Addr
298
-```
299
-Addr returns the listener's network address, a PipeAddr.
300
-
301
-
302
-
303
-### func (\*PipeListener) Close
304
-``` go
305
-func (l *PipeListener) Close() error
306
-```
307
-Close stops listening on the address.
308
-Already Accepted connections are not closed.
309 1
deleted file mode 100644
... ...
@@ -1,50 +0,0 @@
1
-// Copyright 2013 Nate Finch. All rights reserved.
2
-// Use of this source code is governed by an MIT-style
3
-// license that can be found in the LICENSE file.
4
-
5
-// Package npipe provides a pure Go wrapper around Windows named pipes.
6
-//
7
-// !! Note, this package is Windows-only.  There is no code to compile on linux.
8
-//
9
-// Windows named pipe documentation: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365780
10
-//
11
-// Note that the code lives at https://github.com/natefinch/npipe (v2 branch)
12
-// but should be imported as gopkg.in/natefinch/npipe.v2 (the package name is
13
-// still npipe).
14
-//
15
-// npipe provides an interface based on stdlib's net package, with Dial, Listen,
16
-// and Accept functions, as well as associated implementations of net.Conn and
17
-// net.Listener.  It supports rpc over the connection.
18
-//
19
-// Notes
20
-//
21
-// * Deadlines for reading/writing to the connection are only functional in Windows Vista/Server 2008 and above, due to limitations with the Windows API.
22
-//
23
-// * The pipes support byte mode only (no support for message mode)
24
-//
25
-// Examples
26
-//
27
-// The Dial function connects a client to a named pipe:
28
-//   conn, err := npipe.Dial(`\\.\pipe\mypipename`)
29
-//   if err != nil {
30
-//   	<handle error>
31
-//   }
32
-//   fmt.Fprintf(conn, "Hi server!\n")
33
-//   msg, err := bufio.NewReader(conn).ReadString('\n')
34
-//   ...
35
-//
36
-// The Listen function creates servers:
37
-//
38
-//   ln, err := npipe.Listen(`\\.\pipe\mypipename`)
39
-//   if err != nil {
40
-//   	// handle error
41
-//   }
42
-//   for {
43
-//   	conn, err := ln.Accept()
44
-//   	if err != nil {
45
-//   		// handle error
46
-//   		continue
47
-//   	}
48
-//   	go handleConnection(conn)
49
-//   }
50
-package npipe
51 1
deleted file mode 100755
... ...
@@ -1,518 +0,0 @@
1
-package npipe
2
-
3
-//sys createNamedPipe(name *uint16, openMode uint32, pipeMode uint32, maxInstances uint32, outBufSize uint32, inBufSize uint32, defaultTimeout uint32, sa *syscall.SecurityAttributes) (handle syscall.Handle, err error)  [failretval==syscall.InvalidHandle] = CreateNamedPipeW
4
-//sys connectNamedPipe(handle syscall.Handle, overlapped *syscall.Overlapped) (err error) = ConnectNamedPipe
5
-//sys disconnectNamedPipe(handle syscall.Handle) (err error) = DisconnectNamedPipe
6
-//sys waitNamedPipe(name *uint16, timeout uint32) (err error) = WaitNamedPipeW
7
-//sys createEvent(sa *syscall.SecurityAttributes, manualReset bool, initialState bool, name *uint16) (handle syscall.Handle, err error) [failretval==syscall.InvalidHandle] = CreateEventW
8
-//sys getOverlappedResult(handle syscall.Handle, overlapped *syscall.Overlapped, transferred *uint32, wait bool) (err error) = GetOverlappedResult
9
-//sys cancelIoEx(handle syscall.Handle, overlapped *syscall.Overlapped) (err error) = CancelIoEx
10
-
11
-import (
12
-	"fmt"
13
-	"io"
14
-	"net"
15
-	"sync"
16
-	"syscall"
17
-	"time"
18
-)
19
-
20
-const (
21
-	// openMode
22
-	pipe_access_duplex   = 0x3
23
-	pipe_access_inbound  = 0x1
24
-	pipe_access_outbound = 0x2
25
-
26
-	// openMode write flags
27
-	file_flag_first_pipe_instance = 0x00080000
28
-	file_flag_write_through       = 0x80000000
29
-	file_flag_overlapped          = 0x40000000
30
-
31
-	// openMode ACL flags
32
-	write_dac              = 0x00040000
33
-	write_owner            = 0x00080000
34
-	access_system_security = 0x01000000
35
-
36
-	// pipeMode
37
-	pipe_type_byte    = 0x0
38
-	pipe_type_message = 0x4
39
-
40
-	// pipeMode read mode flags
41
-	pipe_readmode_byte    = 0x0
42
-	pipe_readmode_message = 0x2
43
-
44
-	// pipeMode wait mode flags
45
-	pipe_wait   = 0x0
46
-	pipe_nowait = 0x1
47
-
48
-	// pipeMode remote-client mode flags
49
-	pipe_accept_remote_clients = 0x0
50
-	pipe_reject_remote_clients = 0x8
51
-
52
-	pipe_unlimited_instances = 255
53
-
54
-	nmpwait_wait_forever = 0xFFFFFFFF
55
-
56
-	// the two not-an-errors below occur if a client connects to the pipe between
57
-	// the server's CreateNamedPipe and ConnectNamedPipe calls.
58
-	error_no_data        syscall.Errno = 0xE8
59
-	error_pipe_connected syscall.Errno = 0x217
60
-	error_pipe_busy      syscall.Errno = 0xE7
61
-	error_sem_timeout    syscall.Errno = 0x79
62
-
63
-	error_bad_pathname syscall.Errno = 0xA1
64
-	error_invalid_name syscall.Errno = 0x7B
65
-
66
-	error_io_incomplete syscall.Errno = 0x3e4
67
-)
68
-
69
-var _ net.Conn = (*PipeConn)(nil)
70
-var _ net.Listener = (*PipeListener)(nil)
71
-
72
-// ErrClosed is the error returned by PipeListener.Accept when Close is called
73
-// on the PipeListener.
74
-var ErrClosed = PipeError{"Pipe has been closed.", false}
75
-
76
-// PipeError is an error related to a call to a pipe
77
-type PipeError struct {
78
-	msg     string
79
-	timeout bool
80
-}
81
-
82
-// Error implements the error interface
83
-func (e PipeError) Error() string {
84
-	return e.msg
85
-}
86
-
87
-// Timeout implements net.AddrError.Timeout()
88
-func (e PipeError) Timeout() bool {
89
-	return e.timeout
90
-}
91
-
92
-// Temporary implements net.AddrError.Temporary()
93
-func (e PipeError) Temporary() bool {
94
-	return false
95
-}
96
-
97
-// Dial connects to a named pipe with the given address. If the specified pipe is not available,
98
-// it will wait indefinitely for the pipe to become available.
99
-//
100
-// The address must be of the form \\.\\pipe\<name> for local pipes and \\<computer>\pipe\<name>
101
-// for remote pipes.
102
-//
103
-// Dial will return a PipeError if you pass in a badly formatted pipe name.
104
-//
105
-// Examples:
106
-//   // local pipe
107
-//   conn, err := Dial(`\\.\pipe\mypipename`)
108
-//
109
-//   // remote pipe
110
-//   conn, err := Dial(`\\othercomp\pipe\mypipename`)
111
-func Dial(address string) (*PipeConn, error) {
112
-	for {
113
-		conn, err := dial(address, nmpwait_wait_forever)
114
-		if err == nil {
115
-			return conn, nil
116
-		}
117
-		if isPipeNotReady(err) {
118
-			<-time.After(100 * time.Millisecond)
119
-			continue
120
-		}
121
-		return nil, err
122
-	}
123
-}
124
-
125
-// DialTimeout acts like Dial, but will time out after the duration of timeout
126
-func DialTimeout(address string, timeout time.Duration) (*PipeConn, error) {
127
-	deadline := time.Now().Add(timeout)
128
-
129
-	now := time.Now()
130
-	for now.Before(deadline) {
131
-		millis := uint32(deadline.Sub(now) / time.Millisecond)
132
-		conn, err := dial(address, millis)
133
-		if err == nil {
134
-			return conn, nil
135
-		}
136
-		if err == error_sem_timeout {
137
-			// This is WaitNamedPipe's timeout error, so we know we're done
138
-			return nil, PipeError{fmt.Sprintf(
139
-				"Timed out waiting for pipe '%s' to come available", address), true}
140
-		}
141
-		if isPipeNotReady(err) {
142
-			left := deadline.Sub(time.Now())
143
-			retry := 100 * time.Millisecond
144
-			if left > retry {
145
-				<-time.After(retry)
146
-			} else {
147
-				<-time.After(left - time.Millisecond)
148
-			}
149
-			now = time.Now()
150
-			continue
151
-		}
152
-		return nil, err
153
-	}
154
-	return nil, PipeError{fmt.Sprintf(
155
-		"Timed out waiting for pipe '%s' to come available", address), true}
156
-}
157
-
158
-// isPipeNotReady checks the error to see if it indicates the pipe is not ready
159
-func isPipeNotReady(err error) bool {
160
-	// Pipe Busy means another client just grabbed the open pipe end,
161
-	// and the server hasn't made a new one yet.
162
-	// File Not Found means the server hasn't created the pipe yet.
163
-	// Neither is a fatal error.
164
-
165
-	return err == syscall.ERROR_FILE_NOT_FOUND || err == error_pipe_busy
166
-}
167
-
168
-// newOverlapped creates a structure used to track asynchronous
169
-// I/O requests that have been issued.
170
-func newOverlapped() (*syscall.Overlapped, error) {
171
-	event, err := createEvent(nil, true, true, nil)
172
-	if err != nil {
173
-		return nil, err
174
-	}
175
-	return &syscall.Overlapped{HEvent: event}, nil
176
-}
177
-
178
-// waitForCompletion waits for an asynchronous I/O request referred to by overlapped to complete.
179
-// This function returns the number of bytes transferred by the operation and an error code if
180
-// applicable (nil otherwise).
181
-func waitForCompletion(handle syscall.Handle, overlapped *syscall.Overlapped) (uint32, error) {
182
-	_, err := syscall.WaitForSingleObject(overlapped.HEvent, syscall.INFINITE)
183
-	if err != nil {
184
-		return 0, err
185
-	}
186
-	var transferred uint32
187
-	err = getOverlappedResult(handle, overlapped, &transferred, true)
188
-	return transferred, err
189
-}
190
-
191
-// dial is a helper to initiate a connection to a named pipe that has been started by a server.
192
-// The timeout is only enforced if the pipe server has already created the pipe, otherwise
193
-// this function will return immediately.
194
-func dial(address string, timeout uint32) (*PipeConn, error) {
195
-	name, err := syscall.UTF16PtrFromString(string(address))
196
-	if err != nil {
197
-		return nil, err
198
-	}
199
-	// If at least one instance of the pipe has been created, this function
200
-	// will wait timeout milliseconds for it to become available.
201
-	// It will return immediately regardless of timeout, if no instances
202
-	// of the named pipe have been created yet.
203
-	// If this returns with no error, there is a pipe available.
204
-	if err := waitNamedPipe(name, timeout); err != nil {
205
-		if err == error_bad_pathname {
206
-			// badly formatted pipe name
207
-			return nil, badAddr(address)
208
-		}
209
-		return nil, err
210
-	}
211
-	pathp, err := syscall.UTF16PtrFromString(address)
212
-	if err != nil {
213
-		return nil, err
214
-	}
215
-	handle, err := syscall.CreateFile(pathp, syscall.GENERIC_READ|syscall.GENERIC_WRITE,
216
-		uint32(syscall.FILE_SHARE_READ|syscall.FILE_SHARE_WRITE), nil, syscall.OPEN_EXISTING,
217
-		syscall.FILE_FLAG_OVERLAPPED, 0)
218
-	if err != nil {
219
-		return nil, err
220
-	}
221
-	return &PipeConn{handle: handle, addr: PipeAddr(address)}, nil
222
-}
223
-
224
-// Listen returns a new PipeListener that will listen on a pipe with the given
225
-// address. The address must be of the form \\.\pipe\<name>
226
-//
227
-// Listen will return a PipeError for an incorrectly formatted pipe name.
228
-func Listen(address string) (*PipeListener, error) {
229
-	handle, err := createPipe(address, true)
230
-	if err == error_invalid_name {
231
-		return nil, badAddr(address)
232
-	}
233
-	if err != nil {
234
-		return nil, err
235
-	}
236
-	return &PipeListener{
237
-		addr:   PipeAddr(address),
238
-		handle: handle,
239
-	}, nil
240
-}
241
-
242
-// PipeListener is a named pipe listener. Clients should typically
243
-// use variables of type net.Listener instead of assuming named pipe.
244
-type PipeListener struct {
245
-	addr   PipeAddr
246
-	handle syscall.Handle
247
-	closed bool
248
-
249
-	// acceptHandle contains the current handle waiting for
250
-	// an incoming connection or nil.
251
-	acceptHandle syscall.Handle
252
-	// acceptOverlapped is set before waiting on a connection.
253
-	// If not waiting, it is nil.
254
-	acceptOverlapped *syscall.Overlapped
255
-	// acceptMutex protects the handle and overlapped structure.
256
-	acceptMutex sync.Mutex
257
-}
258
-
259
-// Accept implements the Accept method in the net.Listener interface; it
260
-// waits for the next call and returns a generic net.Conn.
261
-func (l *PipeListener) Accept() (net.Conn, error) {
262
-	c, err := l.AcceptPipe()
263
-	for err == error_no_data {
264
-		// Ignore clients that connect and immediately disconnect.
265
-		c, err = l.AcceptPipe()
266
-	}
267
-	if err != nil {
268
-		return nil, err
269
-	}
270
-	return c, nil
271
-}
272
-
273
-// AcceptPipe accepts the next incoming call and returns the new connection.
274
-// It might return an error if a client connected and immediately cancelled
275
-// the connection.
276
-func (l *PipeListener) AcceptPipe() (*PipeConn, error) {
277
-	if l == nil || l.addr == "" || l.closed {
278
-		return nil, syscall.EINVAL
279
-	}
280
-
281
-	// the first time we call accept, the handle will have been created by the Listen
282
-	// call. This is to prevent race conditions where the client thinks the server
283
-	// isn't listening because it hasn't actually called create yet. After the first time, we'll
284
-	// have to create a new handle each time
285
-	handle := l.handle
286
-	if handle == 0 {
287
-		var err error
288
-		handle, err = createPipe(string(l.addr), false)
289
-		if err != nil {
290
-			return nil, err
291
-		}
292
-	} else {
293
-		l.handle = 0
294
-	}
295
-
296
-	overlapped, err := newOverlapped()
297
-	if err != nil {
298
-		return nil, err
299
-	}
300
-	defer syscall.CloseHandle(overlapped.HEvent)
301
-	if err := connectNamedPipe(handle, overlapped); err != nil && err != error_pipe_connected {
302
-		if err == error_io_incomplete || err == syscall.ERROR_IO_PENDING {
303
-			l.acceptMutex.Lock()
304
-			l.acceptOverlapped = overlapped
305
-			l.acceptHandle = handle
306
-			l.acceptMutex.Unlock()
307
-			defer func() {
308
-				l.acceptMutex.Lock()
309
-				l.acceptOverlapped = nil
310
-				l.acceptHandle = 0
311
-				l.acceptMutex.Unlock()
312
-			}()
313
-
314
-			_, err = waitForCompletion(handle, overlapped)
315
-		}
316
-		if err == syscall.ERROR_OPERATION_ABORTED {
317
-			// Return error compatible to net.Listener.Accept() in case the
318
-			// listener was closed.
319
-			return nil, ErrClosed
320
-		}
321
-		if err != nil {
322
-			return nil, err
323
-		}
324
-	}
325
-	return &PipeConn{handle: handle, addr: l.addr}, nil
326
-}
327
-
328
-// Close stops listening on the address.
329
-// Already Accepted connections are not closed.
330
-func (l *PipeListener) Close() error {
331
-	if l.closed {
332
-		return nil
333
-	}
334
-	l.closed = true
335
-	if l.handle != 0 {
336
-		err := disconnectNamedPipe(l.handle)
337
-		if err != nil {
338
-			return err
339
-		}
340
-		err = syscall.CloseHandle(l.handle)
341
-		if err != nil {
342
-			return err
343
-		}
344
-		l.handle = 0
345
-	}
346
-	l.acceptMutex.Lock()
347
-	defer l.acceptMutex.Unlock()
348
-	if l.acceptOverlapped != nil && l.acceptHandle != 0 {
349
-		// Cancel the pending IO. This call does not block, so it is safe
350
-		// to hold onto the mutex above.
351
-		if err := cancelIoEx(l.acceptHandle, l.acceptOverlapped); err != nil {
352
-			return err
353
-		}
354
-		err := syscall.CloseHandle(l.acceptOverlapped.HEvent)
355
-		if err != nil {
356
-			return err
357
-		}
358
-		l.acceptOverlapped.HEvent = 0
359
-		err = syscall.CloseHandle(l.acceptHandle)
360
-		if err != nil {
361
-			return err
362
-		}
363
-		l.acceptHandle = 0
364
-	}
365
-	return nil
366
-}
367
-
368
-// Addr returns the listener's network address, a PipeAddr.
369
-func (l *PipeListener) Addr() net.Addr { return l.addr }
370
-
371
-// PipeConn is the implementation of the net.Conn interface for named pipe connections.
372
-type PipeConn struct {
373
-	handle syscall.Handle
374
-	addr   PipeAddr
375
-
376
-	// these aren't actually used yet
377
-	readDeadline  *time.Time
378
-	writeDeadline *time.Time
379
-}
380
-
381
-type iodata struct {
382
-	n   uint32
383
-	err error
384
-}
385
-
386
-// completeRequest looks at iodata to see if a request is pending. If so, it waits for it to either complete or to
387
-// abort due to hitting the specified deadline. Deadline may be set to nil to wait forever. If no request is pending,
388
-// the content of iodata is returned.
389
-func (c *PipeConn) completeRequest(data iodata, deadline *time.Time, overlapped *syscall.Overlapped) (int, error) {
390
-	if data.err == error_io_incomplete || data.err == syscall.ERROR_IO_PENDING {
391
-		var timer <-chan time.Time
392
-		if deadline != nil {
393
-			if timeDiff := deadline.Sub(time.Now()); timeDiff > 0 {
394
-				timer = time.After(timeDiff)
395
-			}
396
-		}
397
-		done := make(chan iodata)
398
-		go func() {
399
-			n, err := waitForCompletion(c.handle, overlapped)
400
-			done <- iodata{n, err}
401
-		}()
402
-		select {
403
-		case data = <-done:
404
-		case <-timer:
405
-			syscall.CancelIoEx(c.handle, overlapped)
406
-			data = iodata{0, timeout(c.addr.String())}
407
-		}
408
-	}
409
-	// Windows will produce ERROR_BROKEN_PIPE upon closing
410
-	// a handle on the other end of a connection. Go RPC
411
-	// expects an io.EOF error in this case.
412
-	if data.err == syscall.ERROR_BROKEN_PIPE {
413
-		data.err = io.EOF
414
-	}
415
-	return int(data.n), data.err
416
-}
417
-
418
-// Read implements the net.Conn Read method.
419
-func (c *PipeConn) Read(b []byte) (int, error) {
420
-	// Use ReadFile() rather than Read() because the latter
421
-	// contains a workaround that eats ERROR_BROKEN_PIPE.
422
-	overlapped, err := newOverlapped()
423
-	if err != nil {
424
-		return 0, err
425
-	}
426
-	defer syscall.CloseHandle(overlapped.HEvent)
427
-	var n uint32
428
-	err = syscall.ReadFile(c.handle, b, &n, overlapped)
429
-	return c.completeRequest(iodata{n, err}, c.readDeadline, overlapped)
430
-}
431
-
432
-// Write implements the net.Conn Write method.
433
-func (c *PipeConn) Write(b []byte) (int, error) {
434
-	overlapped, err := newOverlapped()
435
-	if err != nil {
436
-		return 0, err
437
-	}
438
-	defer syscall.CloseHandle(overlapped.HEvent)
439
-	var n uint32
440
-	err = syscall.WriteFile(c.handle, b, &n, overlapped)
441
-	return c.completeRequest(iodata{n, err}, c.writeDeadline, overlapped)
442
-}
443
-
444
-// Close closes the connection.
445
-func (c *PipeConn) Close() error {
446
-	return syscall.CloseHandle(c.handle)
447
-}
448
-
449
-// LocalAddr returns the local network address.
450
-func (c *PipeConn) LocalAddr() net.Addr {
451
-	return c.addr
452
-}
453
-
454
-// RemoteAddr returns the remote network address.
455
-func (c *PipeConn) RemoteAddr() net.Addr {
456
-	// not sure what to do here, we don't have remote addr....
457
-	return c.addr
458
-}
459
-
460
-// SetDeadline implements the net.Conn SetDeadline method.
461
-// Note that timeouts are only supported on Windows Vista/Server 2008 and above
462
-func (c *PipeConn) SetDeadline(t time.Time) error {
463
-	c.SetReadDeadline(t)
464
-	c.SetWriteDeadline(t)
465
-	return nil
466
-}
467
-
468
-// SetReadDeadline implements the net.Conn SetReadDeadline method.
469
-// Note that timeouts are only supported on Windows Vista/Server 2008 and above
470
-func (c *PipeConn) SetReadDeadline(t time.Time) error {
471
-	c.readDeadline = &t
472
-	return nil
473
-}
474
-
475
-// SetWriteDeadline implements the net.Conn SetWriteDeadline method.
476
-// Note that timeouts are only supported on Windows Vista/Server 2008 and above
477
-func (c *PipeConn) SetWriteDeadline(t time.Time) error {
478
-	c.writeDeadline = &t
479
-	return nil
480
-}
481
-
482
-// PipeAddr represents the address of a named pipe.
483
-type PipeAddr string
484
-
485
-// Network returns the address's network name, "pipe".
486
-func (a PipeAddr) Network() string { return "pipe" }
487
-
488
-// String returns the address of the pipe
489
-func (a PipeAddr) String() string {
490
-	return string(a)
491
-}
492
-
493
-// createPipe is a helper function to make sure we always create pipes
494
-// with the same arguments, since subsequent calls to create pipe need
495
-// to use the same arguments as the first one. If first is set, fail
496
-// if the pipe already exists.
497
-func createPipe(address string, first bool) (syscall.Handle, error) {
498
-	n, err := syscall.UTF16PtrFromString(address)
499
-	if err != nil {
500
-		return 0, err
501
-	}
502
-	mode := uint32(pipe_access_duplex | syscall.FILE_FLAG_OVERLAPPED)
503
-	if first {
504
-		mode |= file_flag_first_pipe_instance
505
-	}
506
-	return createNamedPipe(n,
507
-		mode,
508
-		pipe_type_byte,
509
-		pipe_unlimited_instances,
510
-		512, 512, 0, nil)
511
-}
512
-
513
-func badAddr(addr string) PipeError {
514
-	return PipeError{fmt.Sprintf("Invalid pipe address '%s'.", addr), false}
515
-}
516
-func timeout(addr string) PipeError {
517
-	return PipeError{fmt.Sprintf("Pipe IO timed out waiting for '%s'", addr), true}
518
-}
519 1
deleted file mode 100644
... ...
@@ -1,124 +0,0 @@
1
-// +build windows
2
-// go build mksyscall_windows.go && ./mksyscall_windows npipe_windows.go
3
-// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
4
-
5
-package npipe
6
-
7
-import "unsafe"
8
-import "syscall"
9
-
10
-var (
11
-	modkernel32 = syscall.NewLazyDLL("kernel32.dll")
12
-
13
-	procCreateNamedPipeW    = modkernel32.NewProc("CreateNamedPipeW")
14
-	procConnectNamedPipe    = modkernel32.NewProc("ConnectNamedPipe")
15
-	procDisconnectNamedPipe = modkernel32.NewProc("DisconnectNamedPipe")
16
-	procWaitNamedPipeW      = modkernel32.NewProc("WaitNamedPipeW")
17
-	procCreateEventW        = modkernel32.NewProc("CreateEventW")
18
-	procGetOverlappedResult = modkernel32.NewProc("GetOverlappedResult")
19
-	procCancelIoEx          = modkernel32.NewProc("CancelIoEx")
20
-)
21
-
22
-func createNamedPipe(name *uint16, openMode uint32, pipeMode uint32, maxInstances uint32, outBufSize uint32, inBufSize uint32, defaultTimeout uint32, sa *syscall.SecurityAttributes) (handle syscall.Handle, err error) {
23
-	r0, _, e1 := syscall.Syscall9(procCreateNamedPipeW.Addr(), 8, uintptr(unsafe.Pointer(name)), uintptr(openMode), uintptr(pipeMode), uintptr(maxInstances), uintptr(outBufSize), uintptr(inBufSize), uintptr(defaultTimeout), uintptr(unsafe.Pointer(sa)), 0)
24
-	handle = syscall.Handle(r0)
25
-	if handle == syscall.InvalidHandle {
26
-		if e1 != 0 {
27
-			err = error(e1)
28
-		} else {
29
-			err = syscall.EINVAL
30
-		}
31
-	}
32
-	return
33
-}
34
-
35
-func cancelIoEx(handle syscall.Handle, overlapped *syscall.Overlapped) (err error) {
36
-	r1, _, e1 := syscall.Syscall(procCancelIoEx.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(overlapped)), 0)
37
-	if r1 == 0 {
38
-		if e1 != 0 {
39
-			err = error(e1)
40
-		} else {
41
-			err = syscall.EINVAL
42
-		}
43
-	}
44
-	return
45
-}
46
-
47
-func connectNamedPipe(handle syscall.Handle, overlapped *syscall.Overlapped) (err error) {
48
-	r1, _, e1 := syscall.Syscall(procConnectNamedPipe.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(overlapped)), 0)
49
-	if r1 == 0 {
50
-		if e1 != 0 {
51
-			err = error(e1)
52
-		} else {
53
-			err = syscall.EINVAL
54
-		}
55
-	}
56
-	return
57
-}
58
-
59
-func disconnectNamedPipe(handle syscall.Handle) (err error) {
60
-	r1, _, e1 := syscall.Syscall(procDisconnectNamedPipe.Addr(), 1, uintptr(handle), 0, 0)
61
-	if r1 == 0 {
62
-		if e1 != 0 {
63
-			err = error(e1)
64
-		} else {
65
-			err = syscall.EINVAL
66
-		}
67
-	}
68
-	return
69
-}
70
-
71
-func waitNamedPipe(name *uint16, timeout uint32) (err error) {
72
-	r1, _, e1 := syscall.Syscall(procWaitNamedPipeW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(timeout), 0)
73
-	if r1 == 0 {
74
-		if e1 != 0 {
75
-			err = error(e1)
76
-		} else {
77
-			err = syscall.EINVAL
78
-		}
79
-	}
80
-	return
81
-}
82
-
83
-func createEvent(sa *syscall.SecurityAttributes, manualReset bool, initialState bool, name *uint16) (handle syscall.Handle, err error) {
84
-	var _p0 uint32
85
-	if manualReset {
86
-		_p0 = 1
87
-	} else {
88
-		_p0 = 0
89
-	}
90
-	var _p1 uint32
91
-	if initialState {
92
-		_p1 = 1
93
-	} else {
94
-		_p1 = 0
95
-	}
96
-	r0, _, e1 := syscall.Syscall6(procCreateEventW.Addr(), 4, uintptr(unsafe.Pointer(sa)), uintptr(_p0), uintptr(_p1), uintptr(unsafe.Pointer(name)), 0, 0)
97
-	handle = syscall.Handle(r0)
98
-	if handle == syscall.InvalidHandle {
99
-		if e1 != 0 {
100
-			err = error(e1)
101
-		} else {
102
-			err = syscall.EINVAL
103
-		}
104
-	}
105
-	return
106
-}
107
-
108
-func getOverlappedResult(handle syscall.Handle, overlapped *syscall.Overlapped, transferred *uint32, wait bool) (err error) {
109
-	var _p0 uint32
110
-	if wait {
111
-		_p0 = 1
112
-	} else {
113
-		_p0 = 0
114
-	}
115
-	r1, _, e1 := syscall.Syscall6(procGetOverlappedResult.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(transferred)), uintptr(_p0), 0, 0)
116
-	if r1 == 0 {
117
-		if e1 != 0 {
118
-			err = error(e1)
119
-		} else {
120
-			err = syscall.EINVAL
121
-		}
122
-	}
123
-	return
124
-}
125 1
deleted file mode 100644
... ...
@@ -1,124 +0,0 @@
1
-// +build windows
2
-// go build mksyscall_windows.go && ./mksyscall_windows npipe_windows.go
3
-// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
4
-
5
-package npipe
6
-
7
-import "unsafe"
8
-import "syscall"
9
-
10
-var (
11
-	modkernel32 = syscall.NewLazyDLL("kernel32.dll")
12
-
13
-	procCreateNamedPipeW    = modkernel32.NewProc("CreateNamedPipeW")
14
-	procConnectNamedPipe    = modkernel32.NewProc("ConnectNamedPipe")
15
-	procDisconnectNamedPipe = modkernel32.NewProc("DisconnectNamedPipe")
16
-	procWaitNamedPipeW      = modkernel32.NewProc("WaitNamedPipeW")
17
-	procCreateEventW        = modkernel32.NewProc("CreateEventW")
18
-	procGetOverlappedResult = modkernel32.NewProc("GetOverlappedResult")
19
-	procCancelIoEx          = modkernel32.NewProc("CancelIoEx")
20
-)
21
-
22
-func createNamedPipe(name *uint16, openMode uint32, pipeMode uint32, maxInstances uint32, outBufSize uint32, inBufSize uint32, defaultTimeout uint32, sa *syscall.SecurityAttributes) (handle syscall.Handle, err error) {
23
-	r0, _, e1 := syscall.Syscall9(procCreateNamedPipeW.Addr(), 8, uintptr(unsafe.Pointer(name)), uintptr(openMode), uintptr(pipeMode), uintptr(maxInstances), uintptr(outBufSize), uintptr(inBufSize), uintptr(defaultTimeout), uintptr(unsafe.Pointer(sa)), 0)
24
-	handle = syscall.Handle(r0)
25
-	if handle == syscall.InvalidHandle {
26
-		if e1 != 0 {
27
-			err = error(e1)
28
-		} else {
29
-			err = syscall.EINVAL
30
-		}
31
-	}
32
-	return
33
-}
34
-
35
-func cancelIoEx(handle syscall.Handle, overlapped *syscall.Overlapped) (err error) {
36
-	r1, _, e1 := syscall.Syscall(procCancelIoEx.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(overlapped)), 0)
37
-	if r1 == 0 {
38
-		if e1 != 0 {
39
-			err = error(e1)
40
-		} else {
41
-			err = syscall.EINVAL
42
-		}
43
-	}
44
-	return
45
-}
46
-
47
-func connectNamedPipe(handle syscall.Handle, overlapped *syscall.Overlapped) (err error) {
48
-	r1, _, e1 := syscall.Syscall(procConnectNamedPipe.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(overlapped)), 0)
49
-	if r1 == 0 {
50
-		if e1 != 0 {
51
-			err = error(e1)
52
-		} else {
53
-			err = syscall.EINVAL
54
-		}
55
-	}
56
-	return
57
-}
58
-
59
-func disconnectNamedPipe(handle syscall.Handle) (err error) {
60
-	r1, _, e1 := syscall.Syscall(procDisconnectNamedPipe.Addr(), 1, uintptr(handle), 0, 0)
61
-	if r1 == 0 {
62
-		if e1 != 0 {
63
-			err = error(e1)
64
-		} else {
65
-			err = syscall.EINVAL
66
-		}
67
-	}
68
-	return
69
-}
70
-
71
-func waitNamedPipe(name *uint16, timeout uint32) (err error) {
72
-	r1, _, e1 := syscall.Syscall(procWaitNamedPipeW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(timeout), 0)
73
-	if r1 == 0 {
74
-		if e1 != 0 {
75
-			err = error(e1)
76
-		} else {
77
-			err = syscall.EINVAL
78
-		}
79
-	}
80
-	return
81
-}
82
-
83
-func createEvent(sa *syscall.SecurityAttributes, manualReset bool, initialState bool, name *uint16) (handle syscall.Handle, err error) {
84
-	var _p0 uint32
85
-	if manualReset {
86
-		_p0 = 1
87
-	} else {
88
-		_p0 = 0
89
-	}
90
-	var _p1 uint32
91
-	if initialState {
92
-		_p1 = 1
93
-	} else {
94
-		_p1 = 0
95
-	}
96
-	r0, _, e1 := syscall.Syscall6(procCreateEventW.Addr(), 4, uintptr(unsafe.Pointer(sa)), uintptr(_p0), uintptr(_p1), uintptr(unsafe.Pointer(name)), 0, 0)
97
-	handle = syscall.Handle(r0)
98
-	if handle == syscall.InvalidHandle {
99
-		if e1 != 0 {
100
-			err = error(e1)
101
-		} else {
102
-			err = syscall.EINVAL
103
-		}
104
-	}
105
-	return
106
-}
107
-
108
-func getOverlappedResult(handle syscall.Handle, overlapped *syscall.Overlapped, transferred *uint32, wait bool) (err error) {
109
-	var _p0 uint32
110
-	if wait {
111
-		_p0 = 1
112
-	} else {
113
-		_p0 = 0
114
-	}
115
-	r1, _, e1 := syscall.Syscall6(procGetOverlappedResult.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(transferred)), uintptr(_p0), 0, 0)
116
-	if r1 == 0 {
117
-		if e1 != 0 {
118
-			err = error(e1)
119
-		} else {
120
-			err = syscall.EINVAL
121
-		}
122
-	}
123
-	return
124
-}