diff options
author | Jan Tattermusch <jtattermusch@google.com> | 2016-12-02 16:52:26 +0100 |
---|---|---|
committer | Jan Tattermusch <jtattermusch@google.com> | 2016-12-02 17:09:46 +0100 |
commit | 058f555b7e1e1b4235ea66b53bacca7cf32ad0e8 (patch) | |
tree | 769f48c7a29f44f3d1f057e01eb1257287f6c413 /src | |
parent | 43416dac68fec7269a3f9bb570543657944a2372 (diff) |
make CallFlags internal, expose WaitForReady
Diffstat (limited to 'src')
-rw-r--r-- | src/csharp/Grpc.Core.Tests/CallOptionsTest.cs | 11 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/CallOptions.cs | 34 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Grpc.Core.csproj | 2 | ||||
-rw-r--r-- | src/csharp/Grpc.Core/Internal/CallFlags.cs (renamed from src/csharp/Grpc.Core/CallFlags.cs) | 6 |
4 files changed, 43 insertions, 10 deletions
diff --git a/src/csharp/Grpc.Core.Tests/CallOptionsTest.cs b/src/csharp/Grpc.Core.Tests/CallOptionsTest.cs index c4bcf66e38..3c3b9f7745 100644 --- a/src/csharp/Grpc.Core.Tests/CallOptionsTest.cs +++ b/src/csharp/Grpc.Core.Tests/CallOptionsTest.cs @@ -98,5 +98,16 @@ namespace Grpc.Core.Tests Assert.AreEqual(token, new CallOptions(propagationToken: propagationToken2).Normalize().CancellationToken); Assert.Throws(typeof(ArgumentException), () => new CallOptions(cancellationToken: token, propagationToken: propagationToken2).Normalize()); } + + [Test] + public void WaitForReady() + { + var callOptions = new CallOptions(); + Assert.IsFalse(callOptions.IsWaitForReady); + + Assert.AreEqual(CallFlags.WaitForReady, callOptions.WithWaitForReady().Flags); + Assert.IsTrue(callOptions.WithWaitForReady().IsWaitForReady); + Assert.IsFalse(callOptions.WithWaitForReady(true).WithWaitForReady(false).IsWaitForReady); + } } } diff --git a/src/csharp/Grpc.Core/CallOptions.cs b/src/csharp/Grpc.Core/CallOptions.cs index 850eafc059..ce43dae171 100644 --- a/src/csharp/Grpc.Core/CallOptions.cs +++ b/src/csharp/Grpc.Core/CallOptions.cs @@ -61,10 +61,8 @@ namespace Grpc.Core /// <param name="writeOptions">Write options that will be used for this call.</param> /// <param name="propagationToken">Context propagation token obtained from <see cref="ServerCallContext"/>.</param> /// <param name="credentials">Credentials to use for this call.</param> - /// <param name="flags">Flags to use for this call.</param> public CallOptions(Metadata headers = null, DateTime? deadline = null, CancellationToken cancellationToken = default(CancellationToken), - WriteOptions writeOptions = null, ContextPropagationToken propagationToken = null, CallCredentials credentials = null, - CallFlags flags = default(CallFlags)) + WriteOptions writeOptions = null, ContextPropagationToken propagationToken = null, CallCredentials credentials = null) { this.headers = headers; this.deadline = deadline; @@ -72,7 +70,7 @@ namespace Grpc.Core this.writeOptions = writeOptions; this.propagationToken = propagationToken; this.credentials = credentials; - this.flags = flags; + this.flags = default(CallFlags); } /// <summary> @@ -130,9 +128,19 @@ namespace Grpc.Core } /// <summary> + /// If <c>true</c> and and channel is in <c>ChannelState.TransientFailure</c>, the call will attempt waiting for the channel to recover + /// instead of failing immediately (which is the default "FailFast" semantics). + /// Note: experimental API that can change or be removed without any prior notice. + /// </summary> + public bool IsWaitForReady + { + get { return (this.flags & CallFlags.WaitForReady) == CallFlags.WaitForReady; } + } + + /// <summary> /// Flags to use for this call. /// </summary> - public CallFlags Flags + internal CallFlags Flags { get { return this.flags; } } @@ -210,11 +218,25 @@ namespace Grpc.Core } /// <summary> + /// Returns new instance of <see cref="CallOptions"/> with "WaitForReady" semantics enabled/disabled. + /// <see cref="IsWaitForReady"/>. + /// Note: experimental API that can change or be removed without any prior notice. + /// </summary> + public CallOptions WithWaitForReady(bool waitForReady = true) + { + if (waitForReady) + { + return WithFlags(this.flags | CallFlags.WaitForReady); + } + return WithFlags(this.flags & ~CallFlags.WaitForReady); + } + + /// <summary> /// Returns new instance of <see cref="CallOptions"/> with /// <c>Flags</c> set to the value provided. Values of all other fields are preserved. /// </summary> /// <param name="flags">The call flags.</param> - public CallOptions WithFlags(CallFlags flags) + internal CallOptions WithFlags(CallFlags flags) { var newOptions = this; newOptions.flags = flags; diff --git a/src/csharp/Grpc.Core/Grpc.Core.csproj b/src/csharp/Grpc.Core/Grpc.Core.csproj index 9a3d084ec0..5bfb978ca6 100644 --- a/src/csharp/Grpc.Core/Grpc.Core.csproj +++ b/src/csharp/Grpc.Core/Grpc.Core.csproj @@ -48,7 +48,6 @@ <Compile Include="AsyncServerStreamingCall.cs" /> <Compile Include="AsyncAuthInterceptor.cs" /> <Compile Include="CallCredentials.cs" /> - <Compile Include="CallFlags.cs" /> <Compile Include="IClientStreamWriter.cs" /> <Compile Include="Internal\NativeMethods.cs" /> <Compile Include="Internal\PlatformApis.cs" /> @@ -141,6 +140,7 @@ <Compile Include="Logging\LogLevelFilterLogger.cs" /> <Compile Include="Internal\RequestCallContextSafeHandle.cs" /> <Compile Include="Utils\TaskUtils.cs" /> + <Compile Include="Internal\CallFlags.cs" /> </ItemGroup> <ItemGroup> <None Include="Grpc.Core.project.json" /> diff --git a/src/csharp/Grpc.Core/CallFlags.cs b/src/csharp/Grpc.Core/Internal/CallFlags.cs index e61fc69597..454fa9b1f4 100644 --- a/src/csharp/Grpc.Core/CallFlags.cs +++ b/src/csharp/Grpc.Core/Internal/CallFlags.cs @@ -33,13 +33,13 @@ using System; -namespace Grpc.Core +namespace Grpc.Core.Internal { /// <summary> - /// Flags for various call behaviors (client-side only). + /// Flags to enable special call behaviors (client-side only). /// </summary> [Flags] - public enum CallFlags + internal enum CallFlags { /// <summary> /// The call is idempotent (retrying the call doesn't change the outcome of the operation). |