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