Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
1018bf6a
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 搜索 >>
提交
1018bf6a
编写于
3月 24, 2017
作者:
P
Péter Szilágyi
提交者:
Felix Lange
3月 24, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rpc: honour pending requests before tearing conn down (#3814)
上级
37e25258
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
28 addition
and
14 deletion
+28
-14
rpc/server.go
rpc/server.go
+28
-14
未找到文件。
rpc/server.go
浏览文件 @
1018bf6a
...
...
@@ -21,6 +21,7 @@ import (
"fmt"
"reflect"
"runtime"
"sync"
"sync/atomic"
"github.com/ethereum/go-ethereum/log"
...
...
@@ -143,6 +144,8 @@ func hasOption(option CodecOption, options []CodecOption) bool {
// requests until the codec returns an error when reading a request (in most cases
// an EOF). It executes requests in parallel when singleShot is false.
func
(
s
*
Server
)
serveRequest
(
codec
ServerCodec
,
singleShot
bool
,
options
CodecOption
)
error
{
var
pend
sync
.
WaitGroup
defer
func
()
{
if
err
:=
recover
();
err
!=
nil
{
const
size
=
64
<<
10
...
...
@@ -150,7 +153,6 @@ func (s *Server) serveRequest(codec ServerCodec, singleShot bool, options CodecO
buf
=
buf
[
:
runtime
.
Stack
(
buf
,
false
)]
log
.
Error
(
fmt
.
Sprint
(
string
(
buf
)))
}
s
.
codecsMu
.
Lock
()
s
.
codecs
.
Remove
(
codec
)
s
.
codecsMu
.
Unlock
()
...
...
@@ -179,8 +181,13 @@ func (s *Server) serveRequest(codec ServerCodec, singleShot bool, options CodecO
for
atomic
.
LoadInt32
(
&
s
.
run
)
==
1
{
reqs
,
batch
,
err
:=
s
.
readRequest
(
codec
)
if
err
!=
nil
{
log
.
Debug
(
fmt
.
Sprintf
(
"read error %v
\n
"
,
err
))
codec
.
Write
(
codec
.
CreateErrorResponse
(
nil
,
err
))
// If a parsing error occurred, send an error
if
err
.
Error
()
!=
"EOF"
{
log
.
Debug
(
fmt
.
Sprintf
(
"read error %v
\n
"
,
err
))
codec
.
Write
(
codec
.
CreateErrorResponse
(
nil
,
err
))
}
// Error or end of stream, wait for requests and tear down
pend
.
Wait
()
return
nil
}
...
...
@@ -199,20 +206,27 @@ func (s *Server) serveRequest(codec ServerCodec, singleShot bool, options CodecO
}
return
nil
}
if
singleShot
&&
batch
{
s
.
execBatch
(
ctx
,
codec
,
reqs
)
return
nil
}
else
if
singleShot
&&
!
batch
{
s
.
exec
(
ctx
,
codec
,
reqs
[
0
])
// If a single shot request is executing, run and return immediately
if
singleShot
{
if
batch
{
s
.
execBatch
(
ctx
,
codec
,
reqs
)
}
else
{
s
.
exec
(
ctx
,
codec
,
reqs
[
0
])
}
return
nil
}
else
if
!
singleShot
&&
batch
{
go
s
.
execBatch
(
ctx
,
codec
,
reqs
)
}
else
{
go
s
.
exec
(
ctx
,
codec
,
reqs
[
0
])
}
}
// For multi-shot connections, start a goroutine to serve and loop back
pend
.
Add
(
1
)
go
func
(
reqs
[]
*
serverRequest
,
batch
bool
)
{
defer
pend
.
Done
()
if
batch
{
s
.
execBatch
(
ctx
,
codec
,
reqs
)
}
else
{
s
.
exec
(
ctx
,
codec
,
reqs
[
0
])
}
}(
reqs
,
batch
)
}
return
nil
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录