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
cef46d37
Commit
cef46d37
authored
Sep 07, 2016
by
alexstocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add (Session)clear
parent
05ebc1c5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
20 deletions
+23
-20
README.md
README.md
+3
-0
session.go
session.go
+20
-20
No files found.
README.md
View file @
cef46d37
...
...
@@ -11,6 +11,9 @@
## develop history ##
---
-
2016/09/07
> 1 session.go:(Session)Close() -> session.go:(Session)clear() to be invoked by session.go:(Session)handleLoop
-
2016/09/06
> 1 codec.go:(Reader)Read(*Session, []byte) (interface{}, error) -> codec.go:(Reader)Read(*Session, []byte) (interface{}, int, error)
>
...
...
session.go
View file @
cef46d37
...
...
@@ -280,13 +280,12 @@ func (this *Session) RemoveAttribute(key string) {
}
func
(
this
*
Session
)
sessionToken
()
string
{
return
fmt
.
Sprintf
(
"{%s, %d, %s <-> %s}"
,
this
.
name
,
this
.
ID
,
this
.
conn
.
LocalAddr
()
.
String
(),
this
.
conn
.
RemoteAddr
()
.
String
(),
)
var
localAddr
,
peerAddr
string
if
this
.
conn
!=
nil
{
localAddr
=
this
.
conn
.
LocalAddr
()
.
String
()
peerAddr
=
this
.
conn
.
RemoteAddr
()
.
String
()
}
return
fmt
.
Sprintf
(
"{%s, %d, %s <-> %s}"
,
this
.
name
,
this
.
ID
,
localAddr
,
peerAddr
)
}
// Queued write, for handler
...
...
@@ -361,7 +360,7 @@ func (this *Session) handleLoop() {
grNum
=
atomic
.
AddInt32
(
&
(
this
.
grNum
),
-
1
)
this
.
listener
.
OnClose
(
this
)
log
.
Info
(
"statistic{%s}, [session.handleLoop] goroutine exit now, left gr num %d"
,
this
.
Stat
(),
grNum
)
this
.
Close
()
this
.
gc
()
}()
ticker
=
time
.
NewTicker
(
this
.
peroid
)
...
...
@@ -509,20 +508,15 @@ func (this *Session) stop() {
}
}
// this function will be invoked by NewSessionCallback(if return error is not nil) or (Session)handleLoop automatically.
// It is goroutine-safe to be invoked many times.
func
(
this
*
Session
)
Close
()
error
{
this
.
stop
()
log
.
Info
(
"%s closed now, its current gr num %d"
,
this
.
sessionToken
(),
atomic
.
LoadInt32
(
&
(
this
.
grNum
)))
func
(
this
*
Session
)
gc
()
{
this
.
lock
.
Lock
()
if
this
.
attrs
!=
nil
{
this
.
attrs
=
nil
select
{
case
<-
this
.
readerDone
:
default
:
close
(
this
.
readerDone
)
}
//
select {
//
case <-this.readerDone:
//
default:
//
close(this.readerDone)
//
}
close
(
this
.
wQ
)
this
.
wQ
=
nil
close
(
this
.
rQ
)
...
...
@@ -530,6 +524,12 @@ func (this *Session) Close() error {
this
.
gettyConn
.
close
((
int
)((
int64
)(
this
.
wait
)))
}
this
.
lock
.
Unlock
()
}
return
nil
// this function will be invoked by NewSessionCallback(if return error is not nil) or (Session)handleLoop automatically.
// It is goroutine-safe to be invoked many times.
func
(
this
*
Session
)
Close
()
{
this
.
stop
()
log
.
Info
(
"%s closed now, its current gr num %d"
,
this
.
sessionToken
(),
atomic
.
LoadInt32
(
&
(
this
.
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