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
262c2a33
Commit
262c2a33
authored
Nov 12, 2021
by
wei.xuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove timer
parent
622d6d17
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
14 deletions
+37
-14
client.go
client.go
+7
-9
go.mod
go.mod
+1
-1
go.sum
go.sum
+2
-2
logger.go
logger.go
+26
-0
server.go
server.go
+1
-2
No files found.
client.go
View file @
262c2a33
...
...
@@ -31,8 +31,6 @@ import (
"github.com/adamweixuan/gostnops/bytes"
"github.com/adamweixuan/gostnops/net"
gxsync
"github.com/adamweixuan/gostnops/sync"
gxtime
"github.com/adamweixuan/gostnops/time"
"github.com/gorilla/websocket"
perrors
"github.com/pkg/errors"
...
...
@@ -149,7 +147,7 @@ func (c *client) dialTCP() Session {
}
log
.
Warnf
(
"net.DialTimeout(addr:%s, timeout:%v) = error:%+v"
,
c
.
addr
,
connectTimeout
,
err
)
<-
gx
time
.
After
(
time
.
Millisecond
*
time
.
Duration
(
c
.
reconnectInterval
))
<-
time
.
After
(
time
.
Millisecond
*
time
.
Duration
(
c
.
reconnectInterval
))
}
}
...
...
@@ -180,7 +178,7 @@ func (c *client) dialUDP() Session {
}
if
err
!=
nil
{
log
.
Warnf
(
"net.DialTimeout(addr:%s, timeout:%v) = error:%+v"
,
c
.
addr
,
perrors
.
WithStack
(
err
))
<-
gx
time
.
After
(
connectInterval
)
<-
time
.
After
(
connectInterval
)
continue
}
...
...
@@ -189,7 +187,7 @@ func (c *client) dialUDP() Session {
if
length
,
err
=
conn
.
Write
(
connectPingPackage
[
:
]);
err
!=
nil
{
conn
.
Close
()
log
.
Warnf
(
"conn.Write(%s) = {length:%d, err:%+v}"
,
string
(
connectPingPackage
),
length
,
perrors
.
WithStack
(
err
))
<-
gx
time
.
After
(
connectInterval
)
<-
time
.
After
(
connectInterval
)
continue
}
conn
.
SetReadDeadline
(
time
.
Now
()
.
Add
(
1e9
))
...
...
@@ -200,7 +198,7 @@ func (c *client) dialUDP() Session {
if
err
!=
nil
{
log
.
Infof
(
"conn{%#v}.Read() = {length:%d, err:%+v}"
,
conn
,
length
,
perrors
.
WithStack
(
err
))
conn
.
Close
()
<-
gx
time
.
After
(
connectInterval
)
<-
time
.
After
(
connectInterval
)
continue
}
return
newUDPSession
(
conn
,
c
)
...
...
@@ -236,7 +234,7 @@ func (c *client) dialWS() Session {
}
log
.
Infof
(
"websocket.dialer.Dial(addr:%s) = error:%+v"
,
c
.
addr
,
perrors
.
WithStack
(
err
))
<-
gx
time
.
After
(
connectInterval
)
<-
time
.
After
(
connectInterval
)
}
}
...
...
@@ -314,7 +312,7 @@ func (c *client) dialWSS() Session {
}
log
.
Infof
(
"websocket.dialer.Dial(addr:%s) = error:%+v"
,
c
.
addr
,
perrors
.
WithStack
(
err
))
<-
gx
time
.
After
(
connectInterval
)
<-
time
.
After
(
connectInterval
)
}
}
...
...
@@ -418,7 +416,7 @@ func (c *client) reConnect() {
}
rinterval
:=
time
.
Duration
(
int64
(
times
)
*
int64
(
interval
))
log
.
Infof
(
"==============client reConnect %+v==========="
,
rinterval
)
<-
gx
time
.
After
(
rinterval
)
<-
time
.
After
(
rinterval
)
}
}
...
...
go.mod
View file @
262c2a33
...
...
@@ -3,7 +3,7 @@ module github.com/adamweixuan/getty
go 1.17
require (
github.com/adamweixuan/gostnops v
1.11.20-0.20211029124314-3f0589fceea6
github.com/adamweixuan/gostnops v
0.0.1
github.com/gorilla/websocket v1.4.2
github.com/pkg/errors v0.9.1
go.uber.org/atomic v1.9.0
...
...
go.sum
View file @
262c2a33
github.com/adamweixuan/gostnops v
1.11.20-0.20211029124314-3f0589fceea6 h1:UGMsACjkGfNRKCz5U8ijtkpKL8o/25rGHxTV1adWjak
=
github.com/adamweixuan/gostnops v
1.11.20-0.20211029124314-3f0589fceea6/go.mod h1:zZYjPhU2+ujyEOWWE0l1pEdf5H4CyfiMG//rSpNjwcQ
=
github.com/adamweixuan/gostnops v
0.0.1 h1:oBfrRgBoRyaGjBTfq0DGH07jARS4OqN7jbSv1Mn05Fg
=
github.com/adamweixuan/gostnops v
0.0.1/go.mod h1:lTe81VUWCpja0NOVqXyi2cH28m2hYezzhTt3MudpDbU
=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
...
...
logger.go
View file @
262c2a33
...
...
@@ -125,3 +125,29 @@ func Online(logfile string) error {
log
=
zapLogger
.
Sugar
()
return
nil
}
func
NewLogger
(
logName
string
,
level
LoggerLevel
)
Logger
{
config
:=
zap
.
NewDevelopmentConfig
()
config
.
EncoderConfig
=
zapcore
.
EncoderConfig
{
TimeKey
:
"time"
,
LevelKey
:
"level"
,
NameKey
:
"logger"
,
CallerKey
:
"caller"
,
MessageKey
:
"message"
,
StacktraceKey
:
"stacktrace"
,
EncodeLevel
:
zapcore
.
CapitalColorLevelEncoder
,
EncodeTime
:
zapcore
.
ISO8601TimeEncoder
,
EncodeDuration
:
zapcore
.
SecondsDurationEncoder
,
EncodeCaller
:
zapcore
.
ShortCallerEncoder
,
}
config
.
Level
=
zap
.
NewAtomicLevelAt
(
zapcore
.
Level
(
level
))
config
.
OutputPaths
=
[]
string
{
logName
}
config
.
Development
=
false
config
.
DisableCaller
=
true
config
.
DisableStacktrace
=
true
zapLogger
,
err
:=
config
.
Build
()
if
err
!=
nil
{
panic
(
err
)
}
return
zapLogger
.
Sugar
()
}
server.go
View file @
262c2a33
...
...
@@ -31,7 +31,6 @@ import (
gxnet
"github.com/adamweixuan/gostnops/net"
gxsync
"github.com/adamweixuan/gostnops/sync"
gxtime
"github.com/adamweixuan/gostnops/time"
"github.com/gorilla/websocket"
perrors
"github.com/pkg/errors"
uatomic
"go.uber.org/atomic"
...
...
@@ -287,7 +286,7 @@ func (s *server) runTCPEventLoop(newSession NewSessionCallback) {
return
}
if
delay
!=
0
{
<-
gx
time
.
After
(
delay
)
<-
time
.
After
(
delay
)
}
client
,
err
=
s
.
accept
(
newSession
)
if
err
!=
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