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
ee22cae5
Commit
ee22cae5
authored
Sep 03, 2016
by
alexstocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify readme
parent
3d7706a1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
34 deletions
+34
-34
README.md
README.md
+1
-1
session.go
session.go
+33
-33
No files found.
README.md
View file @
ee22cae5
...
...
@@ -15,7 +15,7 @@
>
> 2 add clause "this.attrs = nil" in session.go:(Session)Close
>
> 3
modify session.go:Session{*gettyConn} to session.go:Session{gettyConn
}
> 3
session.go:Session{*gettyConn, readDeadline, writeDeadline} -> session.go:Session{gettyConn, rDeadline, wDeadline
}
>
> 4 session.go:(Session)Reset
>
...
...
session.go
View file @
ee22cae5
...
...
@@ -24,7 +24,7 @@ import (
const
(
maxReadBufLen
=
4
*
1024
netIOTimeout
=
100e6
// 100ms
cronPeriod
=
60
*
1e9
// 1 minute
peroid
=
60
*
1e9
// 1 minute
pendingDuration
=
3e9
defaultSessionName
=
"Session"
outputFormat
=
"session %s, Read Count: %d, Write Count: %d, Read Pkg Count: %d, Write Pkg Count: %d"
...
...
@@ -99,12 +99,12 @@ type Session struct {
done
chan
struct
{}
readerDone
chan
struct
{}
// end reader
cronPerio
d
time
.
Duration
r
eadDeadline
time
.
Duration
w
rite
Deadline
time
.
Duration
wait
time
.
Duration
rQ
chan
interface
{}
wQ
chan
interface
{}
peroi
d
time
.
Duration
r
Deadline
time
.
Duration
wDeadline
time
.
Duration
wait
time
.
Duration
rQ
chan
interface
{}
wQ
chan
interface
{}
// attribute
attrs
map
[
string
]
interface
{}
...
...
@@ -115,15 +115,15 @@ type Session struct {
func
NewSession
(
conn
net
.
Conn
)
*
Session
{
return
&
Session
{
name
:
defaultSessionName
,
gettyConn
:
newGettyConn
(
conn
),
done
:
make
(
chan
struct
{}),
readerDone
:
make
(
chan
struct
{}),
cronPeriod
:
cronPerio
d
,
r
ead
Deadline
:
netIOTimeout
,
w
riteDeadline
:
netIOTimeout
,
wait
:
pendingDuration
,
attrs
:
make
(
map
[
string
]
interface
{}),
name
:
defaultSessionName
,
gettyConn
:
newGettyConn
(
conn
),
done
:
make
(
chan
struct
{}),
readerDone
:
make
(
chan
struct
{}),
peroid
:
peroi
d
,
rDeadline
:
netIOTimeout
,
w
Deadline
:
netIOTimeout
,
wait
:
pendingDuration
,
attrs
:
make
(
map
[
string
]
interface
{}),
}
}
...
...
@@ -131,9 +131,9 @@ func (this *Session) Reset() {
this
.
name
=
defaultSessionName
this
.
done
=
make
(
chan
struct
{})
this
.
readerDone
=
make
(
chan
struct
{})
this
.
cronPeriod
=
cronPerio
d
this
.
r
ead
Deadline
=
netIOTimeout
this
.
w
rite
Deadline
=
netIOTimeout
this
.
peroid
=
peroi
d
this
.
rDeadline
=
netIOTimeout
this
.
wDeadline
=
netIOTimeout
this
.
wait
=
pendingDuration
this
.
attrs
=
make
(
map
[
string
]
interface
{})
}
...
...
@@ -179,7 +179,7 @@ func (this *Session) SetCronPeriod(period int) {
}
this
.
lock
.
Lock
()
this
.
cronPerio
d
=
time
.
Duration
(
period
)
*
time
.
Millisecond
this
.
peroi
d
=
time
.
Duration
(
period
)
*
time
.
Millisecond
this
.
lock
.
Unlock
()
}
...
...
@@ -205,26 +205,26 @@ func (this *Session) SetWQLen(writeQLen int) {
this
.
lock
.
Unlock
()
}
func
(
this
*
Session
)
SetReadDeadline
(
r
ead
Deadline
time
.
Duration
)
{
if
r
ead
Deadline
<
1
{
panic
(
"@r
ead
Deadline < 1"
)
func
(
this
*
Session
)
SetReadDeadline
(
rDeadline
time
.
Duration
)
{
if
rDeadline
<
1
{
panic
(
"@rDeadline < 1"
)
}
this
.
lock
.
Lock
()
this
.
r
eadDeadline
=
read
Deadline
if
this
.
w
rite
Deadline
==
0
{
this
.
w
riteDeadline
=
read
Deadline
this
.
r
Deadline
=
r
Deadline
if
this
.
wDeadline
==
0
{
this
.
w
Deadline
=
r
Deadline
}
this
.
lock
.
Unlock
()
}
func
(
this
*
Session
)
SetWriteDeadline
(
w
rite
Deadline
time
.
Duration
)
{
if
w
rite
Deadline
<
1
{
panic
(
"@w
rite
Deadline < 1"
)
func
(
this
*
Session
)
SetWriteDeadline
(
wDeadline
time
.
Duration
)
{
if
wDeadline
<
1
{
panic
(
"@wDeadline < 1"
)
}
this
.
lock
.
Lock
()
this
.
w
riteDeadline
=
write
Deadline
this
.
w
Deadline
=
w
Deadline
this
.
lock
.
Unlock
()
}
...
...
@@ -312,7 +312,7 @@ func (this *Session) WritePkg(pkg interface{}) error {
// for codecs
func
(
this
*
Session
)
WriteBytes
(
pkg
[]
byte
)
error
{
this
.
conn
.
SetWriteDeadline
(
time
.
Now
()
.
Add
(
this
.
r
ead
Deadline
))
this
.
conn
.
SetWriteDeadline
(
time
.
Now
()
.
Add
(
this
.
rDeadline
))
_
,
err
:=
this
.
write
(
pkg
)
return
err
}
...
...
@@ -373,7 +373,7 @@ func (this *Session) handleLoop() {
this
.
listener
.
OnOpen
(
this
)
}
ticker
=
time
.
NewTicker
(
this
.
cronPerio
d
)
ticker
=
time
.
NewTicker
(
this
.
peroi
d
)
LOOP
:
for
{
select
{
...
...
@@ -469,7 +469,7 @@ func (this *Session) handlePackage() {
if
exit
{
break
// 退出前不再读取任何packet,跳到下个for-loop处理完pktBuf中的stream
}
this
.
conn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
this
.
r
ead
Deadline
))
this
.
conn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
this
.
rDeadline
))
len
,
err
=
this
.
read
(
buf
)
if
err
!=
nil
{
if
nerr
,
ok
=
err
.
(
net
.
Error
);
ok
&&
nerr
.
Timeout
()
{
...
...
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