-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
50 lines (42 loc) · 848 Bytes
/
client.go
File metadata and controls
50 lines (42 loc) · 848 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
package main
import (
"os"
"sync"
"github.com/coder/websocket"
)
type Client struct {
id string
commandName string
commandArgs []string
adminConn *websocket.Conn
termConn *websocket.Conn
ptmx *os.File
}
var clients map[string]*Client = make(map[string]*Client)
var clients_lock sync.Mutex
func AddClient(c *Client) {
clients_lock.Lock()
defer clients_lock.Unlock()
clients[c.id] = c
}
func FindClient(id string) *Client {
clients_lock.Lock()
defer clients_lock.Unlock()
return clients[id]
}
func DelClient(id string) *Client {
clients_lock.Lock()
defer clients_lock.Unlock()
c := clients[id]
delete(clients, id)
return c
}
func NewClient(id string, cmdName string, args ...string) *Client {
c := &Client{
id: id,
commandName: cmdName,
commandArgs: args,
}
AddClient(c)
return c
}