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
3f195ce4
Commit
3f195ce4
authored
Jun 07, 2019
by
AlexStocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mod: add remark for tcp reading
parent
bdf5e640
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
3 deletions
+17
-3
conn.go
conn.go
+2
-0
getty.go
getty.go
+11
-3
session.go
session.go
+4
-0
No files found.
conn.go
View file @
3f195ce4
...
...
@@ -235,6 +235,7 @@ func (t *gettyTCPConn) read(p []byte) (int, error) {
length
int
)
// set read timeout deadline
if
t
.
compress
==
CompressNone
&&
t
.
rTimeout
>
0
{
// Optimization: update read deadline only if more than 25%
// of the last read deadline exceeded.
...
...
@@ -242,6 +243,7 @@ func (t *gettyTCPConn) read(p []byte) (int, error) {
currentTime
=
time
.
Now
()
if
currentTime
.
Sub
(
t
.
rLastDeadline
)
>
(
t
.
rTimeout
>>
2
)
{
if
err
=
t
.
conn
.
SetReadDeadline
(
currentTime
.
Add
(
t
.
rTimeout
));
err
!=
nil
{
// just a timeout error
return
0
,
perrors
.
WithStack
(
err
)
}
t
.
rLastDeadline
=
currentTime
...
...
getty.go
View file @
3f195ce4
...
...
@@ -24,9 +24,17 @@ type NewSessionCallback func(Session) error
// Reader is used to unmarshal a complete pkg from buffer
type
Reader
interface
{
// Parse tcp/udp/websocket pkg from buffer and if possible return a complete pkg
// If length of buf is not long enough, u should return {nil,0, nil}
// The second return value is the length of the pkg.
// Parse tcp/udp/websocket pkg from buffer and if possible return a complete pkg.
// When receiving a tcp network streaming segment, there are 4 cases as following:
// case 1: a error found in the streaming segment;
// case 2: can not unmarshal a pkg from the streaming segment;
// case 3: just unmarshal a pkg from the streaming segment;
// case 4: unmarshal more than one pkg from the streaming segment;
//
// The return value is (nil, 0, error) as case 1.
// The return value is (nil, 0, nil) as case 2.
// The return value is (pkg, pkgLen, nil) as case 3.
// The handleTcpPackage may invoke func Read many times as case 4.
Read
(
Session
,
[]
byte
)
(
interface
{},
int
,
error
)
}
...
...
session.go
View file @
3f195ce4
...
...
@@ -623,6 +623,7 @@ func (s *session) handleTCPPackage() error {
if
err
==
nil
&&
s
.
maxMsgLen
>
0
&&
pkgLen
>
int
(
s
.
maxMsgLen
)
{
err
=
perrors
.
Errorf
(
"pkgLen %d > session max message len %d"
,
pkgLen
,
s
.
maxMsgLen
)
}
// handle case 1
if
err
!=
nil
{
log
.
Warnf
(
"%s, [session.handleTCPPackage] = len{%d}, error:%+v"
,
s
.
sessionToken
(),
pkgLen
,
err
)
...
...
@@ -631,12 +632,15 @@ func (s *session) handleTCPPackage() error {
exit
=
true
break
}
// handle case 2
if
pkg
==
nil
{
break
}
// handle case 3
s
.
UpdateActive
()
s
.
rQ
<-
pkg
pktBuf
.
Next
(
pkgLen
)
// continue to handle case 4
}
if
exit
{
break
...
...
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