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
58fdcad9
Commit
58fdcad9
authored
Oct 19, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
multiconn: map + close on children close
parent
fc5b0c29
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
2 deletions
+39
-2
net/conn/multiconn.go
net/conn/multiconn.go
+8
-0
net/conn/multiconn_test.go
net/conn/multiconn_test.go
+29
-0
net/conn/secure_conn_test.go
net/conn/secure_conn_test.go
+2
-2
No files found.
net/conn/multiconn.go
View file @
58fdcad9
...
...
@@ -10,6 +10,9 @@ import (
u
"github.com/jbenet/go-ipfs/util"
)
// MultiConnMap is for shorthand
type
MultiConnMap
map
[
u
.
Key
]
*
MultiConn
// Duplex is a simple duplex channel
type
Duplex
struct
{
In
chan
[]
byte
...
...
@@ -160,10 +163,15 @@ func (c *MultiConn) fanInSingle(child Conn) {
// in case it still is in the map, remove it.
c
.
Lock
()
delete
(
c
.
conns
,
child
.
ID
())
connLen
:=
len
(
c
.
conns
)
c
.
Unlock
()
c
.
Children
()
.
Done
()
child
.
Children
()
.
Done
()
if
connLen
==
0
{
c
.
Close
()
// close self if all underlying children are gone?
}
}()
for
{
...
...
net/conn/multiconn_test.go
View file @
58fdcad9
...
...
@@ -293,3 +293,32 @@ func TestMulticonnSendUnderlying(t *testing.T) {
msgsFrom1
.
CheckDone
(
t
)
msgsFrom2
.
CheckDone
(
t
)
}
func
TestMulticonnClose
(
t
*
testing
.
T
)
{
// t.Skip("fooo")
log
.
Info
(
"TestMulticonnSendUnderlying"
)
ctx
:=
context
.
Background
()
c1
,
c2
:=
setupMultiConns
(
t
,
ctx
)
for
_
,
c
:=
range
c1
.
conns
{
c
.
Close
()
}
for
_
,
c
:=
range
c2
.
conns
{
c
.
Close
()
}
timeout
:=
time
.
After
(
100
*
time
.
Millisecond
)
select
{
case
<-
c1
.
Closed
()
:
case
<-
timeout
:
t
.
Fatal
(
"timeout"
)
}
select
{
case
<-
c2
.
Closed
()
:
case
<-
timeout
:
t
.
Fatal
(
"timeout"
)
}
}
net/conn/secure_conn_test.go
View file @
58fdcad9
...
...
@@ -50,7 +50,7 @@ func TestSecureClose(t *testing.T) {
select
{
case
<-
c1
.
Closed
()
:
default
:
t
.
Fatal
(
"not done after c
ancel
"
)
t
.
Fatal
(
"not done after c
lose
"
)
}
c2
.
Close
()
...
...
@@ -58,7 +58,7 @@ func TestSecureClose(t *testing.T) {
select
{
case
<-
c2
.
Closed
()
:
default
:
t
.
Fatal
(
"not done after c
ancel
"
)
t
.
Fatal
(
"not done after c
lose
"
)
}
cancel
()
// close the listener :P
...
...
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