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
dms3
go-unixfs
Commits
e45a6ced
Commit
e45a6ced
authored
10 years ago
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
can just use ctx.Done
parent
8aed79cd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
15 deletions
+12
-15
net/conn/conn.go
net/conn/conn.go
+12
-15
No files found.
net/conn/conn.go
View file @
e45a6ced
...
...
@@ -45,7 +45,6 @@ type singleConn struct {
// context + cancel
ctx
context
.
Context
cancel
context
.
CancelFunc
closed
chan
struct
{}
secure
*
spipe
.
SecurePipe
insecure
*
msgioPipe
...
...
@@ -67,7 +66,6 @@ func newSingleConn(ctx context.Context, local, remote *peer.Peer,
maconn
:
maconn
,
ctx
:
ctx
,
cancel
:
cancel
,
closed
:
make
(
chan
struct
{}),
insecure
:
newMsgioPipe
(
10
),
msgpipe
:
msg
.
NewPipe
(
10
),
}
...
...
@@ -77,7 +75,7 @@ func newSingleConn(ctx context.Context, local, remote *peer.Peer,
// setup the various io goroutines
go
conn
.
insecure
.
outgoing
.
WriteTo
(
maconn
)
go
conn
.
insecure
.
incoming
.
ReadFrom
(
maconn
,
MaxMessageSize
)
go
conn
.
waitToClose
(
ctx
)
go
conn
.
waitToClose
()
// perform secure handshake before returning this connection.
if
err
:=
conn
.
secureHandshake
(
peers
);
err
!=
nil
{
...
...
@@ -101,12 +99,14 @@ func (c *singleConn) secureHandshake(peers peer.Peerstore) error {
}
// spipe performs the secure handshake, which takes multiple RTT
var
err
error
c
.
secure
,
err
=
spipe
.
NewSecurePipe
(
c
.
ctx
,
10
,
c
.
local
,
peers
,
insecure
)
sp
,
err
:=
spipe
.
NewSecurePipe
(
c
.
ctx
,
10
,
c
.
local
,
peers
,
insecure
)
if
err
!=
nil
{
return
err
}
// assign it into the conn object
c
.
secure
=
sp
if
c
.
remote
==
nil
{
c
.
remote
=
c
.
secure
.
RemotePeer
()
...
...
@@ -157,9 +157,9 @@ func (c *singleConn) wrapInMsgs() {
}
// waitToClose waits on the given context's Done before closing Conn.
func
(
c
*
singleConn
)
waitToClose
(
ctx
context
.
Context
)
{
func
(
c
*
singleConn
)
waitToClose
()
{
select
{
case
<-
ctx
.
Done
()
:
case
<-
c
.
ctx
.
Done
()
:
}
// close underlying connection
...
...
@@ -167,15 +167,16 @@ func (c *singleConn) waitToClose(ctx context.Context) {
// closing channels
c
.
insecure
.
outgoing
.
Close
()
c
.
secure
.
Close
()
if
c
.
secure
!=
nil
{
// may never have gotten here.
c
.
secure
.
Close
()
}
close
(
c
.
msgpipe
.
Incoming
)
close
(
c
.
closed
)
}
// isClosed returns whether this Conn is open or closed.
func
(
c
*
singleConn
)
isClosed
()
bool
{
select
{
case
<-
c
.
c
losed
:
case
<-
c
.
c
tx
.
Done
()
:
return
true
default
:
return
false
...
...
@@ -280,7 +281,6 @@ type listener struct {
// ctx + cancel func
ctx
context
.
Context
cancel
context
.
CancelFunc
closed
chan
struct
{}
}
// waitToClose is needed to hand
...
...
@@ -290,12 +290,11 @@ func (l *listener) waitToClose() {
}
l
.
Listener
.
Close
()
close
(
l
.
closed
)
}
func
(
l
*
listener
)
isClosed
()
bool
{
select
{
case
<-
l
.
c
losed
:
case
<-
l
.
c
tx
.
Done
()
:
return
true
default
:
return
false
...
...
@@ -368,7 +367,6 @@ func (l *listener) Close() error {
}
l
.
cancel
()
<-
l
.
closed
return
nil
}
...
...
@@ -388,7 +386,6 @@ func Listen(ctx context.Context, addr ma.Multiaddr, local *peer.Peer, peers peer
l
:=
&
listener
{
ctx
:
ctx
,
cancel
:
cancel
,
closed
:
make
(
chan
struct
{}),
Listener
:
ml
,
maddr
:
addr
,
peers
:
peers
,
...
...
This diff is collapsed.
Click to expand it.
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