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
9ff81a94
Commit
9ff81a94
authored
Oct 15, 2016
by
alexstocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify version & echo package format
parent
9de187bb
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
26 additions
and
25 deletions
+26
-25
client.go
echo/tcp-echo/client/app/client.go
+3
-4
echo.go
echo/tcp-echo/client/app/echo.go
+3
-3
handler.go
echo/tcp-echo/client/app/handler.go
+2
-3
main.go
echo/tcp-echo/client/app/main.go
+1
-1
version.go
echo/tcp-echo/client/app/version.go
+1
-1
echo.go
echo/tcp-echo/server/app/echo.go
+3
-4
handler.go
echo/tcp-echo/server/app/handler.go
+9
-5
version.go
echo/tcp-echo/server/app/version.go
+1
-1
version.go
echo/ws-echo/client/app/version.go
+1
-1
config.toml
echo/ws-echo/client/profiles/test/config.toml
+1
-1
.handler.go.swp
echo/ws-echo/server/app/.handler.go.swp
+0
-0
version.go
echo/ws-echo/server/app/version.go
+1
-1
No files found.
echo/tcp-echo/client/app/client.go
View file @
9ff81a94
...
...
@@ -53,7 +53,7 @@ func (this *EchoClient) close() {
if
client
.
gettyClient
!=
nil
{
for
_
,
s
:=
range
this
.
sessions
{
log
.
Info
(
"close client session{%s, last active:%s, request number:%d}"
,
s
.
session
.
Stat
(),
s
.
active
.
String
(),
s
.
reqNum
)
s
.
session
.
Stat
(),
s
.
session
.
GetActive
()
.
String
(),
s
.
reqNum
)
s
.
session
.
Close
()
}
client
.
gettyClient
.
Close
()
...
...
@@ -83,7 +83,7 @@ func (this *EchoClient) addSession(session *getty.Session) {
}
this
.
lock
.
Lock
()
this
.
sessions
=
append
(
this
.
sessions
,
&
clientEchoSession
{
session
:
session
,
active
:
time
.
Now
()
})
this
.
sessions
=
append
(
this
.
sessions
,
&
clientEchoSession
{
session
:
session
})
this
.
lock
.
Unlock
()
}
...
...
@@ -115,7 +115,6 @@ func (this *EchoClient) updateSession(session *getty.Session) {
for
i
,
s
:=
range
this
.
sessions
{
if
s
.
session
==
session
{
this
.
sessions
[
i
]
.
active
=
time
.
Now
()
this
.
sessions
[
i
]
.
reqNum
++
break
}
...
...
@@ -154,7 +153,7 @@ func (this *EchoClient) heartbeat(session *getty.Session) {
// pkg.H.ServiceID = 0
pkg
.
H
.
Command
=
heartbeatCmd
pkg
.
B
=
echoHeartbeatRequestString
pkg
.
H
.
Len
=
(
uint16
)(
len
(
pkg
.
B
))
pkg
.
H
.
Len
=
(
uint16
)(
len
(
pkg
.
B
)
+
1
)
if
err
:=
session
.
WritePkg
(
&
pkg
);
err
!=
nil
{
log
.
Warn
(
"session.WritePkg(session{%s}, pkg{%s}) = error{%v}"
,
session
.
Stat
(),
pkg
,
err
)
...
...
echo/tcp-echo/client/app/echo.go
View file @
9ff81a94
...
...
@@ -4,7 +4,7 @@
# LICENCE : Apache License 2.0
# EMAIL : alexstocks@foxmail.com
# MOD : 2016-08-22 17:44
# FILE :
utils
.go
# FILE :
echo
.go
******************************************************/
package
main
...
...
@@ -131,7 +131,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
if
buf
.
Len
()
<
(
int
)(
this
.
H
.
Len
)
{
return
0
,
ErrNotEnoughSteam
}
if
maxEchoStringLen
<
this
.
H
.
Len
{
if
maxEchoStringLen
<
this
.
H
.
Len
-
1
{
return
0
,
ErrTooLargePackage
}
...
...
@@ -141,5 +141,5 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
}
this
.
B
=
(
string
)(
buf
.
Next
((
int
)(
len
)))
return
(
int
)(
this
.
H
.
Len
)
+
1
+
echoPkgHeaderLen
,
nil
return
(
int
)(
this
.
H
.
Len
)
+
echoPkgHeaderLen
,
nil
}
echo/tcp-echo/client/app/handler.go
View file @
9ff81a94
...
...
@@ -29,7 +29,6 @@ var (
type
clientEchoSession
struct
{
session
*
getty
.
Session
active
time
.
Time
reqNum
int32
}
...
...
@@ -73,9 +72,9 @@ func (this *EchoMessageHandler) OnCron(session *getty.Session) {
log
.
Error
(
"client.getClientSession(session{%s}) = error{%#v}"
,
session
.
Stat
(),
err
)
return
}
if
conf
.
sessionTimeout
.
Nanoseconds
()
<
time
.
Since
(
clientEchoSession
.
active
)
.
Nanoseconds
()
{
if
conf
.
sessionTimeout
.
Nanoseconds
()
<
time
.
Since
(
session
.
GetActive
()
)
.
Nanoseconds
()
{
log
.
Warn
(
"session{%s} timeout{%s}, reqNum{%d}"
,
session
.
Stat
(),
time
.
Since
(
clientEchoSession
.
active
)
.
String
(),
clientEchoSession
.
reqNum
)
session
.
Stat
(),
time
.
Since
(
session
.
GetActive
()
)
.
String
(),
clientEchoSession
.
reqNum
)
client
.
removeSession
(
session
)
return
}
...
...
echo/tcp-echo/client/app/main.go
View file @
9ff81a94
...
...
@@ -146,7 +146,7 @@ func echo() {
// pkg.H.ServiceID = 0
pkg
.
H
.
Command
=
echoCmd
pkg
.
B
=
conf
.
EchoString
pkg
.
H
.
Len
=
(
uint16
)(
len
(
pkg
.
B
))
pkg
.
H
.
Len
=
(
uint16
)(
len
(
pkg
.
B
))
+
1
if
session
:=
client
.
selectSession
();
session
!=
nil
{
err
:=
session
.
WritePkg
(
&
pkg
)
...
...
echo/tcp-echo/client/app/version.go
View file @
9ff81a94
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.
3.07
"
Version
=
"0.
4.04
"
)
echo/tcp-echo/server/app/echo.go
View file @
9ff81a94
...
...
@@ -4,7 +4,7 @@
# LICENCE : Apache License 2.0
# EMAIL : alexstocks@foxmail.com
# MOD : 2016-08-22 17:44
# FILE :
utils
.go
# FILE :
echo
.go
******************************************************/
package
main
...
...
@@ -51,7 +51,6 @@ const (
echoHeartbeatRequestString
=
"ping"
echoHeartbeatResponseString
=
"pong"
echoMessage
=
"Hello, getty!"
)
var
(
...
...
@@ -133,7 +132,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
return
0
,
ErrNotEnoughSteam
}
// 防止恶意客户端把这个字段设置过大导致服务端死等或者服务端在准备对应的缓冲区时内存崩溃
if
maxEchoStringLen
<
this
.
H
.
Len
{
if
maxEchoStringLen
<
this
.
H
.
Len
-
1
{
return
0
,
ErrTooLargePackage
}
...
...
@@ -143,5 +142,5 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
}
this
.
B
=
(
string
)(
buf
.
Next
((
int
)(
len
)))
return
(
int
)(
this
.
H
.
Len
)
+
1
+
echoPkgHeaderLen
,
nil
return
(
int
)(
this
.
H
.
Len
)
+
echoPkgHeaderLen
,
nil
}
echo/tcp-echo/server/app/handler.go
View file @
9ff81a94
...
...
@@ -40,7 +40,7 @@ func (this *HeartbeatHandler) Handle(session *getty.Session, pkg *EchoPackage) e
var
rspPkg
EchoPackage
rspPkg
.
H
=
pkg
.
H
rspPkg
.
B
=
echoHeartbeatResponseString
rspPkg
.
H
.
Len
=
uint16
(
len
(
rspPkg
.
B
))
rspPkg
.
H
.
Len
=
uint16
(
len
(
rspPkg
.
B
)
+
1
)
return
session
.
WritePkg
(
&
rspPkg
)
}
...
...
@@ -97,7 +97,7 @@ func (this *EchoMessageHandler) OnOpen(session *getty.Session) error {
log
.
Info
(
"got session:%s"
,
session
.
Stat
())
this
.
rwlock
.
Lock
()
this
.
sessionMap
[
session
]
=
&
clientEchoSession
{
session
:
session
,
active
:
time
.
Now
()
}
this
.
sessionMap
[
session
]
=
&
clientEchoSession
{
session
:
session
}
this
.
rwlock
.
Unlock
()
return
nil
}
...
...
@@ -140,13 +140,17 @@ func (this *EchoMessageHandler) OnMessage(session *getty.Session, pkg interface{
}
func
(
this
*
EchoMessageHandler
)
OnCron
(
session
*
getty
.
Session
)
{
var
flag
bool
var
(
flag
bool
active
time
.
Time
)
this
.
rwlock
.
RLock
()
if
_
,
ok
:=
this
.
sessionMap
[
session
];
ok
{
if
conf
.
sessionTimeout
.
Nanoseconds
()
<
time
.
Since
(
this
.
sessionMap
[
session
]
.
active
)
.
Nanoseconds
()
{
active
=
session
.
GetActive
()
if
conf
.
sessionTimeout
.
Nanoseconds
()
<
time
.
Since
(
active
)
.
Nanoseconds
()
{
flag
=
true
log
.
Warn
(
"session{%s} timeout{%s}, reqNum{%d}"
,
session
.
Stat
(),
time
.
Since
(
this
.
sessionMap
[
session
]
.
active
)
.
String
(),
this
.
sessionMap
[
session
]
.
reqNum
)
session
.
Stat
(),
time
.
Since
(
active
)
.
String
(),
this
.
sessionMap
[
session
]
.
reqNum
)
}
}
this
.
rwlock
.
RUnlock
()
...
...
echo/tcp-echo/server/app/version.go
View file @
9ff81a94
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.
3.07
"
Version
=
"0.
4.04
"
)
echo/ws-echo/client/app/version.go
View file @
9ff81a94
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.
3.07
"
Version
=
"0.
4.04
"
)
echo/ws-echo/client/profiles/test/config.toml
View file @
9ff81a94
...
...
@@ -7,7 +7,7 @@ AppName = "ECHO-CLIENT"
LocalHost
=
"127.0.0.1"
# server
ServerHost
=
"192.168.35.
3
"
ServerHost
=
"192.168.35.
1
"
ServerPort
=
10000
ServerPath
=
"/echo"
ProfilePort
=
10080
...
...
echo/ws-echo/server/app/.handler.go.swp
deleted
100644 → 0
View file @
9de187bb
File deleted
echo/ws-echo/server/app/version.go
View file @
9ff81a94
...
...
@@ -10,5 +10,5 @@
package
main
var
(
Version
=
"0.
3.07
"
Version
=
"0.
4.04
"
)
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