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
a021f778
Commit
a021f778
authored
Sep 26, 2016
by
alexstocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add time wheel
parent
f83552e6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
12 deletions
+18
-12
dev.list
dev.list
+4
-0
session.go
session.go
+12
-10
version.go
version.go
+2
-2
No files found.
dev.list
View file @
a021f778
...
...
@@ -13,6 +13,10 @@
- 2016/09/26
> 1 move utils.go's function to github.com/AlexStocks/goext and delete it
>
> 2 use goext/time Wheel
>
> 3 version: 0.3.11
- 2016/09/20
> 1 just invoke OnError when session got error
...
...
session.go
View file @
a021f778
...
...
@@ -44,6 +44,7 @@ var (
var
(
connID
uint32
wheel
*
gxtime
.
Wheel
=
gxtime
.
NewWheel
(
gxtime
.
TimeSecondDuration
(
1
),
3600
)
// wheel longest span is 1 hour
)
type
gettyConn
struct
{
...
...
@@ -317,7 +318,8 @@ func (this *Session) WritePkg(pkg interface{}) error {
// default:
// case <-time.After(this.wDeadline):
case
<-
time
.
After
(
netIOTimeout
)
:
// case <-time.After(netIOTimeout):
case
<-
wheel
.
After
(
this
.
wDeadline
)
:
log
.
Warn
(
"%s, [session.WritePkg] wQ{len:%d, cap:%d}"
,
this
.
Stat
(),
len
(
this
.
wQ
),
cap
(
this
.
wQ
))
return
ErrSessionBlocked
}
...
...
@@ -363,10 +365,10 @@ func (this *Session) handleLoop() {
flag
bool
// start time.Time
counter
gxtime
.
CountWatch
ticker
*
time
.
Ticker
// ticker *time.Ticker // use wheel instead, 2016/09/26
inPkg
interface
{}
outPkg
interface
{}
once
sync
.
Once
// once sync.Once // use wheel instead, 2016/09/26
)
defer
func
()
{
...
...
@@ -388,13 +390,13 @@ func (this *Session) handleLoop() {
}()
flag
=
true
// do not do any read/write/cron operation while got write error
ticker
=
time
.
NewTicker
(
this
.
period
)
// ticker = time.NewTicker(this.period) // use wheel instead, 2016/09/26
LOOP
:
for
{
select
{
case
<-
this
.
done
:
// 这个分支确保(Session)handleLoop gr在(Session)handlePackage gr之后退出
once
.
Do
(
func
()
{
ticker
.
Stop
()
})
// once.Do(func() { ticker.Stop() }) // use wheel instead, 2016/09/26
if
atomic
.
LoadInt32
(
&
(
this
.
grNum
))
==
1
{
// make sure @(Session)handlePackage goroutine has been closed.
if
len
(
this
.
rQ
)
==
0
&&
len
(
this
.
wQ
)
==
0
{
log
.
Info
(
"%s, [session.handleLoop] got done signal. Both rQ and wQ are nil."
,
this
.
Stat
())
...
...
@@ -430,14 +432,14 @@ LOOP:
log
.
Info
(
"[session.handleLoop] drop writeout package{%#v}"
,
outPkg
)
}
case
<-
ticker
.
C
:
// case <-ticker.C: // use wheel instead, 2016/09/26
case
<-
wheel
.
After
(
this
.
period
)
:
if
flag
{
this
.
listener
.
OnCron
(
this
)
}
}
}
once
.
Do
(
func
()
{
ticker
.
Stop
()
})
// ticker.Stop()
// once.Do(func() { ticker.Stop() }) // use wheel instead, 2016/09/26
}
// get package from tcp stream(packet)
...
...
version.go
View file @
a021f778
...
...
@@ -10,8 +10,8 @@
package
getty
const
(
Version
=
"0.3.1
0
"
Version
=
"0.3.1
1
"
GETTY_MAJOR
=
0
GETTY_MINOR
=
3
GETTY_BUILD
=
1
0
GETTY_BUILD
=
1
1
)
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