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-dms3
Commits
113c44fe
Commit
113c44fe
authored
Oct 19, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
listen: conn fate sharing
parent
a4e49234
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
3 deletions
+11
-3
net/conn/listen.go
net/conn/listen.go
+11
-3
No files found.
net/conn/listen.go
View file @
113c44fe
...
...
@@ -27,6 +27,9 @@ type listener struct {
// Peerstore is the set of peers we know about locally
peers
peer
.
Peerstore
// Context for children Conn
ctx
context
.
Context
// embedded ContextCloser
ContextCloser
}
...
...
@@ -54,13 +57,13 @@ func (l *listener) listen() {
handle
:=
func
(
maconn
manet
.
Conn
)
{
defer
func
()
{
<-
sem
}()
// release
c
,
err
:=
newSingleConn
(
l
.
Context
()
,
l
.
local
,
nil
,
maconn
)
c
,
err
:=
newSingleConn
(
l
.
ctx
,
l
.
local
,
nil
,
maconn
)
if
err
!=
nil
{
log
.
Error
(
"Error accepting connection: %v"
,
err
)
return
}
sc
,
err
:=
newSecureConn
(
l
.
Context
()
,
c
,
l
.
peers
)
sc
,
err
:=
newSecureConn
(
l
.
ctx
,
c
,
l
.
peers
)
if
err
!=
nil
{
log
.
Error
(
"Error securing connection: %v"
,
err
)
return
...
...
@@ -130,9 +133,14 @@ func Listen(ctx context.Context, addr ma.Multiaddr, local *peer.Peer, peers peer
local
:
local
,
conns
:
make
(
chan
Conn
,
chansize
),
chansize
:
chansize
,
ctx
:
ctx
,
}
l
.
ContextCloser
=
NewContextCloser
(
ctx
,
l
.
close
)
// need a separate context to use for the context closer.
// This is because the parent context will be given to all connections too,
// and if we close the listener, the connections shouldn't share the fate.
ctx2
,
_
:=
context
.
WithCancel
(
ctx
)
l
.
ContextCloser
=
NewContextCloser
(
ctx2
,
l
.
close
)
go
l
.
listen
()
...
...
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