Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
getty
Project
Project
Details
Activity
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
wei.xuan
getty
Commits
6b4adbd5
Commit
6b4adbd5
authored
Oct 27, 2018
by
AlexStocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Imp: remote go client reconnection goroutine by reconnect method in Session:Stop
parent
724bc6d7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
36 deletions
+35
-36
client.go
client.go
+27
-32
examples
examples
+1
-1
session.go
session.go
+7
-3
No files found.
client.go
View file @
6b4adbd5
...
...
@@ -36,6 +36,7 @@ const (
)
var
(
sessionClientKey
=
"session-client-owner"
connectPingPackage
=
[]
byte
(
"connect-ping"
)
)
...
...
@@ -363,6 +364,7 @@ func (c *client) connect() {
c
.
Lock
()
c
.
ssMap
[
ss
]
=
gxsync
.
Empty
{}
c
.
Unlock
()
ss
.
SetAttribute
(
sessionClientKey
,
c
)
break
}
// don't distinguish between tcp connection and websocket connection. Because
...
...
@@ -382,42 +384,34 @@ func (c *client) RunEventLoop(newSession NewSessionCallback) {
c
.
Lock
()
c
.
newSession
=
newSession
c
.
Unlock
()
c
.
reConnect
()
}
c
.
wg
.
Add
(
1
)
// a for-loop goroutine to make sure the connection is valid
go
func
()
{
var
num
,
max
,
times
int
defer
c
.
wg
.
Done
()
// a for-loop connect to make sure the connection pool is valid
func
(
c
*
client
)
reConnect
()
{
var
num
,
max
,
times
int
c
.
Lock
()
max
=
c
.
number
c
.
Unlock
()
// log.Info("maximum client connection number:%d", max)
for
{
if
c
.
IsClosed
()
{
log
.
Warn
(
"client{peer:%s} goroutine exit now."
,
c
.
addr
)
break
}
// c.Lock()
max
=
c
.
number
// c.Unlock()
for
{
if
c
.
IsClosed
()
{
log
.
Warn
(
"client{peer:%s} goroutine exit now."
,
c
.
addr
)
break
}
num
=
c
.
sessionNum
()
// log.Info("current client connction number:%d", num)
if
max
<=
num
{
times
++
if
maxTimes
<
times
{
times
=
maxTimes
}
// time.Sleep(time.Duration(int64(times) * connInterval))
<-
wheel
.
After
(
time
.
Duration
(
int64
(
times
)
*
connInterval
))
continue
}
times
=
0
c
.
connect
()
//if c.endPointType == UDP_CLIENT {
// break
//}
// time.Sleep(c.interval) // build c.number connections asap
num
=
c
.
sessionNum
()
if
max
<=
num
{
break
}
c
.
connect
()
times
++
if
maxTimes
<
times
{
times
=
maxTimes
}
}()
// time.Sleep(time.Duration(int64(times) * connInterval))
<-
wheel
.
After
(
time
.
Duration
(
int64
(
times
)
*
connInterval
))
}
}
func
(
c
*
client
)
stop
()
{
...
...
@@ -429,6 +423,7 @@ func (c *client) stop() {
close
(
c
.
done
)
c
.
Lock
()
for
s
:=
range
c
.
ssMap
{
s
.
RemoveAttribute
(
sessionClientKey
)
s
.
Close
()
}
c
.
ssMap
=
nil
...
...
examples
@
abe816f7
Subproject commit
0e6d40895587d9eb6d7c5b2ddd6bd7e1f008d0da
Subproject commit
abe816f76766902e9d3b1ab40962890f50fddddd
session.go
View file @
6b4adbd5
...
...
@@ -774,6 +774,10 @@ func (s *session) stop() {
conn
.
SetWriteDeadline
(
now
.
Add
(
s
.
writeTimeout
()))
}
close
(
s
.
done
)
c
:=
s
.
GetAttribute
(
sessionClientKey
)
if
clt
,
ok
:=
c
.
(
*
client
);
ok
{
clt
.
reConnect
()
}
})
}
}
...
...
@@ -791,9 +795,9 @@ func (s *session) gc() {
s
.
lock
.
Unlock
()
}
// Close will be invoked by NewSessionCallback(if return error is not nil)
or (session)handleLoop automatically.
// It's thread safe.
// Close will be invoked by NewSessionCallback(if return error is not nil)
//
or (session)handleLoop automatically.
It's thread safe.
func
(
s
*
session
)
Close
()
{
s
.
stop
()
log
.
Info
(
"%s closed now
, its current gr num
%d"
,
s
.
sessionToken
(),
atomic
.
LoadInt32
(
&
(
s
.
grNum
)))
log
.
Info
(
"%s closed now
. its current gr num is
%d"
,
s
.
sessionToken
(),
atomic
.
LoadInt32
(
&
(
s
.
grNum
)))
}
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