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