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
63469514
Commit
63469514
authored
Oct 10, 2016
by
alexstocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
invoke codec.go:(EventListener)OnClose when got error
parent
16eda0f9
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
17 deletions
+25
-17
codec.go
codec.go
+1
-1
dev.list
dev.list
+5
-0
server.go
server.go
+1
-0
session.go
session.go
+13
-14
version.go
version.go
+5
-2
No files found.
codec.go
View file @
63469514
...
...
@@ -39,7 +39,7 @@ type EventListener interface {
// If the return error is not nil, @Session will be closed.
OnOpen
(
*
Session
)
error
// invoked when session closed.
when @Session got error, session will not invoke @OnClose but invoke @OnError.
// invoked when session closed.
OnClose
(
*
Session
)
// invoked when got error.
...
...
dev.list
View file @
63469514
...
...
@@ -11,6 +11,11 @@
## develop history ##
---
- 2016/10/10
> 1 delete session.go:Session{errFlag} to invoke codec.go:EventListener{OnClose&OnError} both when got a error
>
> 2 version: 0.4.01
- 2016/10/09
> 1 add client.go:NewWSSClient
>
...
...
server.go
View file @
63469514
...
...
@@ -147,6 +147,7 @@ func newWSHandler(server *Server, newSession NewSessionCallback) *wsHandler {
}
func
(
this
*
wsHandler
)
ServeWSRequest
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
log
.
Debug
(
"get client request:%#v"
,
r
)
if
r
.
Method
!=
"GET"
{
// w.WriteHeader(http.StatusMethodNotAllowed)
http
.
Error
(
w
,
"Method not allowed"
,
405
)
...
...
session.go
View file @
63469514
...
...
@@ -61,7 +61,7 @@ type Session struct {
listener
EventListener
once
sync
.
Once
done
chan
empty
errFlag
bool
//
errFlag bool
period
time
.
Duration
rDeadline
time
.
Duration
// network current limiting
...
...
@@ -119,7 +119,7 @@ func (this *Session) Reset() {
this
.
name
=
defaultSessionName
this
.
once
=
sync
.
Once
{}
this
.
done
=
make
(
chan
empty
)
this
.
errFlag
=
false
//
this.errFlag = false
this
.
period
=
period
this
.
rDeadline
=
netIOTimeout
this
.
wDeadline
=
netIOTimeout
...
...
@@ -418,9 +418,9 @@ func (this *Session) handleLoop() {
}
grNum
=
atomic
.
AddInt32
(
&
(
this
.
grNum
),
-
1
)
if
!
this
.
errFlag
{
this
.
listener
.
OnClose
(
this
)
}
//
if !this.errFlag {
this
.
listener
.
OnClose
(
this
)
//
}
log
.
Info
(
"%s, [session.handleLoop] goroutine exit now, left gr num %d"
,
this
.
Stat
(),
grNum
)
this
.
gc
()
}()
...
...
@@ -494,7 +494,8 @@ func (this *Session) handlePackage() {
grNum
=
atomic
.
AddInt32
(
&
(
this
.
grNum
),
-
1
)
log
.
Info
(
"%s, [session.handlePackage] gr will exit now, left gr num %d"
,
this
.
sessionToken
(),
grNum
)
this
.
stop
()
if
this
.
errFlag
{
// if this.errFlag {
if
err
!=
nil
{
log
.
Error
(
"%s, [session.handlePackage] error{%#v}"
,
this
.
sessionToken
(),
err
)
this
.
listener
.
OnError
(
this
,
err
)
}
...
...
@@ -512,10 +513,9 @@ func (this *Session) handleTCPPackage() error {
var
(
err
error
// nerr net.Error
conn
*
gettyTCPConn
ok
bool
exit
bool
// errFlag bool
conn
*
gettyTCPConn
ok
bool
exit
bool
bufLen
int
pkgLen
int
buf
[]
byte
...
...
@@ -544,7 +544,7 @@ func (this *Session) handleTCPPackage() error {
// }
log
.
Error
(
"%s, [session.conn.read] = error{%v}"
,
this
.
sessionToken
(),
err
)
// for (Codec)OnErr
this
.
errFlag
=
true
//
this.errFlag = true
exit
=
true
}
break
...
...
@@ -565,8 +565,7 @@ func (this *Session) handleTCPPackage() error {
if
err
!=
nil
{
log
.
Info
(
"%s, [session.pkgHandler.Read] = error{%+v}"
,
this
.
sessionToken
(),
err
)
// for (Codec)OnErr
// errFlag = true
this
.
errFlag
=
true
// this.errFlag = true
exit
=
true
break
}
...
...
@@ -604,7 +603,7 @@ func (this *Session) handleWSPackage() error {
pkg
,
err
=
conn
.
read
()
if
err
!=
nil
{
log
.
Info
(
"%s, [session.handleWSPackage.Read] = error{%+v}"
,
this
.
sessionToken
(),
err
)
this
.
errFlag
=
true
//
this.errFlag = true
return
err
}
this
.
rQ
<-
pkg
...
...
version.go
View file @
63469514
...
...
@@ -10,6 +10,9 @@
package
getty
const
(
Version
=
"0.4.0"
DATE
=
"2016/10/08"
Version
=
"0.4.01"
DATE
=
"2016/10/10"
GETTY_MAJOR
=
0
GETTY_MINOR
=
4
GETTY_BUILD
=
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