Skip to content

Commit b6454dd

Browse files
authored
Merge pull request #312 from mysql-net/netstandard2.0
Target netstandard2.0. Fixes #270
2 parents 71b208f + f75f35f commit b6454dd

File tree

16 files changed

+127
-51
lines changed

16 files changed

+127
-51
lines changed

.ci/build.ps1

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function DownloadWithRetry([string] $url, [string] $downloadLocation, [int] $ret
3131
$repoFolder = Join-Path $PSScriptRoot ..
3232
$env:REPO_FOLDER = $repoFolder
3333

34-
$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/1.0.0-msbuild-rtm.zip"
34+
$koreBuildZip="https://github.com/aspnet/KoreBuild/archive/rel/2.0.0-preview2.zip"
3535
if ($env:KOREBUILD_ZIP)
3636
{
3737
$koreBuildZip=$env:KOREBUILD_ZIP
@@ -61,21 +61,31 @@ if (!(Test-Path $buildFolder)) {
6161
}
6262
}
6363

64-
$dotnetVersion = "1.0.3"
65-
$dotnetChannel = "rel-1.0.0"
66-
$dotnetSharedRuntimeVersion = "1.1.1"
67-
$dotnetSharedRuntimeChannel = "rel-1.0.0"
64+
$dotnetArch = 'x64'
65+
$dotnetChannel = "preview"
66+
$dotnetVersion = "2.0.0-preview2-006497"
6867

6968
$dotnetLocalInstallFolder = $env:DOTNET_INSTALL_DIR
7069
if (!$dotnetLocalInstallFolder)
7170
{
7271
$dotnetLocalInstallFolder = "$env:LOCALAPPDATA\Microsoft\dotnet\"
7372
}
7473

75-
& "$buildFolder\dotnet\dotnet-install.ps1" -Channel $dotnetChannel -Version $dotnetVersion -Architecture x64
76-
# Avoid redownloading the CLI if it's already installed.
77-
$sharedRuntimePath = [IO.Path]::Combine($dotnetLocalInstallFolder, 'shared', 'Microsoft.NETCore.App', $dotnetSharedRuntimeVersion)
78-
if (!(Test-Path $sharedRuntimePath))
74+
function InstallSharedRuntime([string] $version, [string] $channel)
7975
{
80-
& "$buildFolder\dotnet\dotnet-install.ps1" -Channel $dotnetSharedRuntimeChannel -SharedRuntime -Version $dotnetSharedRuntimeVersion -Architecture x64
76+
$sharedRuntimePath = [IO.Path]::Combine($dotnetLocalInstallFolder, 'shared', 'Microsoft.NETCore.App', $version)
77+
# Avoid redownloading the CLI if it's already installed.
78+
if (!(Test-Path $sharedRuntimePath))
79+
{
80+
& "$buildFolder\dotnet\dotnet-install.ps1" -Channel $channel `
81+
-SharedRuntime `
82+
-Version $version `
83+
-Architecture $dotnetArch `
84+
-InstallDir $dotnetLocalInstallFolder
85+
}
8186
}
87+
88+
& "$buildFolder\dotnet\dotnet-install.ps1" -Channel $dotnetChannel -Version $dotnetVersion -Architecture $dotnetArch
89+
InstallSharedRuntime -version "1.1.2" -channel "release/1.1.0"
90+
91+
dotnet --info

.ci/test.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
$ErrorActionPreference = "Stop"
2-
31
# restore
42
dotnet restore
53
if ($LASTEXITCODE -ne 0){

.travis.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,20 @@ before_install:
2121
- sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet-release/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list'
2222
- sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 417A0893
2323
- sudo apt-get update
24-
- sudo apt-get install -y dotnet-dev-1.0.1
24+
- sudo apt-get install -y dotnet-sdk-2.0.0-preview2-006497 dotnet-sharedframework-microsoft.netcore.app-1.1.2
2525

2626
script:
2727
- dotnet restore
28-
- dotnet test tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj -c Release -f netcoreapp1.1.1
29-
- dotnet build tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
30-
- echo 'Executing tests with No Compression, No SSL' && ./.ci/use-config.sh config.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
31-
- echo 'Executing Debug Only tests' && time dotnet test tests/SideBySide/SideBySide.csproj -c Debug -f netcoreapp1.1.1 --filter "FullyQualifiedName~SideBySide.DebugOnlyTests"
32-
- echo 'Executing tests with Compression, No SSL' && ./.ci/use-config.sh config.compression.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
33-
- echo 'Executing tests with No Compression, SSL' && ./.ci/use-config.sh config.ssl.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
34-
- echo 'Executing tests with Compression, SSL' && ./.ci/use-config.sh config.compression+ssl.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
35-
- echo 'Executing tests with Unix Domain Socket, No Compression, No SSL' && ./.ci/use-config.sh config.uds.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
36-
- echo 'Executing tests with Buffering, No Compression, No SSL' && ./.ci/use-config.sh config.buffer.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.1
28+
- dotnet test tests/MySqlConnector.Tests/MySqlConnector.Tests.csproj -c Release -f netcoreapp2.0
29+
- dotnet build tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
30+
- echo 'Executing netcoreapp1.1.2 tests with No Compression, No SSL' && ./.ci/use-config.sh config.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp1.1.2
31+
- echo 'Executing netcoreapp2.0 tests with No Compression, No SSL' && ./.ci/use-config.sh config.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
32+
- echo 'Executing netcoreapp2.0 Debug Only tests' && time dotnet test tests/SideBySide/SideBySide.csproj -c Debug -f netcoreapp2.0 --filter "FullyQualifiedName~SideBySide.DebugOnlyTests"
33+
- echo 'Executing netcoreapp2.0 tests with Compression, No SSL' && ./.ci/use-config.sh config.compression.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
34+
- echo 'Executing netcoreapp2.0 tests with No Compression, SSL' && ./.ci/use-config.sh config.ssl.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
35+
- echo 'Executing netcoreapp2.0 tests with Compression, SSL' && ./.ci/use-config.sh config.compression+ssl.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
36+
- echo 'Executing netcoreapp2.0 tests with Unix Domain Socket, No Compression, No SSL' && ./.ci/use-config.sh config.uds.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
37+
- echo 'Executing netcoreapp2.0 tests with Buffering, No Compression, No SSL' && ./.ci/use-config.sh config.buffer.json 172.17.0.1 3307 $NAME $FEATURES && time dotnet test tests/SideBySide/SideBySide.csproj -c Release -f netcoreapp2.0
3738

3839
after_script:
3940
- chmod +x .ci/build-docs.sh && ./.ci/build-docs.sh

src/MySqlConnector/MySqlClient/MySqlConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ internal void FinishQuerying()
314314

315315
private async Task<MySqlSession> CreateSessionAsync(IOBehavior ioBehavior, CancellationToken cancellationToken)
316316
{
317-
var connectTimeout = m_connectionSettings.ConnectionTimeout == 0 ? Timeout.InfiniteTimeSpan : TimeSpan.FromSeconds(checked((int) m_connectionSettings.ConnectionTimeout));
317+
var connectTimeout = m_connectionSettings.ConnectionTimeout == 0 ? Timeout.InfiniteTimeSpan : TimeSpan.FromMilliseconds(m_connectionSettings.ConnectionTimeoutMilliseconds);
318318
using (var timeoutSource = new CancellationTokenSource(connectTimeout))
319319
using (var linkedSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutSource.Token))
320320
{

src/MySqlConnector/MySqlConnector.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<AssemblyTitle>Async MySQL Connector</AssemblyTitle>
88
<VersionPrefix>0.24.2</VersionPrefix>
99
<Authors>Bradley Grainger;Caleb Lloyd</Authors>
10-
<TargetFrameworks>net45;net46;netstandard1.3</TargetFrameworks>
10+
<TargetFrameworks>net45;net46;netstandard1.3;netstandard2.0</TargetFrameworks>
1111
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1212
<AssemblyName>MySqlConnector</AssemblyName>
1313
<PackageId>MySqlConnector</PackageId>
@@ -28,7 +28,7 @@
2828
<Reference Include="System.Transactions" />
2929
</ItemGroup>
3030

31-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
31+
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' OR '$(TargetFramework)' == 'netstandard2.0' ">
3232
<PackageReference Include="System.Buffers" Version="4.3.0" />
3333
<PackageReference Include="System.Data.Common" Version="4.3.0" />
3434
<PackageReference Include="System.Diagnostics.Process" Version="4.3.0" />

src/MySqlConnector/Serialization/ConnectionSettings.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,30 @@ public ConnectionSettings(MySqlConnectionStringBuilder csb)
101101
public bool TreatTinyAsBoolean { get; }
102102
public bool UseAffectedRows { get; }
103103
public bool UseCompression { get; }
104+
105+
// Helper Functions
106+
private int? _connectionTimeoutMilliseconds;
107+
public int ConnectionTimeoutMilliseconds
108+
{
109+
get
110+
{
111+
if (!_connectionTimeoutMilliseconds.HasValue)
112+
{
113+
try
114+
{
115+
checked
116+
{
117+
_connectionTimeoutMilliseconds = ConnectionTimeout * 1000;
118+
}
119+
}
120+
catch (OverflowException)
121+
{
122+
_connectionTimeoutMilliseconds = Int32.MaxValue;
123+
}
124+
}
125+
return _connectionTimeoutMilliseconds.Value;
126+
}
127+
}
128+
104129
}
105130
}

src/MySqlConnector/Serialization/MySqlSession.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,12 @@ public async Task ConnectAsync(ConnectionSettings cs, IOBehavior ioBehavior, Can
195195
throw new MySqlException("Unable to connect to any of the specified MySQL hosts.");
196196
}
197197

198-
var socketByteHandler = new SocketByteHandler(m_socket);
199-
m_payloadHandler = new StandardPayloadHandler(socketByteHandler);
198+
#if NETSTANDARD2_0
199+
var byteHandler = new StreamByteHandler(m_networkStream);
200+
#else
201+
var byteHandler = new SocketByteHandler(m_socket);
202+
#endif
203+
m_payloadHandler = new StandardPayloadHandler(byteHandler);
200204

201205
var payload = await ReceiveAsync(ioBehavior, cancellationToken).ConfigureAwait(false);
202206
var reader = new ByteArrayReader(payload.ArraySegment.Array, payload.ArraySegment.Offset, payload.ArraySegment.Count);
@@ -502,6 +506,7 @@ private async Task<bool> OpenTcpSocketAsync(ConnectionSettings cs, IOBehavior io
502506
try
503507
{
504508
tcpClient = new TcpClient(ipAddress.AddressFamily);
509+
505510
using (cancellationToken.Register(() => tcpClient?.Client?.Dispose()))
506511
{
507512
try
@@ -515,7 +520,21 @@ private async Task<bool> OpenTcpSocketAsync(ConnectionSettings cs, IOBehavior io
515520
#if NETSTANDARD1_3
516521
await tcpClient.ConnectAsync(ipAddress, cs.Port).ConfigureAwait(false);
517522
#else
518-
tcpClient.Connect(ipAddress, cs.Port);
523+
if (Utility.IsWindows())
524+
{
525+
tcpClient.Connect(ipAddress, cs.Port);
526+
}
527+
else
528+
{
529+
// non-windows platforms block on synchronous connect, use send/receive timeouts: https://github.com/dotnet/corefx/issues/20954
530+
var originalSendTimeout = tcpClient.Client.SendTimeout;
531+
var originalReceiveTimeout = tcpClient.Client.ReceiveTimeout;
532+
tcpClient.Client.SendTimeout = cs.ConnectionTimeoutMilliseconds;
533+
tcpClient.Client.ReceiveTimeout = cs.ConnectionTimeoutMilliseconds;
534+
tcpClient.Connect(ipAddress, cs.Port);
535+
tcpClient.Client.SendTimeout = originalSendTimeout;
536+
tcpClient.Client.ReceiveTimeout = originalReceiveTimeout;
537+
}
519538
#endif
520539
}
521540
}

tests/Benchmark/Benchmark.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
4-
<TargetFrameworks>netcoreapp1.1;net462</TargetFrameworks>
4+
<TargetFrameworks>netcoreapp1.1;net462;netcoreapp2.0</TargetFrameworks>
55
</PropertyGroup>
66
<ItemGroup>
77
<PackageReference Include="BenchmarkDotNet" Version="0.10.8" />

tests/Benchmark/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ static void Main()
2424
.With(JitOptimizationsValidator.FailOnError)
2525
.With(MemoryDiagnoser.Default)
2626
.With(StatisticColumn.AllStatistics)
27-
.With(Job.Default.With(Runtime.Clr).With(Jit.RyuJit).With(Platform.X64).With(CsProjClassicNetToolchain.Net462))
28-
.With(Job.Default.With(Runtime.Core).With(CsProjCoreToolchain.NetCoreApp11))
27+
.With(Job.Default.With(Runtime.Clr).With(Jit.RyuJit).With(Platform.X64).With(CsProjClassicNetToolchain.Net462).WithId("net462"))
28+
.With(Job.Default.With(Runtime.Core).With(CsProjCoreToolchain.NetCoreApp11).WithId("netcore11"))
29+
.With(Job.Default.With(Runtime.Core).With(CsProjCoreToolchain.NetCoreApp20).WithId("netcore20"))
2930
.With(DefaultExporters.Csv);
3031

3132
var summary = BenchmarkRunner.Run<MySqlClient>(customConfig);

tests/MySqlConnector.Performance/MySqlConnector.Performance.csproj

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp1.1.1</TargetFramework>
4+
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
55
<PreserveCompilationContext>true</PreserveCompilationContext>
66
<AssemblyName>MySqlConnector.Performance</AssemblyName>
77
<OutputType>Exe</OutputType>
@@ -12,16 +12,16 @@
1212
</PropertyGroup>
1313

1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
16-
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
17-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
18-
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.1" />
19-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
20-
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="1.1.1" />
21-
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
22-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
23-
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
24-
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
15+
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.0-*" />
16+
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.0-*" />
17+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0-*" />
18+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0-*" />
19+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0-*" />
20+
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="2.0.0-*" />
21+
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.0.0-*" />
22+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0-*" />
23+
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0-*" />
24+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0.0-*" />
2525
</ItemGroup>
2626

2727
<ItemGroup Condition=" '$(Configuration)' != 'Baseline' ">

0 commit comments

Comments
 (0)