opt_firenze
This commit is contained in:
parent
5e596f2aac
commit
b9c56a4213
Binary file not shown.
|
@ -108,6 +108,10 @@ func (h *hub) len() int {
|
|||
}
|
||||
|
||||
func (h *hub) all() []*Session {
|
||||
if h == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
h.rwmutex.RLock()
|
||||
defer h.rwmutex.RUnlock()
|
||||
|
||||
|
@ -118,7 +122,29 @@ func (h *hub) all() []*Session {
|
|||
return s
|
||||
}
|
||||
|
||||
func (h *hub) GetDidSession(did string) *Session {
|
||||
if h == nil {
|
||||
return nil
|
||||
}
|
||||
if len(did) <= 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
h.rwmutex.RLock()
|
||||
s := h.didSessionMap[did]
|
||||
h.rwmutex.RUnlock()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (h *hub) updateSession(s *Session) {
|
||||
if h == nil {
|
||||
return
|
||||
}
|
||||
if s == nil {
|
||||
return
|
||||
}
|
||||
|
||||
if len(s.Sid) > 0 {
|
||||
h.rwmutex.Lock()
|
||||
h.sidSessionMap[s.Sid] = s
|
||||
|
|
|
@ -202,6 +202,13 @@ func (m *Melody) HandleRequestWithKeys(w http.ResponseWriter, r *http.Request, k
|
|||
baseReq.Did = baseReq.Channel
|
||||
}
|
||||
|
||||
// 检查设备
|
||||
oldSession := m.hub.GetDidSession(baseReq.Did)
|
||||
if oldSession != nil {
|
||||
logger.Warn("device reconnect: %d - %s", baseReq.Mid, baseReq.Did)
|
||||
oldSession.close()
|
||||
}
|
||||
|
||||
// 升级协议
|
||||
conn, err := m.Upgrader.Upgrade(w, r, w.Header())
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue