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
c2a228f6
Commit
c2a228f6
authored
Oct 19, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use ContextCloser better (listener fix)
parent
4783332b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
14 deletions
+24
-14
net/conn/conn.go
net/conn/conn.go
+16
-13
net/conn/conn_test.go
net/conn/conn_test.go
+3
-0
net/conn/dial_test.go
net/conn/dial_test.go
+1
-0
net/conn/handshake.go
net/conn/handshake.go
+1
-1
net/conn/secure_conn_test.go
net/conn/secure_conn_test.go
+3
-0
No files found.
net/conn/conn.go
View file @
c2a228f6
...
...
@@ -65,8 +65,16 @@ func newSingleConn(ctx context.Context, local, remote *peer.Peer,
log
.
Info
(
"newSingleConn: %v to %v"
,
local
,
remote
)
// setup the various io goroutines
go
conn
.
msgio
.
outgoing
.
WriteTo
(
maconn
)
go
conn
.
msgio
.
incoming
.
ReadFrom
(
maconn
,
MaxMessageSize
)
go
func
()
{
conn
.
Children
()
.
Add
(
1
)
conn
.
msgio
.
outgoing
.
WriteTo
(
maconn
)
conn
.
Children
()
.
Done
()
}()
go
func
()
{
conn
.
Children
()
.
Add
(
1
)
conn
.
msgio
.
incoming
.
ReadFrom
(
maconn
,
MaxMessageSize
)
conn
.
Children
()
.
Done
()
}()
// version handshake
ctxT
,
_
:=
context
.
WithTimeout
(
ctx
,
HandshakeTimeout
)
...
...
@@ -216,16 +224,9 @@ func (l *listener) close() error {
return
l
.
Listener
.
Close
()
}
func
(
l
*
listener
)
isClosed
()
bool
{
select
{
case
<-
l
.
Closed
()
:
return
true
default
:
return
false
}
}
func
(
l
*
listener
)
listen
()
{
l
.
Children
()
.
Add
(
1
)
defer
l
.
Children
()
.
Done
()
// handle at most chansize concurrent handshakes
sem
:=
make
(
chan
struct
{},
l
.
chansize
)
...
...
@@ -254,9 +255,11 @@ func (l *listener) listen() {
maconn
,
err
:=
l
.
Listener
.
Accept
()
if
err
!=
nil
{
// if cancel is nil we're closed.
if
l
.
isClosed
()
{
// if closing, we should exit.
select
{
case
<-
l
.
Closing
()
:
return
// done.
default
:
}
log
.
Error
(
"Failed to accept connection: %v"
,
err
)
...
...
net/conn/conn_test.go
View file @
c2a228f6
...
...
@@ -13,6 +13,7 @@ import (
)
func
TestClose
(
t
*
testing
.
T
)
{
// t.Skip("Skipping in favor of another test")
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
c1
,
c2
:=
setupConn
(
t
,
ctx
,
"/ip4/127.0.0.1/tcp/1234"
,
"/ip4/127.0.0.1/tcp/2345"
)
...
...
@@ -45,6 +46,7 @@ func TestClose(t *testing.T) {
}
func
TestCancel
(
t
*
testing
.
T
)
{
// t.Skip("Skipping in favor of another test")
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
c1
,
c2
:=
setupConn
(
t
,
ctx
,
"/ip4/127.0.0.1/tcp/1234"
,
"/ip4/127.0.0.1/tcp/2345"
)
...
...
@@ -78,6 +80,7 @@ func TestCancel(t *testing.T) {
}
func
TestCloseLeak
(
t
*
testing
.
T
)
{
// t.Skip("Skipping in favor of another test")
var
wg
sync
.
WaitGroup
...
...
net/conn/dial_test.go
View file @
c2a228f6
...
...
@@ -93,6 +93,7 @@ func setupConn(t *testing.T, ctx context.Context, a1, a2 string) (a, b Conn) {
}
func
TestDialer
(
t
*
testing
.
T
)
{
// t.Skip("Skipping in favor of another test")
p1
,
err
:=
setupPeer
(
"/ip4/127.0.0.1/tcp/1234"
)
if
err
!=
nil
{
...
...
net/conn/handshake.go
View file @
c2a228f6
...
...
@@ -31,7 +31,7 @@ func VersionHandshake(ctx context.Context, c Conn) error {
case
<-
ctx
.
Done
()
:
return
ctx
.
Err
()
case
<-
c
.
Clos
ed
()
:
case
<-
c
.
Clos
ing
()
:
return
errors
.
New
(
"remote closed connection during version exchange"
)
case
data
,
ok
:=
<-
c
.
In
()
:
...
...
net/conn/secure_conn_test.go
View file @
c2a228f6
...
...
@@ -29,6 +29,7 @@ func setupSecureConn(t *testing.T, c Conn) Conn {
}
func
TestSecureClose
(
t
*
testing
.
T
)
{
// t.Skip("Skipping in favor of another test")
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
c1
,
c2
:=
setupConn
(
t
,
ctx
,
"/ip4/127.0.0.1/tcp/1234"
,
"/ip4/127.0.0.1/tcp/2345"
)
...
...
@@ -64,6 +65,7 @@ func TestSecureClose(t *testing.T) {
}
func
TestSecureCancel
(
t
*
testing
.
T
)
{
// t.Skip("Skipping in favor of another test")
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
c1
,
c2
:=
setupConn
(
t
,
ctx
,
"/ip4/127.0.0.1/tcp/1234"
,
"/ip4/127.0.0.1/tcp/2345"
)
...
...
@@ -100,6 +102,7 @@ func TestSecureCancel(t *testing.T) {
}
func
TestSecureCloseLeak
(
t
*
testing
.
T
)
{
// t.Skip("Skipping in favor of another test")
var
wg
sync
.
WaitGroup
...
...
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