This repository has been archived by the owner on May 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathhandleMessage.go
62 lines (53 loc) · 1.45 KB
/
handleMessage.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
package webwire
import "github.com/qbeon/webwire-go/message"
// handleMessage parses and handles incoming messages
func (srv *server) handleMessage(
con *connection,
msg *message.Message,
) (err error) {
// Don't register a task handler for heartbeat messages
//
// TODO: probably this check should include any message type that's not
// handled by handleMessage to avoid registering a handler
if msg.MsgType == message.MsgHeartbeat {
// Release message buffer
msg.Close()
return nil
}
if !srv.registerHandler(con, msg) {
// Release message buffer
msg.Close()
return nil
}
// Message buffers are released by the individual handlers
switch msg.MsgType {
case message.MsgSignalBinary,
message.MsgSignalUtf8,
message.MsgSignalUtf16:
if con.options.ConcurrencyLimit < 0 ||
con.options.ConcurrencyLimit > 1 {
go srv.handleSignal(con, msg)
} else {
srv.handleSignal(con, msg)
}
case message.MsgRequestBinary,
message.MsgRequestUtf8,
message.MsgRequestUtf16:
if con.options.ConcurrencyLimit < 0 ||
con.options.ConcurrencyLimit > 1 {
go srv.handleRequest(con, msg)
} else {
srv.handleRequest(con, msg)
}
case message.MsgRequestRestoreSession:
srv.handleSessionRestore(con, msg)
case message.MsgRequestCloseSession:
srv.handleSessionClosure(con, msg)
default:
// Immediately deregister handlers for unexpected message types
srv.deregisterHandler(con)
// Release message buffer
msg.Close()
}
return nil
}