Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
G
getty
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wei.xuan
getty
Commits
69758dca
Commit
69758dca
authored
Oct 16, 2018
by
AlexStocks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix: panic when got notify method
parent
4b3836b3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
15 deletions
+24
-15
listener.go
rpc/listener.go
+1
-1
readwriter.go
rpc/readwriter.go
+3
-1
rpc.go
rpc/rpc.go
+20
-13
No files found.
rpc/listener.go
View file @
69758dca
...
@@ -92,7 +92,7 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
...
@@ -92,7 +92,7 @@ func (h *RpcServerHandler) OnMessage(session getty.Session, pkg interface{}) {
}
}
if
req
.
header
.
CallType
==
CT_OneWay
{
if
req
.
header
.
CallType
==
CT_OneWay
{
function
:=
req
.
methodType
.
method
.
Func
function
:=
req
.
methodType
.
method
.
Func
function
.
Call
([]
reflect
.
Value
{
req
.
service
.
rcvr
,
req
.
argv
,
req
.
replyv
})
function
.
Call
([]
reflect
.
Value
{
req
.
service
.
rcvr
,
req
.
argv
})
return
return
}
}
if
req
.
header
.
CallType
==
CT_TwoWayNoReply
{
if
req
.
header
.
CallType
==
CT_TwoWayNoReply
{
...
...
rpc/readwriter.go
View file @
69758dca
...
@@ -76,7 +76,9 @@ func (p *RpcServerPackageHandler) Read(ss getty.Session, data []byte) (interface
...
@@ -76,7 +76,9 @@ func (p *RpcServerPackageHandler) Read(ss getty.Session, data []byte) (interface
req
.
argv
=
req
.
argv
.
Elem
()
req
.
argv
=
req
.
argv
.
Elem
()
}
}
// get reply
// get reply
req
.
replyv
=
reflect
.
New
(
req
.
methodType
.
ReplyType
.
Elem
())
if
req
.
methodType
.
ReplyType
!=
nil
{
req
.
replyv
=
reflect
.
New
(
req
.
methodType
.
ReplyType
.
Elem
())
}
return
req
,
length
,
nil
return
req
,
length
,
nil
}
}
...
...
rpc/rpc.go
View file @
69758dca
...
@@ -61,9 +61,12 @@ func suitableMethods(typ reflect.Type) map[string]*methodType {
...
@@ -61,9 +61,12 @@ func suitableMethods(typ reflect.Type) map[string]*methodType {
if
method
.
PkgPath
!=
""
{
if
method
.
PkgPath
!=
""
{
continue
continue
}
}
// Method needs three ins: receiver, *args, *reply.
// service Method needs three ins: receiver, *args, *reply.
if
mtype
.
NumIn
()
!=
3
{
// notify Method needs two ins: receiver, *args.
log
.
Warn
(
"method %s has wrong number of ins %d which should be 3"
,
mname
,
mtype
.
NumIn
())
mInNum
:=
mtype
.
NumIn
()
if
mInNum
!=
2
&&
mInNum
!=
3
{
log
.
Warn
(
"method %s has wrong number of ins %d which should be "
+
"2(notify method) or 3(serive method)"
,
mname
,
mtype
.
NumIn
())
continue
continue
}
}
// First arg need not be a pointer.
// First arg need not be a pointer.
...
@@ -72,16 +75,20 @@ func suitableMethods(typ reflect.Type) map[string]*methodType {
...
@@ -72,16 +75,20 @@ func suitableMethods(typ reflect.Type) map[string]*methodType {
log
.
Error
(
"method{%s} argument type not exported{%v}"
,
mname
,
argType
)
log
.
Error
(
"method{%s} argument type not exported{%v}"
,
mname
,
argType
)
continue
continue
}
}
// Second arg must be a pointer.
replyType
:=
mtype
.
In
(
2
)
var
replyType
reflect
.
Type
if
replyType
.
Kind
()
!=
reflect
.
Ptr
{
if
mInNum
==
3
{
log
.
Error
(
"method{%s} reply type not a pointer{%v}"
,
mname
,
replyType
)
// Second arg must be a pointer.
continue
replyType
=
mtype
.
In
(
2
)
}
if
replyType
.
Kind
()
!=
reflect
.
Ptr
{
// Reply type must be exported.
log
.
Error
(
"method{%s} reply type not a pointer{%v}"
,
mname
,
replyType
)
if
!
isExportedOrBuiltinType
(
replyType
)
{
continue
log
.
Error
(
"method{%s} reply type not exported{%v}"
,
mname
,
replyType
)
}
continue
// Reply type must be exported.
if
!
isExportedOrBuiltinType
(
replyType
)
{
log
.
Error
(
"method{%s} reply type not exported{%v}"
,
mname
,
replyType
)
continue
}
}
}
// Method needs one out.
// Method needs one out.
if
mtype
.
NumOut
()
!=
1
{
if
mtype
.
NumOut
()
!=
1
{
...
...
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