Fixe concurrent map read and map write for XMPP client connected.
This commit is contained in:
parent
458b96bffb
commit
7ad36a0321
|
|
@ -32,7 +32,7 @@ type GatewayInfo struct {
|
||||||
// XMPP
|
// XMPP
|
||||||
XMPP_JID_Client string
|
XMPP_JID_Client string
|
||||||
XMPP_Out chan interface{}
|
XMPP_Out chan interface{}
|
||||||
XMPP_Connected_Client map[string]bool
|
xmpp_Connected_Client *XmppConnectedClient
|
||||||
DebugMessage bool
|
DebugMessage bool
|
||||||
XMPP_IQ_RemoteRoster_Request map[string]string
|
XMPP_IQ_RemoteRoster_Request map[string]string
|
||||||
AllowEditRoster bool
|
AllowEditRoster bool
|
||||||
|
|
@ -44,6 +44,11 @@ type FriendSteam struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type XmppConnectedClient struct {
|
||||||
|
client map[string]bool
|
||||||
|
sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
type StatusSteamFriend struct {
|
type StatusSteamFriend struct {
|
||||||
XMPP_Status string
|
XMPP_Status string
|
||||||
XMPP_Type string
|
XMPP_Type string
|
||||||
|
|
@ -110,3 +115,25 @@ func (s *GatewayInfo) RemoveFriendSteamId(steamId string) {
|
||||||
delete(s.friendSteamId.steamId, steamId)
|
delete(s.friendSteamId.steamId, steamId)
|
||||||
s.friendSteamId.Unlock()
|
s.friendSteamId.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *GatewayInfo) CreateXmppConnectedClient() {
|
||||||
|
s.xmpp_Connected_Client = &XmppConnectedClient{client: make(map[string]bool)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GatewayInfo) SetXmppConnectedClient(jid string) {
|
||||||
|
s.xmpp_Connected_Client.Lock()
|
||||||
|
s.xmpp_Connected_Client.client[jid] = true
|
||||||
|
s.xmpp_Connected_Client.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GatewayInfo) RemoveXmppConnectedClient(jid string) {
|
||||||
|
s.xmpp_Connected_Client.Lock()
|
||||||
|
delete(s.xmpp_Connected_Client.client, jid)
|
||||||
|
s.xmpp_Connected_Client.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *GatewayInfo) GetLenXmppConnectedClient() int {
|
||||||
|
s.xmpp_Connected_Client.RLock()
|
||||||
|
defer s.xmpp_Connected_Client.RUnlock()
|
||||||
|
return len(s.xmpp_Connected_Client.client)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,9 +56,9 @@ func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
|
||||||
if len(jid) == 2 {
|
if len(jid) == 2 {
|
||||||
// Resource exist —> client speaking
|
// Resource exist —> client speaking
|
||||||
if presence.Type == Type_available {
|
if presence.Type == Type_available {
|
||||||
g.XMPP_Connected_Client[presence.From] = true
|
g.SetXmppConnectedClient(presence.From)
|
||||||
} else if presence.Type == Type_unavailable {
|
} else if presence.Type == Type_unavailable {
|
||||||
delete(g.XMPP_Connected_Client, presence.From)
|
g.RemoveXmppConnectedClient(presence.From)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,7 +79,7 @@ func (g *GatewayInfo) ReceivedXMPP_Presence(presence *xmpp.Presence) {
|
||||||
// Destination is gateway itself
|
// Destination is gateway itself
|
||||||
if presence.Type == Type_unavailable {
|
if presence.Type == Type_unavailable {
|
||||||
// Disconnect
|
// Disconnect
|
||||||
if len(g.XMPP_Connected_Client) <= 0 {
|
if g.GetLenXmppConnectedClient() <= 0 {
|
||||||
g.Disconnect()
|
g.Disconnect()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -281,7 +281,7 @@ func AddNewUser(jidUser, steamLogin, steamPwd string, debugMessage bool) {
|
||||||
g.Deleting = false
|
g.Deleting = false
|
||||||
|
|
||||||
g.XMPP_Out = comp.Out
|
g.XMPP_Out = comp.Out
|
||||||
g.XMPP_Connected_Client = make(map[string]bool)
|
g.CreateXmppConnectedClient()
|
||||||
g.DebugMessage = debugMessage
|
g.DebugMessage = debugMessage
|
||||||
g.XMPP_IQ_RemoteRoster_Request = make(map[string]string)
|
g.XMPP_IQ_RemoteRoster_Request = make(map[string]string)
|
||||||
g.AllowEditRoster = false
|
g.AllowEditRoster = false
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue