-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconnection.go
66 lines (56 loc) · 1.08 KB
/
connection.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
package plex
import (
"net"
"github.com/swxctx/plex/pack"
"github.com/swxctx/plex/plog"
)
// plexConnection
type plexConnection struct {
// 用户标识
uid string
// remote
remoteAddr string
// auth success
isAuthenticated bool
// conn cache info
storeInfo *storeInfo
// bind server info
plexServer *plexServer
}
// storeInfo
type storeInfo struct {
// connection client
conn net.Conn
// last heartbeat ts
heartbeat int64
}
// close connection
func (c *plexConnection) close() {
// close conn
c.storeInfo.conn.Close()
// del store
c.plexServer.store.del(c.uid)
// callback
if len(c.uid) > 0 {
c.plexServer.onlineStatusSubscribe(false, c.uid)
}
}
// responseOnlyUri
func (c *plexConnection) responseOnlyUri(uri string) error {
// pack message
message, err := pack.Pack(&pack.Message{
Seq: GetSeq(),
URI: uri,
})
if err != nil {
plog.Errorf("responseOnlyUri: err-> %v, uri-> %s", err, uri)
return err
}
// send message
return c.storeInfo.send(message)
}
// send
func (s *storeInfo) send(data []byte) error {
_, err := s.conn.Write(data)
return err
}