• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #region Copyright notice and license
2 
3 // Copyright 2015 gRPC authors.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 
17 #endregion
18 
19 using System;
20 using System.Runtime.InteropServices;
21 using Grpc.Core.Utils;
22 
23 namespace Grpc.Core.Internal
24 {
25     /// <summary>
26     /// grpc_call_error from grpc/grpc.h
27     /// </summary>
28     internal enum CallError
29     {
30         /* everything went ok */
31         OK = 0,
32         /* something failed, we don't know what */
33         Error,
34         /* this method is not available on the server */
35         NotOnServer,
36         /* this method is not available on the client */
37         NotOnClient,
38         /* this method must be called before server_accept */
39         AlreadyAccepted,
40         /* this method must be called before invoke */
41         AlreadyInvoked,
42         /* this method must be called after invoke */
43         NotInvoked,
44         /* this call is already finished
45      (writes_done or write_status has already been called) */
46         AlreadyFinished,
47         /* there is already an outstanding read/write operation on the call */
48         TooManyOperations,
49         /* the flags value was illegal for this call */
50         InvalidFlags
51     }
52 
53     internal static class CallErrorExtensions
54     {
55         /// <summary>
56         /// Checks the call API invocation's result is OK.
57         /// </summary>
CheckOk(this CallError callError)58         public static void CheckOk(this CallError callError)
59         {
60             if (callError != CallError.OK)
61             {
62                 throw new InvalidOperationException("Call error: " + callError);
63             }
64         }
65     }
66 }
67