Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
im-pool
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoyanbin
im-pool
Commits
d3c3d90e
Commit
d3c3d90e
authored
Nov 14, 2022
by
haoyanbin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
43001efb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
12 deletions
+19
-12
client.go
pool/client.go
+2
-2
hub.go
pool/hub.go
+1
-1
init.go
pool/init.go
+1
-2
publicApi.go
pool/publicApi.go
+14
-7
ws_server.go
ws_server.go
+1
-0
No files found.
pool/client.go
View file @
d3c3d90e
...
...
@@ -25,7 +25,7 @@ const (
//
closeWait
=
60
*
30
*
time
.
Second
//
//
time for auto end
endDate
=
60
*
2
*
time
.
Second
)
...
...
@@ -142,7 +142,7 @@ func (c *Client) readPump() {
close
(
c
.
sendPing
)
c
.
grpool
.
Close
()
c
.
hub
.
RemoveClient
(
c
)
Redis
.
HDel
(
cliKey
,
c
.
Id
)
DelClient
(
c
.
Id
)
dump
()
}()
Loop
:
...
...
pool/hub.go
View file @
d3c3d90e
...
...
@@ -27,7 +27,7 @@ var (
// clients.
type
hub
struct
{
// Registered clients.
clients
map
[
string
]
*
Client
//
//
新的处理方式有没有线程效率会更高,所以SafeMap的锁处理都去掉了
clients
map
[
string
]
*
Client
//新的处理方式有没有线程效率会更高,所以SafeMap的锁处理都去掉了
oldClients
map
[
string
]
*
Client
//缓存断开的连接消息队列
// Inbound messages from the clients.
...
...
pool/init.go
View file @
d3c3d90e
...
...
@@ -28,8 +28,7 @@ func InitWsPool(errfun func(err interface{})) {
}
func
initWsPoolData
()
{
clientsData
:=
Redis
.
HGetAll
(
cliKey
)
clientsAll
:=
clientsData
.
Val
()
clientsAll
:=
GetAllList
(
cliKey
)
for
_
,
v
:=
range
clientsAll
{
if
v
==
""
{
...
...
pool/publicApi.go
View file @
d3c3d90e
...
...
@@ -10,8 +10,6 @@ import (
"time"
)
var
toConverstaionLock
sync
.
Mutex
type
SetMsgReq
struct
{
ProcedureType
int
`json:"procedureType"`
GroupId
string
`json:"groupId" db:"group_id"`
...
...
@@ -78,8 +76,7 @@ func NewClient(conf *Config) *Client {
client
.
OnPing
(
nil
)
client
.
OnPong
(
nil
)
wsSever
.
hub
.
AddClient
(
client
)
jsonData
:=
string
(
SerializeJson
(
conf
))
Redis
.
HSet
(
cliKey
,
client
.
Id
,
jsonData
)
AppendClient
(
client
.
Id
,
string
(
SerializeJson
(
conf
)))
return
client
}
...
...
@@ -509,8 +506,8 @@ func PublishData(mqData *SetMsgReq) {
return
}
func
Get
ConversationList
(
)
map
[
string
]
string
{
jsonData
:=
Redis
.
HGetAll
(
convK
ey
)
func
Get
AllList
(
key
string
)
map
[
string
]
string
{
jsonData
:=
Redis
.
HGetAll
(
k
ey
)
jsonDataAll
:=
jsonData
.
Val
()
return
jsonDataAll
}
...
...
@@ -525,8 +522,18 @@ func DelConversation(customerClientId, userClientId string) {
return
}
func
AppendClient
(
clientId
,
data
string
){
Redis
.
HSet
(
cliKey
,
clientId
,
data
)
return
}
func
DelClient
(
clientId
string
)
{
Redis
.
HDel
(
cliKey
,
clientId
)
return
}
func
SetEnd
()
{
conversationList
:=
Get
ConversationList
(
)
conversationList
:=
Get
AllList
(
convKey
)
for
_
,
vClients
:=
range
conversationList
{
conversationData
:=
&
Conversation
{}
UnserislizeJson
([]
byte
(
vClients
),
conversationData
)
...
...
ws_server.go
View file @
d3c3d90e
...
...
@@ -164,6 +164,7 @@ func ws(w http.ResponseWriter, r *http.Request) {
pool
.
PublishData
(
closeMsg
)
fmt
.
Println
(
"专家关闭连接"
,
client
.
Id
)
}
pool
.
DelClient
(
client
.
Id
)
fmt
.
Printf
(
"连接己经关闭%s"
,
client
.
Id
)
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment