Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
c2a228f6
提交
c2a228f6
authored
10月 19, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use ContextCloser better (listener fix)
上级
4783332b
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
24 行增加
和
14 行删除
+24
-14
conn.go
net/conn/conn.go
+16
-13
conn_test.go
net/conn/conn_test.go
+3
-0
dial_test.go
net/conn/dial_test.go
+1
-0
handshake.go
net/conn/handshake.go
+1
-1
secure_conn_test.go
net/conn/secure_conn_test.go
+3
-0
没有找到文件。
net/conn/conn.go
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论