diff --git a/compiler/go_generator.cc b/compiler/go_generator.cc index 2330f4c2..a23acbff 100644 --- a/compiler/go_generator.cc +++ b/compiler/go_generator.cc @@ -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" diff --git a/interop/grpc_testing/test.pb.go b/interop/grpc_testing/test.pb.go index 0159b8db..192cb454 100755 --- a/interop/grpc_testing/test.pb.go +++ b/interop/grpc_testing/test.pb.go @@ -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 diff --git a/stream.go b/stream.go index ba0ff259..5f4227c7 100644 --- a/stream.go +++ b/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 ", 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 , want ")) } + 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) diff --git a/test/grpc_testing/test.pb.go b/test/grpc_testing/test.pb.go index 0159b8db..192cb454 100755 --- a/test/grpc_testing/test.pb.go +++ b/test/grpc_testing/test.pb.go @@ -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