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
f5224e3a
Commit
f5224e3a
authored
Nov 01, 2016
by
alexstocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add remarks for session.go
parent
0cc6334b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
10 deletions
+30
-10
change_log.md
change_log.md
+8
-0
codec.go
codec.go
+2
-2
session.go
session.go
+17
-5
version.go
version.go
+3
-3
No files found.
change_log.md
View file @
f5224e3a
...
...
@@ -11,6 +11,14 @@
## develop history ##
---
-
2016/11/01
> 1 session.go:Session{maxPkgLen(int)} -> Session{maxPkgLen(int32)}
>
> 2 add remarks in session.go
>
> 2 version: 0.4.07
-
2016/10/21
> 1 session.go:(Session)RunEventLoop -> session.go:(Session)run
>
...
...
codec.go
View file @
f5224e3a
...
...
@@ -27,7 +27,7 @@ type Writer interface {
Write
(
*
Session
,
interface
{})
error
}
// tcp pack
et
handler interface
// tcp pack
age
handler interface
type
ReadWriter
interface
{
Reader
Writer
...
...
@@ -50,6 +50,6 @@ type EventListener interface {
// invoked when receive packge. Pls attention that do not handle long time logic processing in this func.
// Y'd better set the package's maximum length. If the message's length is greater than it, u should
// should return err and getty will close this connection soon.
// should return err
in Reader{Read}
and getty will close this connection soon.
OnMessage
(
*
Session
,
interface
{})
}
session.go
View file @
f5224e3a
...
...
@@ -54,7 +54,7 @@ type empty struct{}
// getty base session
type
Session
struct
{
name
string
maxMsgLen
int
maxMsgLen
int
32
// net read write
iConn
// pkgHandler ReadWriter
...
...
@@ -193,9 +193,13 @@ func (this *Session) IsClosed() bool {
}
}
func
(
this
*
Session
)
SetMaxMsgLen
(
len
int
)
{
this
.
maxMsgLen
=
len
}
func
(
this
*
Session
)
Set
Name
(
name
string
)
{
this
.
name
=
name
}
// set maximum pacakge length of every pacakge in (EventListener)OnMessage(@pkgs)
func
(
this
*
Session
)
Set
MaxMsgLen
(
length
int
)
{
this
.
maxMsgLen
=
int32
(
length
)
}
// set session name
func
(
this
*
Session
)
SetName
(
name
string
)
{
this
.
name
=
name
}
// set EventListener
func
(
this
*
Session
)
SetEventListener
(
listener
EventListener
)
{
this
.
listener
=
listener
}
...
...
@@ -207,10 +211,12 @@ func (this *Session) SetPkgHandler(handler ReadWriter) {
// this.pkgHandler = handler
}
// set Reader
func
(
this
*
Session
)
SetReader
(
reader
Reader
)
{
this
.
reader
=
reader
}
// set Writer
func
(
this
*
Session
)
SetWriter
(
writer
Writer
)
{
this
.
writer
=
writer
}
...
...
@@ -275,6 +281,7 @@ func (this *Session) SetWaitTime(waitTime time.Duration) {
this
.
lock
.
Unlock
()
}
// set attribute of key @session:key
func
(
this
*
Session
)
GetAttribute
(
key
string
)
interface
{}
{
var
ret
interface
{}
this
.
lock
.
RLock
()
...
...
@@ -283,22 +290,26 @@ func (this *Session) GetAttribute(key string) interface{} {
return
ret
}
// get attribute of key @session:key
func
(
this
*
Session
)
SetAttribute
(
key
string
,
value
interface
{})
{
this
.
lock
.
Lock
()
this
.
attrs
[
key
]
=
value
this
.
lock
.
Unlock
()
}
// delete attribute of key @session:key
func
(
this
*
Session
)
RemoveAttribute
(
key
string
)
{
this
.
lock
.
Lock
()
delete
(
this
.
attrs
,
key
)
this
.
lock
.
Unlock
()
}
// update session's active time
func
(
this
*
Session
)
UpdateActive
()
{
this
.
updateActive
()
}
// get session's active time
func
(
this
*
Session
)
GetActive
()
time
.
Time
{
return
this
.
getActive
()
}
...
...
@@ -356,6 +367,7 @@ func (this *Session) WriteBytes(pkg []byte) error {
return
this
.
iConn
.
write
(
pkg
)
}
// write multiple packages at once
func
(
this
*
Session
)
WriteBytesArray
(
pkgs
...
[]
byte
)
error
{
if
this
.
IsClosed
()
{
return
ErrSessionClosed
...
...
@@ -602,7 +614,7 @@ func (this *Session) handleTCPPackage() error {
}
// pkg, err = this.pkgHandler.Read(this, pktBuf)
pkg
,
pkgLen
,
err
=
this
.
reader
.
Read
(
this
,
pktBuf
.
Bytes
())
if
err
==
nil
&&
this
.
maxMsgLen
>
0
&&
pkgLen
>
this
.
maxMsgLen
{
if
err
==
nil
&&
this
.
maxMsgLen
>
0
&&
pkgLen
>
int
(
this
.
maxMsgLen
)
{
err
=
ErrMsgTooLong
}
if
err
!=
nil
{
...
...
@@ -656,7 +668,7 @@ func (this *Session) handleWSPackage() error {
this
.
updateActive
()
if
this
.
reader
!=
nil
{
unmarshalPkg
,
length
,
err
=
this
.
reader
.
Read
(
this
,
pkg
)
if
err
==
nil
&&
this
.
maxMsgLen
>
0
&&
length
>
this
.
maxMsgLen
{
if
err
==
nil
&&
this
.
maxMsgLen
>
0
&&
length
>
int
(
this
.
maxMsgLen
)
{
err
=
ErrMsgTooLong
}
if
err
!=
nil
{
...
...
version.go
View file @
f5224e3a
...
...
@@ -10,9 +10,9 @@
package
getty
const
(
Version
=
"0.4.0
5
"
DATE
=
"2016/1
0/2
1"
Version
=
"0.4.0
7
"
DATE
=
"2016/1
1/0
1"
GETTY_MAJOR
=
0
GETTY_MINOR
=
4
GETTY_BUILD
=
5
GETTY_BUILD
=
7
)
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