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
0df9283b
Commit
0df9283b
authored
Mar 31, 2021
by
georgehao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: format use gofumpt
parent
30e62643
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
41 additions
and
77 deletions
+41
-77
client.go
client.go
+2
-4
client_test.go
client_test.go
+10
-18
connection.go
connection.go
+5
-12
const.go
const.go
+4
-2
consts.go
demo/hello/consts.go
+1
-3
hello.go
demo/hello/hello.go
+1
-4
client.go
demo/hello/tcp/client/client.go
+1
-3
config.go
demo/hello/tcp/config.go
+1
-1
server.go
demo/hello/tcp/server/server.go
+1
-3
client.go
demo/hello/tls/client/client.go
+1
-3
config.go
demo/hello/tls/config.go
+1
-1
server.go
demo/hello/tls/server/server.go
+5
-5
options.go
options.go
+2
-2
server_test.go
server_test.go
+2
-6
session.go
session.go
+3
-9
tls.go
tls.go
+1
-1
No files found.
client.go
View file @
0df9283b
...
...
@@ -54,9 +54,7 @@ var (
// getty tcp client
/////////////////////////////////////////
var
(
clientID
=
EndPointID
(
0
)
)
var
clientID
=
EndPointID
(
0
)
type
client
struct
{
ClientOptions
...
...
@@ -225,7 +223,7 @@ func (c *client) dialUDP() Session {
<-
wheel
.
After
(
connectInterval
)
continue
}
//if err == nil {
//
if err == nil {
return
newUDPSession
(
conn
,
c
)
//}
}
...
...
client_test.go
View file @
0df9283b
...
...
@@ -120,11 +120,9 @@ func TestTCPClient(t *testing.T) {
)
assert
.
NotNil
(
t
,
clt
)
assert
.
True
(
t
,
clt
.
ID
()
>
0
)
//assert.Equal(t, clt.endPointType, TCP_CLIENT)
//
assert.Equal(t, clt.endPointType, TCP_CLIENT)
var
(
msgHandler
MessageHandler
)
var
msgHandler
MessageHandler
cb
:=
func
(
session
Session
)
error
{
return
newSessionCallback
(
session
,
&
msgHandler
)
}
...
...
@@ -193,11 +191,9 @@ func TestUDPClient(t *testing.T) {
)
assert
.
NotNil
(
t
,
clt
)
assert
.
True
(
t
,
clt
.
ID
()
>
0
)
//assert.Equal(t, clt.endPointType, UDP_CLIENT)
//
assert.Equal(t, clt.endPointType, UDP_CLIENT)
var
(
msgHandler
MessageHandler
)
var
msgHandler
MessageHandler
cb
:=
func
(
session
Session
)
error
{
return
newSessionCallback
(
session
,
&
msgHandler
)
}
...
...
@@ -256,7 +252,7 @@ func TestUDPClient(t *testing.T) {
assert
.
True
(
t
,
clt
.
IsClosed
())
msgHandler
.
array
[
0
]
.
Reset
()
assert
.
Nil
(
t
,
msgHandler
.
array
[
0
]
.
Conn
())
//ss.WritePkg([]byte("hello"), 0)
//
ss.WritePkg([]byte("hello"), 0)
}
func
TestNewWSClient
(
t
*
testing
.
T
)
{
...
...
@@ -283,9 +279,7 @@ func TestNewWSClient(t *testing.T) {
WithConnectionNumber
(
1
),
)
var
(
msgHandler
MessageHandler
)
var
msgHandler
MessageHandler
cb
:=
func
(
session
Session
)
error
{
return
newSessionCallback
(
session
,
&
msgHandler
)
}
...
...
@@ -437,9 +431,7 @@ func TestNewWSSClient(t *testing.T) {
WithRootCertificateFile
(
WssClientCRTFile
),
)
var
(
msgHandler
MessageHandler
)
var
msgHandler
MessageHandler
cb
:=
func
(
session
Session
)
error
{
return
newSessionCallback
(
session
,
&
msgHandler
)
}
...
...
@@ -451,7 +443,7 @@ func TestNewWSSClient(t *testing.T) {
client
.
Close
()
assert
.
True
(
t
,
client
.
IsClosed
())
assert
.
False
(
t
,
server
.
IsClosed
())
//time.Sleep(1000e9)
//server.Close()
//assert.True(t, server.IsClosed())
//
time.Sleep(1000e9)
//
server.Close()
//
assert.True(t, server.IsClosed())
}
connection.go
View file @
0df9283b
...
...
@@ -34,19 +34,13 @@ import (
perrors
"github.com/pkg/errors"
)
var
(
launchTime
=
time
.
Now
()
// ErrInvalidConnection = perrors.New("connection has been closed.")
)
var
launchTime
=
time
.
Now
()
// ErrInvalidConnection = perrors.New("connection has been closed.")
/////////////////////////////////////////
// getty connection
/////////////////////////////////////////
var
(
connID
uint32
)
var
connID
uint32
type
gettyConn
struct
{
id
uint32
...
...
@@ -260,7 +254,7 @@ func (t *gettyTCPConn) recv(p []byte) (int, error) {
// log.Debugf("now:%s, length:%d, err:%v", currentTime, length, err)
atomic
.
AddUint32
(
&
t
.
readBytes
,
uint32
(
length
))
return
length
,
perrors
.
WithStack
(
err
)
//return length, err
//
return length, err
}
// tcp connection write
...
...
@@ -330,7 +324,6 @@ func (t *gettyTCPConn) close(waitSec int) {
_
=
conn
.
Close
()
}
else
{
_
=
t
.
conn
.
(
*
tls
.
Conn
)
.
Close
()
}
t
.
conn
=
nil
}
...
...
@@ -422,7 +415,7 @@ func (u *gettyUDPConn) recv(p []byte) (int, *net.UDPAddr, error) {
atomic
.
AddUint32
(
&
u
.
readBytes
,
uint32
(
length
))
}
//return length, addr, err
//
return length, addr, err
return
length
,
addr
,
perrors
.
WithStack
(
err
)
}
...
...
@@ -568,7 +561,7 @@ func (w *gettyWSConn) recv() ([]byte, error) {
}
return
b
,
perrors
.
WithStack
(
e
)
//return b, e
//
return b, e
}
func
(
w
*
gettyWSConn
)
updateWriteDeadline
()
error
{
...
...
const.go
View file @
0df9283b
...
...
@@ -21,8 +21,10 @@ import (
"strconv"
)
type
EndPointID
=
int32
type
EndPointType
int32
type
(
EndPointID
=
int32
EndPointType
int32
)
const
(
UDP_ENDPOINT
EndPointType
=
0
...
...
demo/hello/consts.go
View file @
0df9283b
...
...
@@ -26,6 +26,4 @@ const (
WritePkgTimeout
=
1e8
)
var
(
log
=
getty
.
GetLogger
()
)
var
log
=
getty
.
GetLogger
()
demo/hello/hello.go
View file @
0df9283b
...
...
@@ -21,9 +21,7 @@ import (
"github.com/apache/dubbo-getty"
)
var
(
Sessions
[]
getty
.
Session
)
var
Sessions
[]
getty
.
Session
func
ClientRequest
()
{
for
_
,
session
:=
range
Sessions
{
...
...
@@ -40,5 +38,4 @@ func ClientRequest() {
log
.
Infof
(
"after loop %d times"
,
echoTimes
)
}()
}
}
demo/hello/tcp/client/client.go
View file @
0df9283b
...
...
@@ -41,9 +41,7 @@ var (
pprofPort
=
flag
.
Int
(
"pprof_port"
,
65431
,
"pprof http port"
)
)
var
(
taskPool
gxsync
.
GenericTaskPool
)
var
taskPool
gxsync
.
GenericTaskPool
func
main
()
{
flag
.
Parse
()
...
...
demo/hello/tcp/config.go
View file @
0df9283b
...
...
@@ -38,7 +38,7 @@ var (
)
func
InitialSession
(
session
getty
.
Session
)
(
err
error
)
{
//session.SetCompressType(getty.CompressZip)
//
session.SetCompressType(getty.CompressZip)
tcpConn
,
ok
:=
session
.
Conn
()
.
(
*
net
.
TCPConn
)
if
!
ok
{
...
...
demo/hello/tcp/server/server.go
View file @
0df9283b
...
...
@@ -37,9 +37,7 @@ var (
pprofPort
=
flag
.
Int
(
"pprof_port"
,
65432
,
"pprof http port"
)
)
var
(
taskPool
gxsync
.
GenericTaskPool
)
var
taskPool
gxsync
.
GenericTaskPool
func
main
()
{
flag
.
Parse
()
...
...
demo/hello/tls/client/client.go
View file @
0df9283b
...
...
@@ -42,9 +42,7 @@ var (
pprofPort
=
flag
.
Int
(
"pprof_port"
,
65431
,
"pprof http port"
)
)
var
(
taskPool
gxsync
.
GenericTaskPool
)
var
taskPool
gxsync
.
GenericTaskPool
func
main
()
{
flag
.
Parse
()
...
...
demo/hello/tls/config.go
View file @
0df9283b
...
...
@@ -38,7 +38,7 @@ var (
// InitialSession init session
func
InitialSession
(
session
getty
.
Session
)
(
err
error
)
{
//session.SetCompressType(getty.CompressZip)
//
session.SetCompressType(getty.CompressZip)
_
,
ok
:=
session
.
Conn
()
.
(
*
tls
.
Conn
)
if
ok
{
session
.
SetName
(
"hello"
)
...
...
demo/hello/tls/server/server.go
View file @
0df9283b
...
...
@@ -19,8 +19,9 @@ package main
import
(
"flag"
tls
"github.com/apache/dubbo-getty/demo/hello/tls"
"path/filepath"
tls
"github.com/apache/dubbo-getty/demo/hello/tls"
)
import
(
...
...
@@ -39,9 +40,7 @@ var (
Sessions
[]
getty
.
Session
)
var
(
taskPool
gxsync
.
GenericTaskPool
)
var
taskPool
gxsync
.
GenericTaskPool
func
main
()
{
flag
.
Parse
()
...
...
@@ -62,7 +61,8 @@ func main() {
if
*
taskPoolMode
{
taskPool
=
gxsync
.
NewTaskPoolSimple
(
*
taskPoolSize
)
}
options
:=
[]
getty
.
ServerOption
{
getty
.
WithLocalAddress
(
":8090"
),
options
:=
[]
getty
.
ServerOption
{
getty
.
WithLocalAddress
(
":8090"
),
getty
.
WithServerSslEnabled
(
true
),
getty
.
WithServerTlsConfigBuilder
(
c
),
getty
.
WithServerTaskPool
(
taskPool
),
...
...
options.go
View file @
0df9283b
...
...
@@ -27,7 +27,7 @@ type ServerOption func(*ServerOptions)
type
ServerOptions
struct
{
addr
string
//tls
//
tls
sslEnabled
bool
tlsConfigBuilder
TlsConfigBuilder
// websocket
...
...
@@ -106,7 +106,7 @@ type ClientOptions struct {
number
int
reconnectInterval
int
// reConnect Interval
//tls
//
tls
sslEnabled
bool
tlsConfigBuilder
TlsConfigBuilder
...
...
server_test.go
View file @
0df9283b
...
...
@@ -59,9 +59,7 @@ func testTCPServer(t *testing.T, address string) {
assert
.
True
(
t
,
clt
.
ID
()
>
0
)
assert
.
Equal
(
t
,
clt
.
endPointType
,
TCP_CLIENT
)
var
(
msgHandler
MessageHandler
)
var
msgHandler
MessageHandler
cb
:=
func
(
session
Session
)
error
{
return
newSessionCallback
(
session
,
&
msgHandler
)
}
...
...
@@ -129,9 +127,7 @@ func testTCPTlsServer(t *testing.T, address string) {
assert
.
True
(
t
,
clt
.
ID
()
>
0
)
assert
.
Equal
(
t
,
clt
.
endPointType
,
TCP_CLIENT
)
var
(
msgHandler
MessageHandler
)
var
msgHandler
MessageHandler
cb
:=
func
(
session
Session
)
error
{
return
newSessionCallback
(
session
,
&
msgHandler
)
}
...
...
session.go
View file @
0df9283b
...
...
@@ -58,9 +58,7 @@ const (
// session
/////////////////////////////////////////
var
(
wheel
*
gxtime
.
Wheel
)
var
wheel
*
gxtime
.
Wheel
func
init
()
{
span
:=
100e6
// 100ms
...
...
@@ -544,9 +542,7 @@ func (s *session) addTask(pkg interface{}) {
}
func
(
s
*
session
)
handlePackage
()
{
var
(
err
error
)
var
err
error
defer
func
()
{
if
r
:=
recover
();
r
!=
nil
{
...
...
@@ -826,9 +822,7 @@ func (s *session) stop() {
}
func
(
s
*
session
)
gc
()
{
var
(
conn
Connection
)
var
conn
Connection
s
.
lock
.
Lock
()
if
s
.
attrs
!=
nil
{
...
...
tls.go
View file @
0df9283b
...
...
@@ -23,6 +23,7 @@ import (
"fmt"
"io/ioutil"
)
import
(
perrors
"github.com/pkg/errors"
)
...
...
@@ -88,7 +89,6 @@ type ClientTlsConfigBuilder struct {
// BuildTlsConfig impl TlsConfigBuilder method
func
(
c
*
ClientTlsConfigBuilder
)
BuildTlsConfig
()
(
*
tls
.
Config
,
error
)
{
cert
,
err
:=
tls
.
LoadX509KeyPair
(
c
.
ClientTrustCertCollectionPath
,
c
.
ClientPrivateKeyPath
)
if
err
!=
nil
{
log
.
Error
(
fmt
.
Sprintf
(
"Unable to load X509 Key Pair %v"
,
err
))
...
...
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