Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
2c229bac
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2c229bac
编写于
4月 19, 2015
作者:
B
Bas van Kervel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replaced channel pointer field with non pointer channel
上级
ead3dd97
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
14 addition
and
11 deletion
+14
-11
rpc/http.go
rpc/http.go
+1
-1
rpc/types.go
rpc/types.go
+13
-10
未找到文件。
rpc/http.go
浏览文件 @
2c229bac
...
...
@@ -45,7 +45,7 @@ func Start(pipe *xeth.XEth, config RpcConfig) error {
c
:=
cors
.
New
(
opts
)
handler
=
NewStoppableHandler
(
c
.
Handler
(
JSONRPC
(
pipe
)),
l
.
stop
)
}
else
{
handler
=
JSONRPC
(
pipe
)
handler
=
NewStoppableHandler
(
JSONRPC
(
pipe
),
l
.
stop
)
}
go
http
.
Serve
(
l
,
handler
)
...
...
rpc/types.go
浏览文件 @
2c229bac
...
...
@@ -275,20 +275,21 @@ func (self ListenerStoppedError) Error() string {
var
listenerStoppedError
=
ListenerStoppedError
{
"Listener stopped"
}
// When https://github.com/golang/go/issues/4674 is fixed this could be replaced
type
StoppableTCPListener
struct
{
*
net
.
TCPListener
stop
*
chan
struct
{}
// closed when the listener must stop
stop
chan
struct
{}
// closed when the listener must stop
}
// Wraps the default handler and checks if the RPC service was stopped. In that case it returns an
// error indicating that the service was stopped. This will only happen for connections which are
// kept open (HTTP keep-alive) when the RPC service was shutdown.
func
NewStoppableHandler
(
h
http
.
Handler
,
stop
*
chan
struct
{})
http
.
Handler
{
func
NewStoppableHandler
(
h
http
.
Handler
,
stop
chan
struct
{})
http
.
Handler
{
return
http
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
select
{
case
<-
*
stop
:
case
<-
stop
:
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
jsonerr
:=
&
RpcErrorObject
{
-
32603
,
"RPC service stop
t
"
}
jsonerr
:=
&
RpcErrorObject
{
-
32603
,
"RPC service stop
ped
"
}
send
(
w
,
&
RpcErrorResponse
{
Jsonrpc
:
jsonrpcver
,
Id
:
nil
,
Error
:
jsonerr
})
default
:
h
.
ServeHTTP
(
w
,
r
)
...
...
@@ -298,7 +299,7 @@ func NewStoppableHandler(h http.Handler, stop *chan struct{}) http.Handler {
// Stop the listener and all accepted and still active connections.
func
(
self
*
StoppableTCPListener
)
Stop
()
{
close
(
*
self
.
stop
)
close
(
self
.
stop
)
}
func
NewStoppableTCPListener
(
addr
string
)
(
*
StoppableTCPListener
,
error
)
{
...
...
@@ -309,7 +310,7 @@ func NewStoppableTCPListener(addr string) (*StoppableTCPListener, error) {
if
tcpl
,
ok
:=
wl
.
(
*
net
.
TCPListener
);
ok
{
stop
:=
make
(
chan
struct
{})
l
:=
&
StoppableTCPListener
{
tcpl
,
&
stop
}
l
:=
&
StoppableTCPListener
{
tcpl
,
stop
}
return
l
,
nil
}
...
...
@@ -322,8 +323,10 @@ func (self *StoppableTCPListener) Accept() (net.Conn, error) {
c
,
err
:=
self
.
TCPListener
.
AcceptTCP
()
select
{
case
<-*
self
.
stop
:
c
.
Close
()
case
<-
self
.
stop
:
if
c
!=
nil
{
// accept timeout
c
.
Close
()
}
self
.
TCPListener
.
Close
()
return
nil
,
listenerStoppedError
default
:
...
...
@@ -341,12 +344,12 @@ func (self *StoppableTCPListener) Accept() (net.Conn, error) {
type
ClosableConnection
struct
{
*
net
.
TCPConn
closed
*
chan
struct
{}
closed
chan
struct
{}
}
func
(
self
*
ClosableConnection
)
Read
(
b
[]
byte
)
(
n
int
,
err
error
)
{
select
{
case
<-
*
self
.
closed
:
case
<-
self
.
closed
:
self
.
TCPConn
.
Close
()
return
0
,
io
.
EOF
default
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录