Skip to content

Commit 43716c5

Browse files
committed
Fixed readArguments
1 parent 594df38 commit 43716c5

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

Diff for: examples/http_hello_server/http_hello_server.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ import (
66
"github.com/hprose/hprose-golang/rpc"
77
)
88

9-
func hello(name string) string {
10-
return "Hello " + name + "!"
9+
func hello(name string, context *rpc.HTTPContext) string {
10+
return "Hello !" + context.Request.RemoteAddr
1111
}
1212

1313
func main() {
1414
service := rpc.NewHTTPService()
15+
service.Debug = true
1516
service.AddFunction("hello", hello)
1617
http.ListenAndServe(":8080", service)
1718
}

Diff for: rpc/base_service.go

+16-8
Original file line numberDiff line numberDiff line change
@@ -357,14 +357,18 @@ func readArguments(
357357
fixArguments func(args []reflect.Value, context ServiceContext),
358358
reader *io.Reader,
359359
method *Method,
360+
hasArgs bool,
360361
context ServiceContext) (args []reflect.Value) {
361-
if method != nil {
362-
reader.JSONCompatible = method.JSONCompatible
363-
}
364-
if method == nil || context.IsMissingMethod() {
365-
return reader.ReadSliceWithoutTag()
362+
count := 0
363+
if hasArgs {
364+
if method != nil {
365+
reader.JSONCompatible = method.JSONCompatible
366+
}
367+
if method == nil || context.IsMissingMethod() {
368+
return reader.ReadSliceWithoutTag()
369+
}
370+
count = reader.ReadCount()
366371
}
367-
count := reader.ReadCount()
368372
ft := method.Function.Type()
369373
n := ft.NumIn()
370374
if ft.IsVariadic() {
@@ -386,7 +390,9 @@ func readArguments(
386390
}
387391
}
388392
}
389-
reader.ReadSlice(args[:count])
393+
if hasArgs {
394+
reader.ReadSlice(args[:count])
395+
}
390396
if !ft.IsVariadic() && n > count {
391397
fixArguments(args, context)
392398
}
@@ -439,12 +445,14 @@ func (service *BaseService) doSingleInvoke(
439445
var args []reflect.Value
440446
if tag == io.TagList {
441447
reader.Reset()
442-
args = readArguments(service.FixArguments, reader, method, context)
448+
args = readArguments(service.FixArguments, reader, method, true, context)
443449
tag = reader.CheckTags([]byte{io.TagTrue, io.TagEnd, io.TagCall})
444450
if tag == io.TagTrue {
445451
context.setByRef(true)
446452
tag = reader.CheckTags([]byte{io.TagEnd, io.TagCall})
447453
}
454+
} else {
455+
args = readArguments(service.FixArguments, reader, method, false, context)
448456
}
449457
context.setMethod(method)
450458
result, err := service.beforeInvoke(name, args, context)

0 commit comments

Comments
 (0)