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
e7956e69
Commit
e7956e69
authored
Mar 17, 2018
by
AlexStocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update udp echo server by getty v0.8.2
parent
9a265ed1
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
30 additions
and
22 deletions
+30
-22
change_log.md
echo/udp-echo/change_log.md
+4
-0
client.go
echo/udp-echo/client/app/client.go
+3
-1
config.go
echo/udp-echo/client/app/config.go
+0
-4
handler.go
echo/udp-echo/client/app/handler.go
+2
-2
main.go
echo/udp-echo/client/app/main.go
+12
-7
readwriter.go
echo/udp-echo/client/app/readwriter.go
+1
-2
log.xml
echo/udp-echo/client/profiles/test/log.xml
+1
-1
server.go
echo/udp-echo/server/app/server.go
+6
-4
version.go
echo/udp-echo/server/app/version.go
+1
-1
No files found.
echo/udp-echo/change_log.md
View file @
e7956e69
...
@@ -10,6 +10,10 @@
...
@@ -10,6 +10,10 @@
## develop history ##
## develop history ##
---
---
-
2018/03/17
> improvement
*
use getty v0.8.2
-
2018/03/16
-
2018/03/16
> bug fix
> bug fix
*
forbid close udp session in OnCron
*
forbid close udp session in OnCron
...
...
echo/udp-echo/client/app/client.go
View file @
e7956e69
...
@@ -19,6 +19,7 @@ import (
...
@@ -19,6 +19,7 @@ import (
import
(
import
(
"github.com/AlexStocks/getty"
"github.com/AlexStocks/getty"
log
"github.com/AlexStocks/log4go"
log
"github.com/AlexStocks/log4go"
"net"
)
)
var
(
var
(
...
@@ -38,6 +39,7 @@ type EchoClient struct {
...
@@ -38,6 +39,7 @@ type EchoClient struct {
lock
sync
.
RWMutex
lock
sync
.
RWMutex
sessions
[]
*
clientEchoSession
sessions
[]
*
clientEchoSession
gettyClient
*
getty
.
Client
gettyClient
*
getty
.
Client
serverAddr
net
.
UDPAddr
}
}
func
(
this
*
EchoClient
)
isAvailable
()
bool
{
func
(
this
*
EchoClient
)
isAvailable
()
bool
{
...
@@ -160,7 +162,7 @@ func (this *EchoClient) heartbeat(session getty.Session) {
...
@@ -160,7 +162,7 @@ func (this *EchoClient) heartbeat(session getty.Session) {
pkg
.
H
.
Len
=
(
uint16
)(
len
(
pkg
.
B
)
+
1
)
pkg
.
H
.
Len
=
(
uint16
)(
len
(
pkg
.
B
)
+
1
)
ctx
.
Pkg
=
&
pkg
ctx
.
Pkg
=
&
pkg
ctx
.
PeerAddr
=
&
(
conf
.
serverAddr
)
ctx
.
PeerAddr
=
&
(
this
.
serverAddr
)
if
err
:=
session
.
WritePkg
(
ctx
,
WritePkgTimeout
);
err
!=
nil
{
if
err
:=
session
.
WritePkg
(
ctx
,
WritePkgTimeout
);
err
!=
nil
{
log
.
Warn
(
"session.WritePkg(session{%s}, context{%#v}) = error{%v}"
,
session
.
Stat
(),
ctx
,
err
)
log
.
Warn
(
"session.WritePkg(session{%s}, context{%#v}) = error{%v}"
,
session
.
Stat
(),
ctx
,
err
)
...
...
echo/udp-echo/client/app/config.go
View file @
e7956e69
...
@@ -19,7 +19,6 @@ import (
...
@@ -19,7 +19,6 @@ import (
import
(
import
(
log
"github.com/AlexStocks/log4go"
log
"github.com/AlexStocks/log4go"
config
"github.com/koding/multiconfig"
config
"github.com/koding/multiconfig"
"net"
)
)
const
(
const
(
...
@@ -57,7 +56,6 @@ type (
...
@@ -57,7 +56,6 @@ type (
ServerHost
string
`default:"127.0.0.1"`
ServerHost
string
`default:"127.0.0.1"`
ServerPort
int
`default:"10000"`
ServerPort
int
`default:"10000"`
ProfilePort
int
`default:"10086"`
ProfilePort
int
`default:"10086"`
serverAddr
net
.
UDPAddr
// session pool
// session pool
ConnectionNum
int
`default:"16"`
ConnectionNum
int
`default:"16"`
...
@@ -104,8 +102,6 @@ func initConf() {
...
@@ -104,8 +102,6 @@ func initConf() {
conf
=
new
(
Config
)
conf
=
new
(
Config
)
config
.
MustLoadWithPath
(
confFile
,
conf
)
config
.
MustLoadWithPath
(
confFile
,
conf
)
conf
.
serverAddr
=
net
.
UDPAddr
{
IP
:
net
.
ParseIP
(
conf
.
ServerHost
),
Port
:
conf
.
ServerPort
}
conf
.
connectInterval
,
err
=
time
.
ParseDuration
(
conf
.
ConnectInterval
)
conf
.
connectInterval
,
err
=
time
.
ParseDuration
(
conf
.
ConnectInterval
)
if
err
!=
nil
{
if
err
!=
nil
{
panic
(
fmt
.
Sprintf
(
"time.ParseDuration(ConnectionInterval{%#v}) = error{%v}"
,
conf
.
ConnectInterval
,
err
))
panic
(
fmt
.
Sprintf
(
"time.ParseDuration(ConnectionInterval{%#v}) = error{%v}"
,
conf
.
ConnectInterval
,
err
))
...
...
echo/udp-echo/client/app/handler.go
View file @
e7956e69
...
@@ -80,8 +80,8 @@ func (this *EchoMessageHandler) OnCron(session getty.Session) {
...
@@ -80,8 +80,8 @@ func (this *EchoMessageHandler) OnCron(session getty.Session) {
if
conf
.
sessionTimeout
.
Nanoseconds
()
<
time
.
Since
(
session
.
GetActive
())
.
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
(
session
.
GetActive
())
.
String
(),
clientEchoSession
.
reqNum
)
session
.
Stat
(),
time
.
Since
(
session
.
GetActive
())
.
String
(),
clientEchoSession
.
reqNum
)
client
.
removeSession
(
session
)
//
client.removeSession(session)
return
//
return
}
}
client
.
heartbeat
(
session
)
client
.
heartbeat
(
session
)
...
...
echo/udp-echo/client/app/main.go
View file @
e7956e69
...
@@ -111,6 +111,7 @@ func initClient() {
...
@@ -111,6 +111,7 @@ func initClient() {
gxnet
.
HostAddress
(
conf
.
ServerHost
,
conf
.
ServerPort
),
gxnet
.
HostAddress
(
conf
.
ServerHost
,
conf
.
ServerPort
),
)
)
client
.
gettyClient
.
RunEventLoop
(
newSession
)
client
.
gettyClient
.
RunEventLoop
(
newSession
)
client
.
serverAddr
=
net
.
UDPAddr
{
IP
:
net
.
ParseIP
(
conf
.
ServerHost
),
Port
:
conf
.
ServerPort
}
}
}
func
uninitClient
()
{
func
uninitClient
()
{
...
@@ -146,7 +147,7 @@ func initSignal() {
...
@@ -146,7 +147,7 @@ func initSignal() {
}
}
}
}
func
echo
()
{
func
echo
(
serverAddr
*
net
.
UDPAddr
)
{
var
(
var
(
pkg
EchoPackage
pkg
EchoPackage
ctx
getty
.
UDPContext
ctx
getty
.
UDPContext
...
@@ -161,7 +162,7 @@ func echo() {
...
@@ -161,7 +162,7 @@ func echo() {
pkg
.
H
.
Len
=
(
uint16
)(
len
(
pkg
.
B
))
+
1
pkg
.
H
.
Len
=
(
uint16
)(
len
(
pkg
.
B
))
+
1
ctx
.
Pkg
=
&
pkg
ctx
.
Pkg
=
&
pkg
ctx
.
PeerAddr
=
&
(
conf
.
serverAddr
)
ctx
.
PeerAddr
=
serverAddr
if
session
:=
client
.
selectSession
();
session
!=
nil
{
if
session
:=
client
.
selectSession
();
session
!=
nil
{
err
:=
session
.
WritePkg
(
ctx
,
WritePkgTimeout
)
err
:=
session
.
WritePkg
(
ctx
,
WritePkgTimeout
)
...
@@ -174,6 +175,12 @@ func echo() {
...
@@ -174,6 +175,12 @@ func echo() {
}
}
func
test
()
{
func
test
()
{
var
(
cost
int64
serverAddr
net
.
UDPAddr
counter
gxtime
.
CountWatch
)
for
{
for
{
if
client
.
isAvailable
()
{
if
client
.
isAvailable
()
{
break
break
...
@@ -181,13 +188,11 @@ func test() {
...
@@ -181,13 +188,11 @@ func test() {
time
.
Sleep
(
1e6
)
time
.
Sleep
(
1e6
)
}
}
var
(
serverAddr
=
net
.
UDPAddr
{
IP
:
net
.
ParseIP
(
conf
.
ServerHost
),
Port
:
conf
.
ServerPort
}
cost
int64
counter
gxtime
.
CountWatch
)
counter
.
Start
()
counter
.
Start
()
for
i
:=
0
;
i
<
conf
.
EchoTimes
;
i
++
{
for
i
:=
0
;
i
<
conf
.
EchoTimes
;
i
++
{
echo
()
echo
(
&
serverAddr
)
}
}
cost
=
counter
.
Count
()
cost
=
counter
.
Count
()
log
.
Info
(
"after loop %d times, echo cost %d ms"
,
conf
.
EchoTimes
,
cost
/
1e6
)
log
.
Info
(
"after loop %d times, echo cost %d ms"
,
conf
.
EchoTimes
,
cost
/
1e6
)
...
...
echo/udp-echo/client/app/readwriter.go
View file @
e7956e69
...
@@ -21,8 +21,7 @@ import (
...
@@ -21,8 +21,7 @@ import (
log
"github.com/AlexStocks/log4go"
log
"github.com/AlexStocks/log4go"
)
)
type
EchoPackageHandler
struct
{
type
EchoPackageHandler
struct
{}
}
func
NewEchoPackageHandler
()
*
EchoPackageHandler
{
func
NewEchoPackageHandler
()
*
EchoPackageHandler
{
return
&
EchoPackageHandler
{}
return
&
EchoPackageHandler
{}
...
...
echo/udp-echo/client/profiles/test/log.xml
View file @
e7956e69
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) -->
<!-- level is (:?FINEST|FINE|DEBUG|TRACE|INFO|WARNING|ERROR) -->
<level>
DEBUG
</level>
<level>
DEBUG
</level>
</filter>
</filter>
<filter
enabled=
"
fals
e"
>
<filter
enabled=
"
tru
e"
>
<tag>
debug_file
</tag>
<tag>
debug_file
</tag>
<type>
file
</type>
<type>
file
</type>
<level>
DEBUG
</level>
<level>
DEBUG
</level>
...
...
echo/udp-echo/server/app/server.go
View file @
e7956e69
...
@@ -39,7 +39,7 @@ var (
...
@@ -39,7 +39,7 @@ var (
)
)
var
(
var
(
serverList
[]
*
getty
.
Server
serverList
[]
getty
.
Server
)
)
func
main
()
{
func
main
()
{
...
@@ -110,7 +110,7 @@ func initServer() {
...
@@ -110,7 +110,7 @@ func initServer() {
var
(
var
(
addr
string
addr
string
portList
[]
string
portList
[]
string
server
*
getty
.
Server
server
getty
.
Server
)
)
// if *host == "" {
// if *host == "" {
...
@@ -128,9 +128,11 @@ func initServer() {
...
@@ -128,9 +128,11 @@ func initServer() {
}
}
for
_
,
port
:=
range
portList
{
for
_
,
port
:=
range
portList
{
addr
=
gxnet
.
HostAddress2
(
conf
.
Host
,
port
)
addr
=
gxnet
.
HostAddress2
(
conf
.
Host
,
port
)
server
=
getty
.
NewUDPPServer
(
addr
)
server
=
getty
.
NewUDPPServer
(
getty
.
WithLocalAddress
(
addr
),
)
// run server
// run server
server
.
RunEvent
l
oop
(
newSession
)
server
.
RunEvent
L
oop
(
newSession
)
log
.
Debug
(
"server bind addr{%s} ok!"
,
addr
)
log
.
Debug
(
"server bind addr{%s} ok!"
,
addr
)
serverList
=
append
(
serverList
,
server
)
serverList
=
append
(
serverList
,
server
)
}
}
...
...
echo/udp-echo/server/app/version.go
View file @
e7956e69
...
@@ -10,5 +10,5 @@
...
@@ -10,5 +10,5 @@
package
main
package
main
var
(
var
(
Version
=
"0.8.
1
"
Version
=
"0.8.
2
"
)
)
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