Fix SocketStream.ReadByte() to release unreadable cache
This commit is contained in:
Родитель
da03e58dbe
Коммит
9197b265ff
|
@ -154,12 +154,12 @@
|
|||
<Compile Include="Streaming\TransformedDStream.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(CppDll)' == 'HasCpp' ">
|
||||
<ContentWithTargetPath Include="$(SolutionDir)..\cpp\x64\$(ConfigurationName)\Riosock.dll">
|
||||
<ContentWithTargetPath Include="..\..\..\cpp\x64\$(ConfigurationName)\Riosock.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Link>Cpp\Riosock.dll</Link>
|
||||
<TargetPath>Riosock.dll</TargetPath>
|
||||
</ContentWithTargetPath>
|
||||
<ContentWithTargetPath Include="$(SolutionDir)..\cpp\x64\$(ConfigurationName)\Riosock.pdb">
|
||||
<ContentWithTargetPath Include="..\..\..\cpp\x64\$(ConfigurationName)\Riosock.pdb">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Link>Cpp\Riosock.dll</Link>
|
||||
<TargetPath>Riosock.pdb</TargetPath>
|
||||
|
|
|
@ -124,7 +124,14 @@ namespace Microsoft.Spark.CSharp.Network
|
|||
recvDataCache = streamSocket.Receive();
|
||||
}
|
||||
|
||||
return recvDataCache.ReadByte();
|
||||
var v = recvDataCache.ReadByte();
|
||||
if (recvDataCache.IsReadable()) return v;
|
||||
|
||||
// Release cache if it is not readable. If we do not reset the cache here,
|
||||
// the cache will be used in next Read() that caused 0 bytes return.
|
||||
recvDataCache.Release();
|
||||
recvDataCache = null;
|
||||
return v;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||
<IsCodedUITest>False</IsCodedUITest>
|
||||
<TestProjectType>UnitTest</TestProjectType>
|
||||
<CppDll Condition="Exists('..\..\cpp\x64')">HasCpp</CppDll>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
@ -126,18 +125,6 @@
|
|||
<Name>Tests.Common</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(CppDll)' == 'HasCpp' ">
|
||||
<ContentWithTargetPath Include="$(SolutionDir)..\cpp\x64\$(ConfigurationName)\Riosock.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Link>Cpp\Riosock.pdb</Link>
|
||||
<TargetPath>Riosock.dll</TargetPath>
|
||||
</ContentWithTargetPath>
|
||||
<ContentWithTargetPath Include="$(SolutionDir)..\cpp\x64\$(ConfigurationName)\Riosock.pdb">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Link>Cpp\Riosock.pdb</Link>
|
||||
<TargetPath>Riosock.pdb</TargetPath>
|
||||
</ContentWithTargetPath>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -57,6 +57,9 @@ namespace AdapterTest
|
|||
|
||||
Thread.SpinWait(0);
|
||||
|
||||
// Send more bytes to test ReadByte() do not cause failures
|
||||
s.Write(bytes, 0, bytesRec);
|
||||
|
||||
// Keep sending to ensure no memory leak
|
||||
var longBytes = Encoding.UTF8.GetBytes(new string('x', 8192));
|
||||
for (int i = 0; i < 1000; i++)
|
||||
|
@ -113,6 +116,10 @@ namespace AdapterTest
|
|||
var oneByte = s.ReadByte();
|
||||
Assert.AreEqual((byte)1, oneByte);
|
||||
|
||||
// Receive more message to test ReadByte do not cause failures.
|
||||
bytesRec = s.Read(bytes, 0, bytes.Length);
|
||||
Assert.AreNotEqual(0, bytesRec);
|
||||
|
||||
// Keep receiving to ensure no memory leak.
|
||||
while (true)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
<AssemblyName>SparkCLRPerf</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<CppDll Condition="Exists('..\..\..\cpp\x64')">HasCpp</CppDll>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
@ -49,16 +48,6 @@
|
|||
</None>
|
||||
<None Include="data\deletionbenchmarktestdata.csv" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(CppDll)' == 'HasCpp' ">
|
||||
<None Include="$(SolutionDir)..\cpp\x64\$(ConfigurationName)\Riosock.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Link>Cpp\Riosock.dll</Link>
|
||||
</None>
|
||||
<None Include="$(SolutionDir)..\cpp\x64\$(ConfigurationName)\Riosock.pdb">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Link>Cpp\Riosock.pdb</Link>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Adapter\Microsoft.Spark.CSharp\Adapter.csproj">
|
||||
<Project>{ce999a96-f42b-4e80-b208-709d7f49a77c}</Project>
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
<AssemblyName>SparkCLRSamples</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<CppDll Condition="Exists('..\..\..\cpp\x64')">HasCpp</CppDll>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
@ -79,18 +78,6 @@
|
|||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(CppDll)' == 'HasCpp' ">
|
||||
<ContentWithTargetPath Include="$(SolutionDir)..\cpp\x64\$(ConfigurationName)\Riosock.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Link>Cpp\Riosock.dll</Link>
|
||||
<TargetPath>Riosock.dll</TargetPath>
|
||||
</ContentWithTargetPath>
|
||||
<ContentWithTargetPath Include="$(SolutionDir)..\cpp\x64\$(ConfigurationName)\Riosock.pdb">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Link>Cpp\Riosock.pdb</Link>
|
||||
<TargetPath>Riosock.pdb</TargetPath>
|
||||
</ContentWithTargetPath>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="data\csvtestlog.txt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
<AssemblyName>CSharpWorker</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<CppDll Condition="Exists('..\..\..\cpp\x64')">HasCpp</CppDll>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
|
@ -51,18 +50,6 @@
|
|||
<Compile Include="TaskRunner.cs" />
|
||||
<Compile Include="Worker.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(CppDll)' == 'HasCpp' ">
|
||||
<ContentWithTargetPath Include="$(SolutionDir)..\cpp\x64\$(ConfigurationName)\Riosock.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Link>Cpp\Riosock.dll</Link>
|
||||
<TargetPath>Riosock.dll</TargetPath>
|
||||
</ContentWithTargetPath>
|
||||
<ContentWithTargetPath Include="$(SolutionDir)..\cpp\x64\$(ConfigurationName)\Riosock.pdb">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Link>Cpp\Riosock.pdb</Link>
|
||||
<TargetPath>Riosock.pdb</TargetPath>
|
||||
</ContentWithTargetPath>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Adapter\Microsoft.Spark.CSharp\Adapter.csproj">
|
||||
<Project>{ce999a96-f42b-4e80-b208-709d7f49a77c}</Project>
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
|
||||
<IsCodedUITest>False</IsCodedUITest>
|
||||
<TestProjectType>UnitTest</TestProjectType>
|
||||
<CppDll Condition="Exists('..\..\cpp\x64')">HasCpp</CppDll>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
@ -77,18 +76,6 @@
|
|||
<ItemGroup>
|
||||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(CppDll)' == 'HasCpp' ">
|
||||
<ContentWithTargetPath Include="$(SolutionDir)..\cpp\x64\$(ConfigurationName)\Riosock.dll">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Link>Cpp\Riosock.dll</Link>
|
||||
<TargetPath>Riosock.dll</TargetPath>
|
||||
</ContentWithTargetPath>
|
||||
<ContentWithTargetPath Include="$(SolutionDir)..\cpp\x64\$(ConfigurationName)\Riosock.pdb">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<Link>Cpp\Riosock.pdb</Link>
|
||||
<TargetPath>Riosock.pdb</TargetPath>
|
||||
</ContentWithTargetPath>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
|
|
Загрузка…
Ссылка в новой задаче