Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-tls
Commits
f692110d
Commit
f692110d
authored
Nov 29, 2018
by
Marten Seemann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
simplify returning of context cancellation errors
parent
fa2f7eea
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
transport.go
transport.go
+8
-6
No files found.
transport.go
View file @
f692110d
...
...
@@ -59,7 +59,6 @@ func (t *Transport) handshake(
insecure
net
.
Conn
,
tlsConn
*
tls
.
Conn
,
)
(
cs
.
Conn
,
error
)
{
errChan
:=
make
(
chan
error
,
2
)
// There's no way to pass a context to tls.Conn.Handshake().
// See https://github.com/golang/go/issues/18482.
// Close the connection instead.
...
...
@@ -69,21 +68,24 @@ func (t *Transport) handshake(
select
{
case
<-
done
:
case
<-
ctx
.
Done
()
:
errChan
<-
ctx
.
Err
()
insecure
.
Close
()
}
}()
if
err
:=
tlsConn
.
Handshake
();
err
!=
nil
{
// if the context was canceled, return the context error
errChan
<-
err
return
nil
,
<-
errChan
if
ctxErr
:=
ctx
.
Err
();
ctxErr
!=
nil
{
return
nil
,
ctxErr
}
return
nil
,
err
}
conn
,
err
:=
t
.
setupConn
(
tlsConn
)
if
err
!=
nil
{
// if the context was canceled, return the context error
errChan
<-
err
return
nil
,
<-
errChan
if
ctxErr
:=
ctx
.
Err
();
ctxErr
!=
nil
{
return
nil
,
ctxErr
}
return
nil
,
err
}
return
conn
,
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