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
ec48a400
Commit
ec48a400
authored
Sep 08, 2016
by
alexstocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix bugs
parent
2161daec
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
16 deletions
+28
-16
client.go
echo/client/app/client.go
+3
-1
main.go
echo/client/app/main.go
+9
-0
utils.go
echo/client/app/utils.go
+1
-1
config.toml
echo/client/profiles/test/config.toml
+1
-2
handler.go
echo/server/app/handler.go
+13
-11
utils.go
echo/server/app/utils.go
+1
-1
No files found.
echo/client/app/client.go
View file @
ec48a400
...
...
@@ -156,8 +156,10 @@ func (this *EchoClient) heartbeat(session *getty.Session) {
pkg
.
B
=
echoHeartbeatRequestString
pkg
.
H
.
Len
=
(
uint16
)(
len
(
pkg
.
B
))
if
err
:=
session
.
WritePkg
(
pkg
);
err
!=
nil
{
if
err
:=
session
.
WritePkg
(
&
pkg
);
err
!=
nil
{
log
.
Warn
(
"session.WritePkg(session{%s}, pkg{%s}) = error{%v}"
,
session
.
Stat
(),
pkg
,
err
)
session
.
Close
()
this
.
removeSession
(
session
)
}
}
echo/client/app/main.go
View file @
ec48a400
...
...
@@ -25,6 +25,7 @@ import (
import
(
"github.com/AlexStocks/getty"
"github.com/AlexStocks/gocolor"
log
"github.com/AlexStocks/log4go"
)
...
...
@@ -159,6 +160,7 @@ func echo() {
if
err
!=
nil
{
log
.
Warn
(
"session.WritePkg(session{%s}, pkg{%s}) = error{%v}"
,
session
.
Stat
(),
pkg
,
err
)
session
.
Close
()
client
.
removeSession
(
session
)
}
}
}
...
...
@@ -171,7 +173,14 @@ func test() {
time
.
Sleep
(
1e9
)
}
var
(
cost
int64
counter
getty
.
CountWatch
)
counter
.
Start
()
for
i
:=
0
;
i
<
conf
.
EchoTimes
;
i
++
{
echo
()
}
cost
=
counter
.
Count
()
gocolor
.
Info
(
"after loop %d times, echo cost %d ms"
,
conf
.
EchoTimes
,
cost
/
1e6
)
}
echo/client/app/utils.go
View file @
ec48a400
...
...
@@ -142,5 +142,5 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
}
this
.
B
=
(
string
)(
buf
.
Next
((
int
)(
len
)))
return
(
int
)(
this
.
H
.
Len
)
+
echoPkgHeaderLen
,
nil
return
(
int
)(
this
.
H
.
Len
)
+
1
+
echoPkgHeaderLen
,
nil
}
echo/client/profiles/test/config.toml
View file @
ec48a400
...
...
@@ -2,7 +2,6 @@
LocalHost
=
"127.0.0.1"
# ServerHost = "192.168.35.3"
ServerHost
=
"192.168.35.1"
ServerPort
=
10000
ProfilePort
=
10080
...
...
@@ -18,4 +17,4 @@ HeartbeatPeriod = "10s"
SessionTimeout
=
"20s"
# 发送echo请求次数
EchoTimes
=
100
EchoTimes
=
100
000
echo/server/app/handler.go
View file @
ec48a400
...
...
@@ -25,7 +25,7 @@ var (
)
type
PackageHandler
interface
{
Handle
(
*
getty
.
Session
,
*
EchoPackage
)
Handle
(
*
getty
.
Session
,
*
EchoPackage
)
error
}
////////////////////////////////////////////
...
...
@@ -34,7 +34,7 @@ type PackageHandler interface {
type
HeartbeatHandler
struct
{}
func
(
this
*
HeartbeatHandler
)
Handle
(
session
*
getty
.
Session
,
pkg
*
EchoPackage
)
{
func
(
this
*
HeartbeatHandler
)
Handle
(
session
*
getty
.
Session
,
pkg
*
EchoPackage
)
error
{
log
.
Debug
(
"get echo heartbeat package{%s}"
,
pkg
)
var
rspPkg
EchoPackage
...
...
@@ -42,7 +42,7 @@ func (this *HeartbeatHandler) Handle(session *getty.Session, pkg *EchoPackage) {
rspPkg
.
B
=
echoHeartbeatResponseString
rspPkg
.
H
.
Len
=
uint16
(
len
(
rspPkg
.
B
))
session
.
WritePkg
(
&
rspPkg
)
return
session
.
WritePkg
(
&
rspPkg
)
}
////////////////////////////////////////////
...
...
@@ -51,9 +51,9 @@ func (this *HeartbeatHandler) Handle(session *getty.Session, pkg *EchoPackage) {
type
MessageHandler
struct
{}
func
(
this
*
MessageHandler
)
Handle
(
session
*
getty
.
Session
,
pkg
*
EchoPackage
)
{
func
(
this
*
MessageHandler
)
Handle
(
session
*
getty
.
Session
,
pkg
*
EchoPackage
)
error
{
log
.
Debug
(
"get echo package{%s}"
,
pkg
)
session
.
WritePkg
(
pkg
)
return
session
.
WritePkg
(
pkg
)
}
////////////////////////////////////////////
...
...
@@ -128,13 +128,15 @@ func (this *EchoMessageHandler) OnMessage(session *getty.Session, pkg interface{
log
.
Error
(
"illegal command{%d}"
,
p
.
H
.
Command
)
return
}
handler
.
Handle
(
session
,
p
)
this
.
rwlock
.
Lock
()
if
_
,
ok
:=
this
.
sessionMap
[
session
];
ok
{
this
.
sessionMap
[
session
]
.
active
=
time
.
Now
()
this
.
sessionMap
[
session
]
.
reqNum
++
err
:=
handler
.
Handle
(
session
,
p
)
if
err
!=
nil
{
this
.
rwlock
.
Lock
()
if
_
,
ok
:=
this
.
sessionMap
[
session
];
ok
{
this
.
sessionMap
[
session
]
.
active
=
time
.
Now
()
this
.
sessionMap
[
session
]
.
reqNum
++
}
this
.
rwlock
.
Unlock
()
}
this
.
rwlock
.
Unlock
()
}
func
(
this
*
EchoMessageHandler
)
OnCron
(
session
*
getty
.
Session
)
{
...
...
echo/server/app/utils.go
View file @
ec48a400
...
...
@@ -142,5 +142,5 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
}
this
.
B
=
(
string
)(
buf
.
Next
((
int
)(
len
)))
return
(
int
)(
this
.
H
.
Len
)
+
echoPkgHeaderLen
,
nil
return
(
int
)(
this
.
H
.
Len
)
+
1
+
echoPkgHeaderLen
,
nil
}
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