Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
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() {
...
@@ -53,7 +53,7 @@ func (this *EchoClient) close() {
if
client
.
gettyClient
!=
nil
{
if
client
.
gettyClient
!=
nil
{
for
_
,
s
:=
range
this
.
sessions
{
for
_
,
s
:=
range
this
.
sessions
{
log
.
Info
(
"close client session{%s, last active:%s, request number:%d}"
,
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
()
s
.
session
.
Close
()
}
}
client
.
gettyClient
.
Close
()
client
.
gettyClient
.
Close
()
...
@@ -83,7 +83,7 @@ func (this *EchoClient) addSession(session *getty.Session) {
...
@@ -83,7 +83,7 @@ func (this *EchoClient) addSession(session *getty.Session) {
}
}
this
.
lock
.
Lock
()
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
()
this
.
lock
.
Unlock
()
}
}
...
@@ -115,7 +115,6 @@ func (this *EchoClient) updateSession(session *getty.Session) {
...
@@ -115,7 +115,6 @@ func (this *EchoClient) updateSession(session *getty.Session) {
for
i
,
s
:=
range
this
.
sessions
{
for
i
,
s
:=
range
this
.
sessions
{
if
s
.
session
==
session
{
if
s
.
session
==
session
{
this
.
sessions
[
i
]
.
active
=
time
.
Now
()
this
.
sessions
[
i
]
.
reqNum
++
this
.
sessions
[
i
]
.
reqNum
++
break
break
}
}
...
@@ -154,7 +153,7 @@ func (this *EchoClient) heartbeat(session *getty.Session) {
...
@@ -154,7 +153,7 @@ func (this *EchoClient) heartbeat(session *getty.Session) {
// pkg.H.ServiceID = 0
// pkg.H.ServiceID = 0
pkg
.
H
.
Command
=
heartbeatCmd
pkg
.
H
.
Command
=
heartbeatCmd
pkg
.
B
=
echoHeartbeatRequestString
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
{
if
err
:=
session
.
WritePkg
(
&
pkg
);
err
!=
nil
{
log
.
Warn
(
"session.WritePkg(session{%s}, pkg{%s}) = error{%v}"
,
session
.
Stat
(),
pkg
,
err
)
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 @@
...
@@ -4,7 +4,7 @@
# LICENCE : Apache License 2.0
# LICENCE : Apache License 2.0
# EMAIL : alexstocks@foxmail.com
# EMAIL : alexstocks@foxmail.com
# MOD : 2016-08-22 17:44
# MOD : 2016-08-22 17:44
# FILE :
utils
.go
# FILE :
echo
.go
******************************************************/
******************************************************/
package
main
package
main
...
@@ -131,7 +131,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
...
@@ -131,7 +131,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
if
buf
.
Len
()
<
(
int
)(
this
.
H
.
Len
)
{
if
buf
.
Len
()
<
(
int
)(
this
.
H
.
Len
)
{
return
0
,
ErrNotEnoughSteam
return
0
,
ErrNotEnoughSteam
}
}
if
maxEchoStringLen
<
this
.
H
.
Len
{
if
maxEchoStringLen
<
this
.
H
.
Len
-
1
{
return
0
,
ErrTooLargePackage
return
0
,
ErrTooLargePackage
}
}
...
@@ -141,5 +141,5 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
...
@@ -141,5 +141,5 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
}
}
this
.
B
=
(
string
)(
buf
.
Next
((
int
)(
len
)))
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 (
...
@@ -29,7 +29,6 @@ var (
type
clientEchoSession
struct
{
type
clientEchoSession
struct
{
session
*
getty
.
Session
session
*
getty
.
Session
active
time
.
Time
reqNum
int32
reqNum
int32
}
}
...
@@ -73,9 +72,9 @@ func (this *EchoMessageHandler) OnCron(session *getty.Session) {
...
@@ -73,9 +72,9 @@ func (this *EchoMessageHandler) OnCron(session *getty.Session) {
log
.
Error
(
"client.getClientSession(session{%s}) = error{%#v}"
,
session
.
Stat
(),
err
)
log
.
Error
(
"client.getClientSession(session{%s}) = error{%#v}"
,
session
.
Stat
(),
err
)
return
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}"
,
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
)
client
.
removeSession
(
session
)
return
return
}
}
...
...
echo/tcp-echo/client/app/main.go
View file @
9ff81a94
...
@@ -146,7 +146,7 @@ func echo() {
...
@@ -146,7 +146,7 @@ func echo() {
// pkg.H.ServiceID = 0
// pkg.H.ServiceID = 0
pkg
.
H
.
Command
=
echoCmd
pkg
.
H
.
Command
=
echoCmd
pkg
.
B
=
conf
.
EchoString
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
{
if
session
:=
client
.
selectSession
();
session
!=
nil
{
err
:=
session
.
WritePkg
(
&
pkg
)
err
:=
session
.
WritePkg
(
&
pkg
)
...
...
echo/tcp-echo/client/app/version.go
View file @
9ff81a94
...
@@ -10,5 +10,5 @@
...
@@ -10,5 +10,5 @@
package
main
package
main
var
(
var
(
Version
=
"0.
3.07
"
Version
=
"0.
4.04
"
)
)
echo/tcp-echo/server/app/echo.go
View file @
9ff81a94
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
# LICENCE : Apache License 2.0
# LICENCE : Apache License 2.0
# EMAIL : alexstocks@foxmail.com
# EMAIL : alexstocks@foxmail.com
# MOD : 2016-08-22 17:44
# MOD : 2016-08-22 17:44
# FILE :
utils
.go
# FILE :
echo
.go
******************************************************/
******************************************************/
package
main
package
main
...
@@ -51,7 +51,6 @@ const (
...
@@ -51,7 +51,6 @@ const (
echoHeartbeatRequestString
=
"ping"
echoHeartbeatRequestString
=
"ping"
echoHeartbeatResponseString
=
"pong"
echoHeartbeatResponseString
=
"pong"
echoMessage
=
"Hello, getty!"
)
)
var
(
var
(
...
@@ -133,7 +132,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
...
@@ -133,7 +132,7 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
return
0
,
ErrNotEnoughSteam
return
0
,
ErrNotEnoughSteam
}
}
// 防止恶意客户端把这个字段设置过大导致服务端死等或者服务端在准备对应的缓冲区时内存崩溃
// 防止恶意客户端把这个字段设置过大导致服务端死等或者服务端在准备对应的缓冲区时内存崩溃
if
maxEchoStringLen
<
this
.
H
.
Len
{
if
maxEchoStringLen
<
this
.
H
.
Len
-
1
{
return
0
,
ErrTooLargePackage
return
0
,
ErrTooLargePackage
}
}
...
@@ -143,5 +142,5 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
...
@@ -143,5 +142,5 @@ func (this *EchoPackage) Unmarshal(buf *bytes.Buffer) (int, error) {
}
}
this
.
B
=
(
string
)(
buf
.
Next
((
int
)(
len
)))
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
...
@@ -40,7 +40,7 @@ func (this *HeartbeatHandler) Handle(session *getty.Session, pkg *EchoPackage) e
var
rspPkg
EchoPackage
var
rspPkg
EchoPackage
rspPkg
.
H
=
pkg
.
H
rspPkg
.
H
=
pkg
.
H
rspPkg
.
B
=
echoHeartbeatResponseString
rspPkg
.
B
=
echoHeartbeatResponseString
rspPkg
.
H
.
Len
=
uint16
(
len
(
rspPkg
.
B
))
rspPkg
.
H
.
Len
=
uint16
(
len
(
rspPkg
.
B
)
+
1
)
return
session
.
WritePkg
(
&
rspPkg
)
return
session
.
WritePkg
(
&
rspPkg
)
}
}
...
@@ -97,7 +97,7 @@ func (this *EchoMessageHandler) OnOpen(session *getty.Session) error {
...
@@ -97,7 +97,7 @@ func (this *EchoMessageHandler) OnOpen(session *getty.Session) error {
log
.
Info
(
"got session:%s"
,
session
.
Stat
())
log
.
Info
(
"got session:%s"
,
session
.
Stat
())
this
.
rwlock
.
Lock
()
this
.
rwlock
.
Lock
()
this
.
sessionMap
[
session
]
=
&
clientEchoSession
{
session
:
session
,
active
:
time
.
Now
()
}
this
.
sessionMap
[
session
]
=
&
clientEchoSession
{
session
:
session
}
this
.
rwlock
.
Unlock
()
this
.
rwlock
.
Unlock
()
return
nil
return
nil
}
}
...
@@ -140,13 +140,17 @@ func (this *EchoMessageHandler) OnMessage(session *getty.Session, pkg interface{
...
@@ -140,13 +140,17 @@ func (this *EchoMessageHandler) OnMessage(session *getty.Session, pkg interface{
}
}
func
(
this
*
EchoMessageHandler
)
OnCron
(
session
*
getty
.
Session
)
{
func
(
this
*
EchoMessageHandler
)
OnCron
(
session
*
getty
.
Session
)
{
var
flag
bool
var
(
flag
bool
active
time
.
Time
)
this
.
rwlock
.
RLock
()
this
.
rwlock
.
RLock
()
if
_
,
ok
:=
this
.
sessionMap
[
session
];
ok
{
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
flag
=
true
log
.
Warn
(
"session{%s} timeout{%s}, reqNum{%d}"
,
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
()
this
.
rwlock
.
RUnlock
()
...
...
echo/tcp-echo/server/app/version.go
View file @
9ff81a94
...
@@ -10,5 +10,5 @@
...
@@ -10,5 +10,5 @@
package
main
package
main
var
(
var
(
Version
=
"0.
3.07
"
Version
=
"0.
4.04
"
)
)
echo/ws-echo/client/app/version.go
View file @
9ff81a94
...
@@ -10,5 +10,5 @@
...
@@ -10,5 +10,5 @@
package
main
package
main
var
(
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"
...
@@ -7,7 +7,7 @@ AppName = "ECHO-CLIENT"
LocalHost
=
"127.0.0.1"
LocalHost
=
"127.0.0.1"
# server
# server
ServerHost
=
"192.168.35.
3
"
ServerHost
=
"192.168.35.
1
"
ServerPort
=
10000
ServerPort
=
10000
ServerPath
=
"/echo"
ServerPath
=
"/echo"
ProfilePort
=
10080
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 @@
...
@@ -10,5 +10,5 @@
package
main
package
main
var
(
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