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