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
b1e566ce
Unverified
Commit
b1e566ce
authored
Jul 06, 2021
by
Xin.Zh
Committed by
GitHub
Jul 06, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into improve/delte-handleLoop
parents
82b07bee
03651cac
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
24 deletions
+22
-24
connection.go
connection.go
+22
-24
No files found.
connection.go
View file @
b1e566ce
...
@@ -25,9 +25,7 @@ import (
...
@@ -25,9 +25,7 @@ import (
"net"
"net"
"sync"
"sync"
"time"
"time"
)
import
(
"github.com/golang/snappy"
"github.com/golang/snappy"
"github.com/gorilla/websocket"
"github.com/gorilla/websocket"
perrors
"github.com/pkg/errors"
perrors
"github.com/pkg/errors"
...
@@ -36,9 +34,9 @@ import (
...
@@ -36,9 +34,9 @@ import (
var
launchTime
=
time
.
Now
()
var
launchTime
=
time
.
Now
()
/////////////////////////////////////////
//
///////////////////////////////////////
// getty connection
// getty connection
/////////////////////////////////////////
//
///////////////////////////////////////
var
connID
uatomic
.
Uint32
var
connID
uatomic
.
Uint32
...
@@ -54,8 +52,8 @@ type gettyConn struct {
...
@@ -54,8 +52,8 @@ type gettyConn struct {
active
uatomic
.
Int64
// last active, in milliseconds
active
uatomic
.
Int64
// last active, in milliseconds
rTimeout
time
.
Duration
// network current limiting
rTimeout
time
.
Duration
// network current limiting
wTimeout
time
.
Duration
wTimeout
time
.
Duration
rLastDeadline
time
.
Time
// lastest network read time
rLastDeadline
int64
// lastest network read time
wLastDeadline
time
.
Time
// lastest network write time
wLastDeadline
int64
// lastest network write time
local
string
// local address
local
string
// local address
peer
string
// peer address
peer
string
// peer address
ss
Session
ss
Session
...
@@ -241,12 +239,12 @@ func (t *gettyTCPConn) recv(p []byte) (int, error) {
...
@@ -241,12 +239,12 @@ func (t *gettyTCPConn) recv(p []byte) (int, error) {
// of the last read deadline exceeded.
// of the last read deadline exceeded.
// See https://github.com/golang/go/issues/15133 for details.
// See https://github.com/golang/go/issues/15133 for details.
currentTime
=
time
.
Now
()
currentTime
=
time
.
Now
()
if
currentTime
.
Sub
(
t
.
rLastDeadline
)
>
(
t
.
rTimeout
>>
2
)
{
if
currentTime
.
Unix
()
-
t
.
rLastDeadline
>
int64
(
t
.
rTimeout
>>
2
)
{
if
err
=
t
.
conn
.
SetReadDeadline
(
currentTime
.
Add
(
t
.
rTimeout
));
err
!=
nil
{
if
err
=
t
.
conn
.
SetReadDeadline
(
currentTime
.
Add
(
t
.
rTimeout
));
err
!=
nil
{
// just a timeout error
// just a timeout error
return
0
,
perrors
.
WithStack
(
err
)
return
0
,
perrors
.
WithStack
(
err
)
}
}
t
.
rLastDeadline
=
currentTime
t
.
rLastDeadline
=
currentTime
.
Unix
()
}
}
}
}
...
@@ -271,11 +269,11 @@ func (t *gettyTCPConn) send(pkg interface{}) (int, error) {
...
@@ -271,11 +269,11 @@ func (t *gettyTCPConn) send(pkg interface{}) (int, error) {
// of the last write deadline exceeded.
// of the last write deadline exceeded.
// See https://github.com/golang/go/issues/15133 for details.
// See https://github.com/golang/go/issues/15133 for details.
currentTime
=
time
.
Now
()
currentTime
=
time
.
Now
()
if
currentTime
.
Sub
(
t
.
wLastDeadline
)
>
(
t
.
wTimeout
>>
2
)
{
if
currentTime
.
Unix
()
-
t
.
wLastDeadline
>
int64
(
t
.
wTimeout
>>
2
)
{
if
err
=
t
.
conn
.
SetWriteDeadline
(
currentTime
.
Add
(
t
.
wTimeout
));
err
!=
nil
{
if
err
=
t
.
conn
.
SetWriteDeadline
(
currentTime
.
Add
(
t
.
wTimeout
));
err
!=
nil
{
return
0
,
perrors
.
WithStack
(
err
)
return
0
,
perrors
.
WithStack
(
err
)
}
}
t
.
wLastDeadline
=
currentTime
t
.
wLastDeadline
=
currentTime
.
Unix
()
}
}
}
}
...
@@ -327,9 +325,9 @@ func (t *gettyTCPConn) close(waitSec int) {
...
@@ -327,9 +325,9 @@ func (t *gettyTCPConn) close(waitSec int) {
}
}
}
}
/////////////////////////////////////////
//
///////////////////////////////////////
// getty udp connection
// getty udp connection
/////////////////////////////////////////
//
///////////////////////////////////////
type
UDPContext
struct
{
type
UDPContext
struct
{
Pkg
interface
{}
Pkg
interface
{}
...
@@ -391,12 +389,12 @@ func (u *gettyUDPConn) recv(p []byte) (int, *net.UDPAddr, error) {
...
@@ -391,12 +389,12 @@ func (u *gettyUDPConn) recv(p []byte) (int, *net.UDPAddr, error) {
// Optimization: update read deadline only if more than 25%
// Optimization: update read deadline only if more than 25%
// of the last read deadline exceeded.
// of the last read deadline exceeded.
// See https://github.com/golang/go/issues/15133 for details.
// See https://github.com/golang/go/issues/15133 for details.
currentTime
:
=
time
.
Now
()
currentTime
=
time
.
Now
()
if
currentTime
.
Sub
(
u
.
rLastDeadline
)
>
(
u
.
rTimeout
>>
2
)
{
if
currentTime
.
Unix
()
-
u
.
rLastDeadline
>
int64
(
u
.
rTimeout
>>
2
)
{
if
err
:
=
u
.
conn
.
SetReadDeadline
(
currentTime
.
Add
(
u
.
rTimeout
));
err
!=
nil
{
if
err
=
u
.
conn
.
SetReadDeadline
(
currentTime
.
Add
(
u
.
rTimeout
));
err
!=
nil
{
return
0
,
nil
,
perrors
.
WithStack
(
err
)
return
0
,
nil
,
perrors
.
WithStack
(
err
)
}
}
u
.
rLastDeadline
=
currentTime
u
.
rLastDeadline
=
currentTime
.
Unix
()
}
}
}
}
...
@@ -439,11 +437,11 @@ func (u *gettyUDPConn) send(udpCtx interface{}) (int, error) {
...
@@ -439,11 +437,11 @@ func (u *gettyUDPConn) send(udpCtx interface{}) (int, error) {
// of the last write deadline exceeded.
// of the last write deadline exceeded.
// See https://github.com/golang/go/issues/15133 for details.
// See https://github.com/golang/go/issues/15133 for details.
currentTime
=
time
.
Now
()
currentTime
=
time
.
Now
()
if
currentTime
.
Sub
(
u
.
wLastDeadline
)
>
(
u
.
wTimeout
>>
2
)
{
if
currentTime
.
Unix
()
-
u
.
wLastDeadline
>
int64
(
u
.
wTimeout
>>
2
)
{
if
err
=
u
.
conn
.
SetWriteDeadline
(
currentTime
.
Add
(
u
.
wTimeout
));
err
!=
nil
{
if
err
=
u
.
conn
.
SetWriteDeadline
(
currentTime
.
Add
(
u
.
wTimeout
));
err
!=
nil
{
return
0
,
perrors
.
WithStack
(
err
)
return
0
,
perrors
.
WithStack
(
err
)
}
}
u
.
wLastDeadline
=
currentTime
u
.
wLastDeadline
=
currentTime
.
Unix
()
}
}
}
}
...
@@ -464,9 +462,9 @@ func (u *gettyUDPConn) close(_ int) {
...
@@ -464,9 +462,9 @@ func (u *gettyUDPConn) close(_ int) {
}
}
}
}
/////////////////////////////////////////
//
///////////////////////////////////////
// getty websocket connection
// getty websocket connection
/////////////////////////////////////////
//
///////////////////////////////////////
type
gettyWSConn
struct
{
type
gettyWSConn
struct
{
gettyConn
gettyConn
...
@@ -564,11 +562,11 @@ func (w *gettyWSConn) updateWriteDeadline() error {
...
@@ -564,11 +562,11 @@ func (w *gettyWSConn) updateWriteDeadline() error {
// of the last write deadline exceeded.
// of the last write deadline exceeded.
// See https://github.com/golang/go/issues/15133 for details.
// See https://github.com/golang/go/issues/15133 for details.
currentTime
=
time
.
Now
()
currentTime
=
time
.
Now
()
if
currentTime
.
Sub
(
w
.
wLastDeadline
)
>
(
w
.
wTimeout
>>
2
)
{
if
currentTime
.
Unix
()
-
w
.
wLastDeadline
>
int64
(
w
.
wTimeout
>>
2
)
{
if
err
=
w
.
conn
.
SetWriteDeadline
(
currentTime
.
Add
(
w
.
wTimeout
));
err
!=
nil
{
if
err
=
w
.
conn
.
SetWriteDeadline
(
currentTime
.
Add
(
w
.
wTimeout
));
err
!=
nil
{
return
perrors
.
WithStack
(
err
)
return
perrors
.
WithStack
(
err
)
}
}
w
.
wLastDeadline
=
currentTime
w
.
wLastDeadline
=
currentTime
.
Unix
()
}
}
}
}
...
...
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