aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/service/ipc_pipe.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-02-25 18:47:12 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-02-28 08:05:02 +0100
commit3e7d023068e9d82dc07b5b8740e8b76ca946b7d0 (patch)
treef57899e05cc73a1a5153cc6b118bf0bb810a8098 /service/ipc_pipe.go
parentservice: introduce base of services (diff)
downloadwireguard-windows-3e7d023068e9d82dc07b5b8740e8b76ca946b7d0.tar.xz
wireguard-windows-3e7d023068e9d82dc07b5b8740e8b76ca946b7d0.zip
ipc: add base of IPC
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'service/ipc_pipe.go')
-rw-r--r--service/ipc_pipe.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/service/ipc_pipe.go b/service/ipc_pipe.go
new file mode 100644
index 00000000..ee63f2d4
--- /dev/null
+++ b/service/ipc_pipe.go
@@ -0,0 +1,58 @@
+/* SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2019 WireGuard LLC. All Rights Reserved.
+ */
+
+package service
+
+import (
+ "golang.org/x/sys/windows"
+ "os"
+ "strconv"
+)
+
+type pipeRWC struct {
+ reader *os.File
+ writer *os.File
+}
+
+func (p *pipeRWC) Read(b []byte) (int, error) {
+ return p.reader.Read(b)
+}
+
+func (p *pipeRWC) Write(b []byte) (int, error) {
+ return p.writer.Write(b)
+}
+
+func (p *pipeRWC) Close() error {
+ err1 := p.writer.Close()
+ err2 := p.reader.Close()
+ if err1 != nil {
+ return err1
+ }
+ return err2
+}
+
+func inheritableSocketpairEmulation() (ourReader *os.File, theirReader *os.File, theirReaderStr string, ourWriter *os.File, theirWriter *os.File, theirWriterStr string, err error) {
+ ourReader, theirWriter, err = os.Pipe()
+ if err != nil {
+ return
+ }
+ err = windows.SetHandleInformation(windows.Handle(theirWriter.Fd()), windows.HANDLE_FLAG_INHERIT, windows.HANDLE_FLAG_INHERIT)
+ if err != nil {
+ return
+ }
+ theirWriterStr = strconv.FormatUint(uint64(theirWriter.Fd()), 10)
+
+ theirReader, ourWriter, err = os.Pipe()
+ if err != nil {
+ return
+ }
+ err = windows.SetHandleInformation(windows.Handle(theirReader.Fd()), windows.HANDLE_FLAG_INHERIT, windows.HANDLE_FLAG_INHERIT)
+ if err != nil {
+ return
+ }
+ theirReaderStr = strconv.FormatUint(uint64(theirReader.Fd()), 10)
+
+ return
+}