-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipc.go
More file actions
53 lines (45 loc) · 844 Bytes
/
Copy pathipc.go
File metadata and controls
53 lines (45 loc) · 844 Bytes
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
package main
import (
"fmt"
"net"
"sync"
"gopkg.in/natefinch/npipe.v2"
)
var (
pipeClients []net.Conn
pipeMutex sync.Mutex
)
func startPipeServer() {
ln, err := npipe.Listen(`\\.\pipe\SpaceWorkspace`)
if err != nil {
fmt.Println("Failed to start pipe server:", err)
return
}
for {
conn, err := ln.Accept()
if err != nil {
continue
}
pipeMutex.Lock()
pipeClients = append(pipeClients, conn)
pipeMutex.Unlock()
}
}
func broadcastWorkspace(ws int) {
pipeMutex.Lock()
defer pipeMutex.Unlock()
msg := fmt.Appendf(nil, "%d\n", ws)
var activeClients []net.Conn
for _, conn := range pipeClients {
_, err := conn.Write(msg)
if err == nil {
activeClients = append(activeClients, conn)
} else {
err := conn.Close()
if err != nil {
fmt.Println(err)
}
}
}
pipeClients = activeClients
}