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
0aabe35d
Unverified
Commit
0aabe35d
authored
Jun 25, 2019
by
望哥
Committed by
GitHub
Jun 25, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8 from divebomb/master
Imp: add max buffer length
parents
78e88386
0f516bf7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
20 deletions
+25
-20
getty.go
getty.go
+7
-5
session.go
session.go
+17
-15
task_pool.go
task_pool.go
+1
-0
No files found.
getty.go
View file @
0aabe35d
...
...
@@ -29,14 +29,16 @@ type Reader interface {
// 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;
// case 2: can not unmarshal a pkg header from the streaming segment;
// case 3: unmarshal a pkg header but can not unmarshal a pkg from the streaming segment;
// case 4: just unmarshal a pkg from the streaming segment;
// case 5: 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.
// The return value is (nil, pkgLen, nil) as case 3.
// The return value is (pkg, pkgLen, nil) as case 4.
// The handleTcpPackage may invoke func Read many times as case 5.
Read
(
Session
,
[]
byte
)
(
interface
{},
int
,
error
)
}
...
...
session.go
View file @
0aabe35d
...
...
@@ -664,6 +664,7 @@ func (s *session) handleTCPPackage() error {
}
// pkg, err = s.pkgHandler.Read(s, pktBuf)
pkg
,
pkgLen
,
err
=
s
.
reader
.
Read
(
s
,
pktBuf
.
Bytes
())
// for case 3/case 4
if
err
==
nil
&&
s
.
maxMsgLen
>
0
&&
pkgLen
>
int
(
s
.
maxMsgLen
)
{
err
=
perrors
.
Errorf
(
"pkgLen %d > session max message len %d"
,
pkgLen
,
s
.
maxMsgLen
)
}
...
...
@@ -674,15 +675,15 @@ func (s *session) handleTCPPackage() error {
exit
=
true
break
}
// handle case 2
// handle case 2
/case 3
if
pkg
==
nil
{
break
}
// handle case
3
// handle case
4
s
.
UpdateActive
()
s
.
addTask
(
pkg
)
pktBuf
.
Next
(
pkgLen
)
// continue to handle case
4
// continue to handle case
5
}
if
exit
{
break
...
...
@@ -695,23 +696,24 @@ func (s *session) handleTCPPackage() error {
// get package from udp packet
func
(
s
*
session
)
handleUDPPackage
()
error
{
var
(
ok
bool
err
error
netError
net
.
Error
conn
*
gettyUDPConn
bufLen
int
buf
[]
byte
addr
*
net
.
UDPAddr
pkgLen
int
pkg
interface
{}
ok
bool
err
error
netError
net
.
Error
conn
*
gettyUDPConn
bufLen
int
maxBufLen
int
buf
[]
byte
addr
*
net
.
UDPAddr
pkgLen
int
pkg
interface
{}
)
conn
=
s
.
Connection
.
(
*
gettyUDPConn
)
b
ufLen
=
int
(
s
.
maxMsgLen
+
maxReadBufLen
)
maxB
ufLen
=
int
(
s
.
maxMsgLen
+
maxReadBufLen
)
if
int
(
s
.
maxMsgLen
<<
1
)
<
bufLen
{
b
ufLen
=
int
(
s
.
maxMsgLen
<<
1
)
maxB
ufLen
=
int
(
s
.
maxMsgLen
<<
1
)
}
buf
=
make
([]
byte
,
b
ufLen
)
buf
=
make
([]
byte
,
maxB
ufLen
)
for
{
if
s
.
IsClosed
()
{
break
...
...
task_pool.go
View file @
0aabe35d
...
...
@@ -46,6 +46,7 @@ func NewTaskPool(opts ...TaskPoolOption) *TaskPool {
for
i
:=
0
;
i
<
p
.
tQNumber
;
i
++
{
p
.
qArray
[
i
]
=
make
(
chan
task
,
p
.
tQLen
)
}
p
.
start
()
return
p
}
...
...
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