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
3d7706a1
Commit
3d7706a1
authored
Sep 03, 2016
by
alexstocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
v0.3.01
parent
160d42fa
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
16 deletions
+45
-16
README.md
README.md
+13
-0
session.go
session.go
+31
-15
version.go
version.go
+1
-1
No files found.
README.md
View file @
3d7706a1
...
@@ -10,6 +10,19 @@
...
@@ -10,6 +10,19 @@
## develop history ##
## develop history ##
---
---
-
2016/09/03
> 1 modify return value of session.go:(Session)Close from void to error
>
> 2 add clause "this.attrs = nil" in session.go:(Session)Close
>
> 3 modify session.go:Session{*gettyConn} to session.go:Session{gettyConn}
>
> 4 session.go:(Session)Reset
>
> 5 session.go:(Session)SetConn
>
> 6 version: 0.3.01
-
2016/09/02
-
2016/09/02
> 1 add session.go:(gettyConn)close and session.go:(Session)dispose
> 1 add session.go:(gettyConn)close and session.go:(Session)dispose
>
>
...
...
session.go
View file @
3d7706a1
...
@@ -17,9 +17,7 @@ import (
...
@@ -17,9 +17,7 @@ import (
"sync"
"sync"
"sync/atomic"
"sync/atomic"
"time"
"time"
)
import
(
log
"github.com/AlexStocks/log4go"
log
"github.com/AlexStocks/log4go"
)
)
...
@@ -32,16 +30,14 @@ const (
...
@@ -32,16 +30,14 @@ const (
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"
)
)
var
(
connID
uint32
ErrSessionClosed
=
errors
.
New
(
"Session Already Closed"
)
ErrSessionBlocked
=
errors
.
New
(
"Session full blocked"
)
)
/////////////////////////////////////////
/////////////////////////////////////////
// getty connection
// getty connection
/////////////////////////////////////////
/////////////////////////////////////////
var
(
connID
uint32
)
type
gettyConn
struct
{
type
gettyConn
struct
{
conn
net
.
Conn
conn
net
.
Conn
ID
uint32
ID
uint32
...
@@ -51,8 +47,8 @@ type gettyConn struct {
...
@@ -51,8 +47,8 @@ type gettyConn struct {
writePkgCount
uint32
// recv pkg count
writePkgCount
uint32
// recv pkg count
}
}
func
newGettyConn
(
conn
net
.
Conn
)
*
gettyConn
{
func
newGettyConn
(
conn
net
.
Conn
)
gettyConn
{
return
&
gettyConn
{
conn
:
conn
,
ID
:
atomic
.
AddUint32
(
&
connID
,
1
)}
return
gettyConn
{
conn
:
conn
,
ID
:
atomic
.
AddUint32
(
&
connID
,
1
)}
}
}
func
(
this
*
gettyConn
)
read
(
p
[]
byte
)
(
int
,
error
)
{
func
(
this
*
gettyConn
)
read
(
p
[]
byte
)
(
int
,
error
)
{
...
@@ -87,11 +83,16 @@ func (this *gettyConn) incWritePkgCount() {
...
@@ -87,11 +83,16 @@ func (this *gettyConn) incWritePkgCount() {
// session
// session
/////////////////////////////////////////
/////////////////////////////////////////
var
(
ErrSessionClosed
=
errors
.
New
(
"Session Already Closed"
)
ErrSessionBlocked
=
errors
.
New
(
"Session full blocked"
)
)
// getty base session
// getty base session
type
Session
struct
{
type
Session
struct
{
name
string
name
string
// net read write
// net read write
*
gettyConn
gettyConn
pkgHandler
ReadWriter
pkgHandler
ReadWriter
listener
EventListener
listener
EventListener
once
sync
.
Once
once
sync
.
Once
...
@@ -126,7 +127,19 @@ func NewSession(conn net.Conn) *Session {
...
@@ -126,7 +127,19 @@ func NewSession(conn net.Conn) *Session {
}
}
}
}
func
(
this
*
Session
)
Conn
()
net
.
Conn
{
return
this
.
conn
}
func
(
this
*
Session
)
Reset
()
{
this
.
name
=
defaultSessionName
this
.
done
=
make
(
chan
struct
{})
this
.
readerDone
=
make
(
chan
struct
{})
this
.
cronPeriod
=
cronPeriod
this
.
readDeadline
=
netIOTimeout
this
.
writeDeadline
=
netIOTimeout
this
.
wait
=
pendingDuration
this
.
attrs
=
make
(
map
[
string
]
interface
{})
}
func
(
this
*
Session
)
SetConn
(
conn
net
.
Conn
)
{
this
.
gettyConn
=
newGettyConn
(
conn
)
}
func
(
this
*
Session
)
Conn
()
net
.
Conn
{
return
this
.
conn
}
func
(
this
*
Session
)
Stat
()
string
{
func
(
this
*
Session
)
Stat
()
string
{
return
fmt
.
Sprintf
(
return
fmt
.
Sprintf
(
...
@@ -256,10 +269,13 @@ func (this *Session) stop() {
...
@@ -256,10 +269,13 @@ func (this *Session) stop() {
}
}
}
}
func
(
this
*
Session
)
Close
()
{
func
(
this
*
Session
)
Close
()
error
{
this
.
stop
()
this
.
stop
()
this
.
attrs
=
nil
log
.
Info
(
"%s closed now, its current gr num %d"
,
log
.
Info
(
"%s closed now, its current gr num %d"
,
this
.
sessionToken
(),
atomic
.
LoadInt32
(
&
(
this
.
grNum
)))
this
.
sessionToken
(),
atomic
.
LoadInt32
(
&
(
this
.
grNum
)))
return
nil
}
}
func
(
this
*
Session
)
sessionToken
()
string
{
func
(
this
*
Session
)
sessionToken
()
string
{
...
@@ -366,8 +382,8 @@ LOOP:
...
@@ -366,8 +382,8 @@ LOOP:
break
LOOP
break
LOOP
case
inPkg
=
<-
this
.
rQ
:
case
inPkg
=
<-
this
.
rQ
:
if
this
.
listener
!=
nil
{
if
this
.
listener
!=
nil
{
this
.
incReadPkgCount
()
this
.
listener
.
OnMessage
(
this
,
inPkg
)
this
.
listener
.
OnMessage
(
this
,
inPkg
)
this
.
incReadPkgCount
()
}
}
case
outPkg
=
<-
this
.
wQ
:
case
outPkg
=
<-
this
.
wQ
:
if
err
=
this
.
pkgHandler
.
Write
(
this
,
outPkg
);
err
!=
nil
{
if
err
=
this
.
pkgHandler
.
Write
(
this
,
outPkg
);
err
!=
nil
{
...
@@ -403,8 +419,8 @@ LAST:
...
@@ -403,8 +419,8 @@ LAST:
this
.
incWritePkgCount
()
this
.
incWritePkgCount
()
case
inPkg
=
<-
this
.
rQ
:
case
inPkg
=
<-
this
.
rQ
:
if
this
.
listener
!=
nil
{
if
this
.
listener
!=
nil
{
this
.
incReadPkgCount
()
this
.
listener
.
OnMessage
(
this
,
inPkg
)
this
.
listener
.
OnMessage
(
this
,
inPkg
)
this
.
incReadPkgCount
()
}
}
default
:
default
:
log
.
Info
(
"%s, [session.handleLoop] default"
,
this
.
sessionToken
())
log
.
Info
(
"%s, [session.handleLoop] default"
,
this
.
sessionToken
())
...
...
version.go
View file @
3d7706a1
...
@@ -10,5 +10,5 @@
...
@@ -10,5 +10,5 @@
package
getty
package
getty
var
(
var
(
Version
=
"0.3.0
0
"
Version
=
"0.3.0
1
"
)
)
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