Skip to content

Commit c7ca9ce

Browse files
author
John Luo
authored
Required changes for 3.0.0 preview3 (#112)
* Required changes for 3.0.0 preview3 * Add scripts to install dotnet SDK
1 parent f29c274 commit c7ca9ce

File tree

13 files changed

+145
-23
lines changed

13 files changed

+145
-23
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ branches:
99
only:
1010
- master
1111
install:
12-
- curl -o dotnet-sdk.tar.gz -sSL https://download.visualstudio.microsoft.com/download/pr/efa6dde9-a5ee-4322-b13c-a2a02d3980f0/dad445eba341c1d806bae5c8afb47015/dotnet-sdk-3.0.100-preview-010184-linux-x64.tar.gz
13-
- mkdir -p $PWD/dotnet
14-
- tar zxf dotnet-sdk.tar.gz -C $PWD/dotnet
15-
- export PATH="$PWD/dotnet:$PATH"
12+
- ./build/get-dotnet.sh
13+
- export PATH="~/.dotnet/:$PATH"
1614
script:
1715
- ./build_and_test.sh

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,15 @@ Documentation and guides are coming soon! In the mean time we suggest referring
2727

2828
## To develop gRPC for ASP.NET Core
2929

30-
Install [.NET Core SDK 3 preview 2](https://dotnet.microsoft.com/download/dotnet-core/3.0).
30+
Installing .NET Core SDK:
31+
```
32+
# Run this script before building the project.
33+
./build/get-dotnet.sh or ./build/get-dotnet.ps1
34+
```
3135

3236
Setting up local feed with unreleased Grpc.* packages:
3337
```
34-
# For the time being, we are depending on unreleased Grpc.* packages.
38+
# We may depend on unreleased Grpc.* packages.
3539
# Run this script before building the project.
3640
./build/get-grpc.sh or ./build/get-grpc.ps1
3741
```

build/get-dotnet.ps1

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env powershell
2+
3+
<#
4+
.PARAMETER Upgrade
5+
Upgrade the version of gRPC packages to be downloaded to the latest on https://packages.grpc.io/
6+
.NOTES
7+
This function will create a file grpc-lock.txt. This lock file can be committed to source, but does not have to be.
8+
When the lock file is not present, the script will create one using latest available version from https://packages.grpc.io/.
9+
#>
10+
11+
param (
12+
[switch]$Upgrade = $false
13+
)
14+
15+
Set-StrictMode -Version 2
16+
$ErrorActionPreference = 'Stop'
17+
18+
# Variables
19+
20+
$WorkingDir = $PSScriptRoot
21+
$TempDir = Join-Path $WorkingDir 'obj'
22+
$InstallScriptUrl = 'https://dot.net/v1/dotnet-install.ps1'
23+
$InstallScriptPath = Join-Path $TempDir 'dotnet-install.ps1'
24+
$GlobalJsonPath = Join-Path $WorkingDir '..' | Join-Path -ChildPath 'global.json'
25+
26+
# Functions
27+
28+
function Ensure-Dir([string]$path) {
29+
if (!(Test-Path $path -PathType Container)) {
30+
New-Item -ItemType Directory -Force -Path $path | Out-Null
31+
}
32+
}
33+
34+
# Main
35+
36+
# Resolve SDK version
37+
$GlobalJson = Get-Content -Raw $GlobalJsonPath | ConvertFrom-Json
38+
$SDKVersion = $GlobalJson.sdk.version
39+
40+
# Download install script
41+
Ensure-Dir $TempDir
42+
Write-Host "Downloading install script: $InstallScriptUrl => $InstallScriptPath"
43+
Invoke-WebRequest -Uri $InstallScriptUrl -OutFile $InstallScriptPath
44+
&$InstallScriptPath -Version $SDKVersion

build/get-dotnet.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
# variables
6+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
7+
OBJDIR="$DIR/obj"
8+
global_json_path="$DIR/../global.json"
9+
install_script_url="https://dot.net/v1/dotnet-install.sh"
10+
install_script_path="$OBJDIR/dotnet-install.sh"
11+
12+
# functions
13+
ensure_dir() {
14+
[ -d $1 ] || mkdir $1
15+
}
16+
17+
# main
18+
19+
# resolve SDK version
20+
sdk_version=$(jq -r .sdk.version $global_json_path)
21+
22+
# download dotnet-install.sh
23+
ensure_dir $OBJDIR
24+
25+
echo "Downloading install script: $install_script_url => $install_script_path"
26+
curl -sSL -o $install_script_path $install_script_url
27+
chmod +x $install_script_path
28+
29+
$install_script_path -v $sdk_version

examples/Server/Startup.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
#endregion
1818

19-
using Grpc.AspNetCore;
2019
using Microsoft.AspNetCore.Builder;
21-
using Microsoft.AspNetCore.Hosting;
2220
using Microsoft.Extensions.DependencyInjection;
2321

2422
namespace GRPCServer
@@ -34,7 +32,7 @@ public void ConfigureServices(IServiceCollection services)
3432
}
3533

3634
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
37-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
35+
public void Configure(IApplicationBuilder app)
3836
{
3937
app.UseRouting(routes =>
4038
{

global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "3.0.100-preview-010184"
3+
"version": "3.0.100-preview3-010313"
44
}
55
}

perf/benchmarkapps/BenchmarkServer/Startup.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616

1717
#endregion
1818

19-
using Grpc.AspNetCore;
2019
using Microsoft.AspNetCore.Builder;
21-
using Microsoft.AspNetCore.Hosting;
2220
using Microsoft.Extensions.DependencyInjection;
2321

2422
namespace BenchmarkServer
@@ -33,7 +31,7 @@ public void ConfigureServices(IServiceCollection services)
3331
}
3432

3533
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
36-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
34+
public void Configure(IApplicationBuilder app)
3735
{
3836
app.UseRouting(routes =>
3937
{

src/Grpc.AspNetCore.Server/Internal/PipeExtensions.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,28 @@ public static Task WriteMessageAsync(this PipeWriter pipeWriter, byte[] messageD
5555
return Task.FromException(new RpcException(SendingMessageExceedsLimitStatus));
5656
}
5757

58+
// Must call StartAsync before the first pipeWriter.GetSpan() in WriteHeader
59+
var response = serverCallContext.HttpContext.Response;
60+
if (!response.HasStarted)
61+
{
62+
var startAsyncTask = response.StartAsync();
63+
if (!startAsyncTask.IsCompletedSuccessfully)
64+
{
65+
return pipeWriter.WriteMessageCoreAsyncAwaited(messageData, serverCallContext, flush, startAsyncTask);
66+
}
67+
}
68+
69+
return pipeWriter.WriteMessageCoreAsync(messageData, serverCallContext, flush);
70+
}
71+
72+
private static async Task WriteMessageCoreAsyncAwaited(this PipeWriter pipeWriter, byte[] messageData, HttpContextServerCallContext serverCallContext, bool flush, Task startAsyncTask)
73+
{
74+
await startAsyncTask;
75+
await pipeWriter.WriteMessageCoreAsync(messageData, serverCallContext, flush);
76+
}
77+
78+
private static Task WriteMessageCoreAsync(this PipeWriter pipeWriter, byte[] messageData, HttpContextServerCallContext serverCallContext, bool flush)
79+
{
5880
WriteHeader(pipeWriter, messageData.Length);
5981
pipeWriter.Write(messageData);
6082

@@ -77,7 +99,7 @@ public static Task WriteMessageAsync(this PipeWriter pipeWriter, byte[] messageD
7799

78100
private static void WriteHeader(PipeWriter pipeWriter, int length)
79101
{
80-
Span<byte> headerData = pipeWriter.GetSpan(HeaderSize);
102+
var headerData = pipeWriter.GetSpan(HeaderSize);
81103
// Messages are currently always uncompressed
82104
headerData[0] = 0;
83105
EncodeMessageLength(length, headerData.Slice(1));

test/FunctionalTests/Infrastructure/GrpcTestFixture.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using System.Net.Http;
2121
using FunctionalTestsWebsite.Infrastructure;
2222
using Microsoft.AspNetCore.Hosting;
23+
using Microsoft.AspNetCore.Http.Features;
2324
using Microsoft.AspNetCore.TestHost;
2425
using Microsoft.Extensions.DependencyInjection;
2526

test/Grpc.AspNetCore.Server.Tests/GrpcEndpointRouteBuilderExtensionsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ public void MapGrpcService_CanBind_CreatesEndpoints()
7878

7979
var routeEndpoint1 = (RouteEndpoint)endpoints[0];
8080
Assert.AreEqual("/Greet.Greeter/SayHello", routeEndpoint1.RoutePattern.RawText);
81-
Assert.AreEqual("POST", ((IHttpMethodMetadata)routeEndpoint1.Metadata.Single()).HttpMethods.Single());
81+
Assert.AreEqual("POST", routeEndpoint1.Metadata.GetMetadata<IHttpMethodMetadata>().HttpMethods.Single());
8282

8383
var routeEndpoint2 = (RouteEndpoint)endpoints[1];
8484
Assert.AreEqual("/Greet.Greeter/SayHellos", routeEndpoint2.RoutePattern.RawText);
85-
Assert.AreEqual("POST", ((IHttpMethodMetadata)routeEndpoint2.Metadata.Single()).HttpMethods.Single());
85+
Assert.AreEqual("POST", routeEndpoint2.Metadata.GetMetadata<IHttpMethodMetadata>().HttpMethods.Single());
8686
}
8787

8888
[Test]

0 commit comments

Comments
 (0)