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
b89c0bb5
Commit
b89c0bb5
authored
Jul 20, 2020
by
aliiohs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tls support
parent
4965ba8b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
4 deletions
+14
-4
client.go
client.go
+7
-1
server.go
server.go
+7
-3
No files found.
client.go
View file @
b89c0bb5
...
...
@@ -69,6 +69,7 @@ type client struct {
newSession
NewSessionCallback
ssMap
map
[
Session
]
struct
{}
sslConfig
*
tls
.
Config
sync
.
Once
done
chan
struct
{}
...
...
@@ -152,7 +153,12 @@ func (c *client) dialTCP() Session {
if
c
.
IsClosed
()
{
return
nil
}
conn
,
err
=
net
.
DialTimeout
(
"tcp"
,
c
.
addr
,
connectTimeout
)
if
c
.
sslConfig
!=
nil
{
d
:=
&
net
.
Dialer
{
Timeout
:
connectTimeout
}
conn
,
err
=
tls
.
DialWithDialer
(
d
,
"tcp"
,
c
.
addr
,
c
.
sslConfig
)
}
else
{
conn
,
err
=
net
.
DialTimeout
(
"tcp"
,
c
.
addr
,
connectTimeout
)
}
if
err
==
nil
&&
gxnet
.
IsSameAddr
(
conn
.
RemoteAddr
(),
conn
.
LocalAddr
())
{
conn
.
Close
()
err
=
errSelfConnect
...
...
server.go
View file @
b89c0bb5
...
...
@@ -56,7 +56,7 @@ type server struct {
lock
sync
.
Mutex
// for server
endPointType
EndPointType
server
*
http
.
Server
// for ws or wss server
sslConfig
*
tls
.
Config
sync
.
Once
done
chan
struct
{}
wg
sync
.
WaitGroup
...
...
@@ -80,7 +80,7 @@ func newServer(t EndPointType, opts ...ServerOption) *server {
return
s
}
// NewTCServer builds a tcp server.
// NewTC
P
Server builds a tcp server.
func
NewTCPServer
(
opts
...
ServerOption
)
Server
{
return
newServer
(
TCP_SERVER
,
opts
...
)
}
...
...
@@ -175,7 +175,11 @@ func (s *server) listenTCP() error {
return
perrors
.
Wrapf
(
err
,
"gxnet.ListenOnTCPRandomPort(addr:%s)"
,
s
.
addr
)
}
}
else
{
streamListener
,
err
=
net
.
Listen
(
"tcp"
,
s
.
addr
)
if
s
.
sslConfig
!=
nil
{
streamListener
,
err
=
tls
.
Listen
(
"tcp"
,
s
.
addr
,
s
.
sslConfig
)
}
else
{
streamListener
,
err
=
net
.
Listen
(
"tcp"
,
s
.
addr
)
}
if
err
!=
nil
{
return
perrors
.
Wrapf
(
err
,
"net.Listen(tcp, addr:%s)"
,
s
.
addr
)
}
...
...
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