Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
2cbdd1da
Commit
2cbdd1da
authored
Feb 19, 2021
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
7461a018
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
go/internal/xio/xio.go
go/internal/xio/xio.go
+10
-7
go/neo/neonet/newlink.go
go/neo/neonet/newlink.go
+6
-0
No files found.
go/internal/xio/xio.go
View file @
2cbdd1da
...
...
@@ -83,16 +83,21 @@ func LClose(ctx context.Context, c io.Closer) {
// WithCloseOnErrCancel closes c on ctx cancel while f is run, or if f returns with an error.
//
// It is usually handy to propagate cancellation to interrupt IO.
//
// Returned error is what f returned, or ctx.Err() if f retrned nil despite that
// ctx was canceled and c closed.
func
WithCloseOnErrCancel
(
ctx
context
.
Context
,
c
io
.
Closer
,
f
func
()
error
)
(
err
error
)
{
closed
:=
false
fdone
:=
make
(
chan
error
)
defer
func
()
{
errf
,
ok
:=
<-
fdone
// wait for f to complete
XXX return f's error
errf
,
ok
:=
<-
fdone
// wait for f to complete
if
ok
{
// it was ctx cancel and `return ctx.Err()` vvv
// -> change return to be what f returned
// -> change return to be what f returned if !nil
if
errf
!=
nil
{
err
=
errf
}
}
if
err
!=
nil
{
if
!
closed
{
...
...
@@ -124,17 +129,15 @@ func WithCloseOnErrCancel(ctx context.Context, c io.Closer, f func() error) (err
//
// It is usually handy to propagate cancellation to interrupt IO.
func
WithCloseOnRetCancel
(
ctx
context
.
Context
,
c
io
.
Closer
,
f
func
()
error
)
error
{
var
errf
error
err
:=
WithCloseOnErrCancel
(
ctx
,
c
,
func
()
error
{
errf
=
f
()
e
:=
errf
e
:=
f
()
if
e
==
nil
{
e
=
retOK
// force c close
}
return
e
})
if
err
==
retOK
{
err
=
errf
err
=
nil
}
return
err
}
...
...
go/neo/neonet/newlink.go
View file @
2cbdd1da
...
...
@@ -135,6 +135,9 @@ func _handshakeClient(ctx context.Context, conn net.Conn, version uint32, encPre
return
nil
})
if
err
!=
nil
{
if
ctx
.
Err
()
!=
nil
{
err
=
ctx
.
Err
()
// error was due to ctx cancel
}
return
0
,
nil
,
err
}
...
...
@@ -179,6 +182,9 @@ func _handshakeServer(ctx context.Context, conn net.Conn, version uint32) (enc p
return
nil
})
if
err
!=
nil
{
if
ctx
.
Err
()
!=
nil
{
err
=
ctx
.
Err
()
// error was due to ctx cancel
}
return
0
,
nil
,
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