Let RecvProto return nil for client stream rpc
This commit is contained in:
@ -286,7 +286,7 @@ void PrintClientMethodImpl(google::protobuf::io::Printer* printer,
|
||||
"\t\treturn nil, err\n"
|
||||
"\t}\n"
|
||||
"\tm := new($Response$)\n"
|
||||
"\tif err := x.ClientStream.RecvProto(m); err != io.EOF {\n"
|
||||
"\tif err := x.ClientStream.RecvProto(m); err != nil {\n"
|
||||
"\t\treturn nil, err\n"
|
||||
"\t}\n"
|
||||
"\treturn m, nil\n"
|
||||
@ -618,10 +618,6 @@ string GetServices(const google::protobuf::FileDescriptor* file,
|
||||
vars["PackageName"] = BadToUnderscore(package_name);
|
||||
printer.Print(vars, "package $PackageName$\n\n");
|
||||
printer.Print("import (\n");
|
||||
if (HasClientOnlyStreaming(file)) {
|
||||
printer.Print(
|
||||
"\t\"io\"\n");
|
||||
}
|
||||
printer.Print(
|
||||
"\t\"google.golang.org/grpc\"\n"
|
||||
"\tcontext \"golang.org/x/net/context\"\n"
|
||||
|
@ -58,15 +58,11 @@ import proto "github.com/golang/protobuf/proto"
|
||||
import math "math"
|
||||
|
||||
import (
|
||||
errors "errors"
|
||||
context "golang.org/x/net/context"
|
||||
grpc "google.golang.org/grpc"
|
||||
io "io"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = errors.New
|
||||
var _ = io.EOF
|
||||
var _ context.Context
|
||||
var _ grpc.ClientConn
|
||||
|
||||
@ -489,7 +485,7 @@ func (x *testServiceStreamingInputCallClient) CloseAndRecv() (*StreamingInputCal
|
||||
return nil, err
|
||||
}
|
||||
m := new(StreamingInputCallResponse)
|
||||
if err := x.ClientStream.RecvProto(m); err != io.EOF {
|
||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
|
16
stream.go
16
stream.go
@ -34,7 +34,7 @@
|
||||
package grpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"io"
|
||||
"net"
|
||||
|
||||
@ -170,10 +170,18 @@ func (cs *clientStream) RecvProto(m proto.Message) (err error) {
|
||||
return
|
||||
}
|
||||
// Special handling for client streaming rpc.
|
||||
if err = recvProto(cs.p, m); err != io.EOF {
|
||||
cs.t.CloseStream(cs.s, err)
|
||||
return fmt.Errorf("grpc: client streaming protocol violation: %v, want <EOF>", err)
|
||||
err = recvProto(cs.p, m)
|
||||
cs.t.CloseStream(cs.s, err)
|
||||
if err == nil {
|
||||
return toRPCErr(errors.New("grpc: client streaming protocol violation: get <nil>, want <EOF>"))
|
||||
}
|
||||
if err == io.EOF {
|
||||
if cs.s.StatusCode() == codes.OK {
|
||||
return nil
|
||||
}
|
||||
return Errorf(cs.s.StatusCode(), cs.s.StatusDesc())
|
||||
}
|
||||
return toRPCErr(err)
|
||||
}
|
||||
if _, ok := err.(transport.ConnectionError); !ok {
|
||||
cs.t.CloseStream(cs.s, err)
|
||||
|
@ -58,15 +58,11 @@ import proto "github.com/golang/protobuf/proto"
|
||||
import math "math"
|
||||
|
||||
import (
|
||||
errors "errors"
|
||||
context "golang.org/x/net/context"
|
||||
grpc "google.golang.org/grpc"
|
||||
io "io"
|
||||
)
|
||||
|
||||
// Reference imports to suppress errors if they are not otherwise used.
|
||||
var _ = errors.New
|
||||
var _ = io.EOF
|
||||
var _ context.Context
|
||||
var _ grpc.ClientConn
|
||||
|
||||
@ -489,7 +485,7 @@ func (x *testServiceStreamingInputCallClient) CloseAndRecv() (*StreamingInputCal
|
||||
return nil, err
|
||||
}
|
||||
m := new(StreamingInputCallResponse)
|
||||
if err := x.ClientStream.RecvProto(m); err != io.EOF {
|
||||
if err := x.ClientStream.RecvProto(m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
|
Reference in New Issue
Block a user