You've already forked linux-packaging-mono
Imported Upstream version 5.10.0.47
Former-commit-id: d0813289fa2d35e1f8ed77530acb4fb1df441bc0
This commit is contained in:
parent
88ff76fe28
commit
e46a49ecf1
@@ -4,5 +4,6 @@
|
||||
<PropertyGroup>
|
||||
<AssemblyVersion>4.0.1.0</AssemblyVersion>
|
||||
<AssemblyKey>Open</AssemblyKey>
|
||||
<IsUAP>true</IsUAP>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -3,9 +3,16 @@
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ref\System.IO.Ports.csproj">
|
||||
<SupportedFramework>net461;netcoreapp2.0;$(AllXamarinFrameworks)</SupportedFramework>
|
||||
<SupportedFramework>net461;netcoreapp2.0;$(AllXamarinFrameworks);$(UAPvNextTFM)</SupportedFramework>
|
||||
</ProjectReference>
|
||||
<File Include="$(PlaceHolderFile)">
|
||||
<TargetPath>runtimes/win/lib/$(UAPvNextTFM)</TargetPath>
|
||||
</File>
|
||||
<InboxOnTargetFramework Include="$(UAPvNextTFM)" />
|
||||
<ProjectReference Include="..\src\System.IO.Ports.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InboxOnTargetFramework Include="$(UAPvNextTFM)" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
@@ -6,4 +6,4 @@
|
||||
netfx;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{75DE4259-43BB-4067-9F30-3AC920D51AEC}</ProjectGuid>
|
||||
<IsPartialFacadeAssembly Condition="'$(TargetGroup)' == 'netfx'">true</IsPartialFacadeAssembly>
|
||||
<!-- Must match version supported by frameworks which support 4.0.* inbox.
|
||||
Can be removed when API is added and this assembly is versioned to 4.1.* -->
|
||||
<AssemblyVersion Condition="'$(TargetsNetFx)' != 'true'">4.0.1.0</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<BuildConfigurations>
|
||||
<PackageConfigurations>
|
||||
netstandard-Windows_NT;
|
||||
netstandard;
|
||||
netfx;
|
||||
</PackageConfigurations>
|
||||
<BuildConfigurations>
|
||||
$(PackageConfigurations)
|
||||
uap-Windows_NT;
|
||||
</BuildConfigurations>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
## need to create a uap config that uses CreateFileFromApp, then remove this baseline ##
|
||||
# https://github.com/dotnet/corefx/issues/21025
|
||||
kernel32.dll!CreateFileW
|
||||
@@ -0,0 +1,2 @@
|
||||
# not available in OneCore
|
||||
kernel32.dll!CreateFileW
|
||||
@@ -121,9 +121,6 @@
|
||||
<data name="IndexOutOfRange_IORaceCondition" xml:space="preserve">
|
||||
<value>Probable I/O race condition detected while copying memory. The I/O package is not thread safe by default. In multithreaded applications, a stream must be accessed in a thread-safe way, such as a thread-safe wrapper returned by TextReader's or TextWriter's Synchronized methods. This also applies to classes like StreamWriter and StreamReader.</value>
|
||||
</data>
|
||||
<data name="IO_BindHandleFailed" xml:space="preserve">
|
||||
<value>BindHandle for ThreadPool failed on this handle.</value>
|
||||
</data>
|
||||
<data name="IO_OperationAborted" xml:space="preserve">
|
||||
<value>The I/O operation has been aborted because of either a thread exit or an application request.</value>
|
||||
</data>
|
||||
@@ -169,4 +166,7 @@
|
||||
<data name="PlatformNotSupported_IOPorts" xml:space="preserve">
|
||||
<value>System.IO.Ports is currently only supported on Windows.</value>
|
||||
</data>
|
||||
<data name="PlatformNotSupported_SerialPort_GetPortNames" xml:space="preserve">
|
||||
<value>Enumeration of serial port names is not supported on the current platform.</value>
|
||||
</data>
|
||||
</root>
|
||||
|
||||
@@ -15,12 +15,15 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netstandard-Windows_NT-Release|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Windows_NT-Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Windows_NT-Release|AnyCPU'" />
|
||||
<ItemGroup Condition="'$(TargetGroup)' != 'netfx' AND '$(TargetsWindows)' == 'true'">
|
||||
<Compile Include="System\IO\Ports\Handshake.cs" />
|
||||
<Compile Include="System\IO\Ports\InternalResources.cs" />
|
||||
<Compile Include="System\IO\Ports\NativeMethods.cs" />
|
||||
<Compile Include="System\IO\Ports\Parity.cs" />
|
||||
<Compile Include="System\IO\Ports\SerialData.cs" />
|
||||
<Compile Include="System\IO\Ports\SerialDataReceivedEventArgs.cs" />
|
||||
<Compile Include="System\IO\Ports\SerialDataReceivedEventHandler.cs" />
|
||||
<Compile Include="System\IO\Ports\SerialError.cs" />
|
||||
<Compile Include="System\IO\Ports\SerialErrorReceivedEventArgs.cs" />
|
||||
@@ -28,10 +31,7 @@
|
||||
<Compile Include="System\IO\Ports\SerialPinChange.cs" />
|
||||
<Compile Include="System\IO\Ports\SerialPinChangedEventArgs.cs" />
|
||||
<Compile Include="System\IO\Ports\SerialPinChangedEventHandler.cs" />
|
||||
<Compile Include="System\IO\Ports\SerialPort.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="System\IO\Ports\SerialDataReceivedEventArgs.cs" />
|
||||
<Compile Include="System\IO\Ports\SerialPort.cs" />
|
||||
<Compile Include="System\IO\Ports\SerialStream.cs" />
|
||||
<Compile Include="System\IO\Ports\StopBits.cs" />
|
||||
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.DCB.cs">
|
||||
@@ -85,9 +85,6 @@
|
||||
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.WaitCommEvent.cs">
|
||||
<Link>Common\Interop\Windows\kernel32\Interop.WaitCommEvent.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.CreateFile.cs">
|
||||
<Link>Common\Interop\Windows\kernel32\Interop.CreateFile.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.ReadFile_SafeHandle_IntPtr.cs">
|
||||
<Link>Common\Interop\Windows\kernel32\Interop.ReadFile_SafeHandle_IntPtr.cs</Link>
|
||||
</Compile>
|
||||
@@ -115,6 +112,9 @@
|
||||
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.FileTypes.cs">
|
||||
<Link>Common\Interop\Windows\Interop.FileTypes.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonPath)\Interop\Windows\kernelbase\Interop.OpenCommPort.cs">
|
||||
<Link>Common\Interop\Windows\kernelbase\Interop.OpenCommPort.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="$(CommonPath)\System\IO\PathInternal.Windows.cs">
|
||||
<Link>Common\System\IO\PathInternal.Windows.cs</Link>
|
||||
</Compile>
|
||||
@@ -131,6 +131,19 @@
|
||||
<Link>Common\Interop\Windows\Interop.BOOL.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetGroup)' != 'uap' and '$(TargetsWindows)' == 'true'">
|
||||
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.CreateFile.cs">
|
||||
<Link>Common\Interop\Windows\kernel32\Interop.CreateFile.cs</Link>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetGroup)' == 'uap'">
|
||||
<Compile Include="System\IO\Ports\SerialPort.Uap.cs" />
|
||||
<Compile Include="System\IO\Ports\SerialStream.Uap.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetGroup)' != 'uap' and '$(TargetGroup)' != 'netfx' and '$(TargetsWindows)' == 'true'">
|
||||
<Compile Include="System\IO\Ports\SerialPort.Win32.cs" />
|
||||
<Compile Include="System\IO\Ports\SerialStream.Win32.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetGroup)' == 'netfx'">
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="System" />
|
||||
@@ -138,5 +151,20 @@
|
||||
<ItemGroup Condition="'$(TargetGroup)' != 'netfx'">
|
||||
<Reference Include="Microsoft.Win32.Registry" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition="'$(TargetGroup)' == 'uap'">
|
||||
<Reference Include="Microsoft.Win32.Primitives" />
|
||||
<Reference Include="System.ComponentModel.Primitives" />
|
||||
<Reference Include="System.Diagnostics.Debug" />
|
||||
<Reference Include="System.Diagnostics.Tools" />
|
||||
<Reference Include="System.Resources.ResourceManager" />
|
||||
<Reference Include="System.Runtime" />
|
||||
<Reference Include="System.Runtime.Extensions" />
|
||||
<Reference Include="System.Runtime.InteropServices" />
|
||||
<Reference Include="System.Text.Encoding.Extensions" />
|
||||
<Reference Include="System.Threading" />
|
||||
<Reference Include="System.Threading.Overlapped" />
|
||||
<Reference Include="System.Threading.Thread" />
|
||||
<Reference Include="System.Threading.ThreadPool" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
17
external/corefx/src/System.IO.Ports/src/System/IO/Ports/SerialPort.Uap.cs
vendored
Normal file
17
external/corefx/src/System.IO.Ports/src/System/IO/Ports/SerialPort.Uap.cs
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace System.IO.Ports
|
||||
{
|
||||
public partial class SerialPort : Component
|
||||
{
|
||||
public static string[] GetPortNames()
|
||||
{
|
||||
// See https://github.com/dotnet/corefx/issues/20588 for more information.
|
||||
throw new PlatformNotSupportedException(System.SR.PlatformNotSupported_SerialPort_GetPortNames);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
external/corefx/src/System.IO.Ports/src/System/IO/Ports/SerialPort.Win32.cs
vendored
Normal file
38
external/corefx/src/System.IO.Ports/src/System/IO/Ports/SerialPort.Win32.cs
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.Win32;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace System.IO.Ports
|
||||
{
|
||||
public partial class SerialPort : Component
|
||||
{
|
||||
public static string[] GetPortNames()
|
||||
{
|
||||
// Hitting the registry for this isn't the only way to get the ports.
|
||||
//
|
||||
// WMI: https://msdn.microsoft.com/en-us/library/aa394413.aspx
|
||||
// QueryDosDevice: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365461.aspx
|
||||
//
|
||||
// QueryDosDevice involves finding any ports that map to \Device\Serialx (call with null to get all, then iterate to get the actual device name)
|
||||
|
||||
using (RegistryKey serialKey = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DEVICEMAP\SERIALCOMM"))
|
||||
{
|
||||
if (serialKey != null)
|
||||
{
|
||||
string[] result = serialKey.GetValueNames();
|
||||
for (int i = 0; i < result.Length; i++)
|
||||
{
|
||||
// Replace the name in the array with its value.
|
||||
result[i] = (string)serialKey.GetValue(result[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using System.Text;
|
||||
|
||||
namespace System.IO.Ports
|
||||
{
|
||||
public class SerialPort : Component
|
||||
public partial class SerialPort : Component
|
||||
{
|
||||
public const int InfiniteTimeout = -1;
|
||||
|
||||
@@ -555,32 +555,6 @@ namespace System.IO.Ports
|
||||
_internalSerialStream.DiscardOutBuffer();
|
||||
}
|
||||
|
||||
public static string[] GetPortNames()
|
||||
{
|
||||
// Hitting the registry for this isn't the only way to get the ports.
|
||||
//
|
||||
// WMI: https://msdn.microsoft.com/en-us/library/aa394413.aspx
|
||||
// QueryDosDevice: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365461.aspx
|
||||
//
|
||||
// QueryDosDevice involves finding any ports that map to \Device\Serialx (call with null to get all, then iterate to get the actual device name)
|
||||
|
||||
using (RegistryKey serialKey = Registry.LocalMachine.OpenSubKey(@"HARDWARE\DEVICEMAP\SERIALCOMM"))
|
||||
{
|
||||
if (serialKey != null)
|
||||
{
|
||||
string[] result = serialKey.GetValueNames();
|
||||
for (int i = 0; i < result.Length; i++)
|
||||
{
|
||||
// Replace the name in the array with its value.
|
||||
result[i] = (string)serialKey.GetValue(result[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
|
||||
// SerialPort is open <=> SerialPort has an associated SerialStream.
|
||||
// The two statements are functionally equivalent here, so this method basically calls underlying Stream's
|
||||
// constructor from the main properties specified in SerialPort: baud, stopBits, parity, dataBits,
|
||||
|
||||
19
external/corefx/src/System.IO.Ports/src/System/IO/Ports/SerialStream.Uap.cs
vendored
Normal file
19
external/corefx/src/System.IO.Ports/src/System/IO/Ports/SerialStream.Uap.cs
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
|
||||
namespace System.IO.Ports
|
||||
{
|
||||
internal sealed partial class SerialStream
|
||||
{
|
||||
public SafeFileHandle OpenPort(uint portNumber)
|
||||
{
|
||||
return Interop.KernelBase.OpenCommPort(
|
||||
portNumber,
|
||||
Interop.Kernel32.GenericOperations.GENERIC_READ | Interop.Kernel32.GenericOperations.GENERIC_WRITE,
|
||||
NativeMethods.FILE_FLAG_OVERLAPPED);
|
||||
}
|
||||
}
|
||||
}
|
||||
22
external/corefx/src/System.IO.Ports/src/System/IO/Ports/SerialStream.Win32.cs
vendored
Normal file
22
external/corefx/src/System.IO.Ports/src/System/IO/Ports/SerialStream.Win32.cs
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using Microsoft.Win32.SafeHandles;
|
||||
using System.Globalization;
|
||||
|
||||
namespace System.IO.Ports
|
||||
{
|
||||
internal sealed partial class SerialStream
|
||||
{
|
||||
public SafeFileHandle OpenPort(uint portNumber)
|
||||
{
|
||||
return Interop.Kernel32.CreateFileDefaultSecurity(
|
||||
@"\\?\COM" + portNumber.ToString(CultureInfo.InvariantCulture),
|
||||
Interop.Kernel32.GenericOperations.GENERIC_READ | Interop.Kernel32.GenericOperations.GENERIC_WRITE,
|
||||
0, // comm devices must be opened w/exclusive-access
|
||||
FileMode.Open, // comm devices must use OPEN_EXISTING
|
||||
NativeMethods.FILE_FLAG_OVERLAPPED);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace System.IO.Ports
|
||||
{
|
||||
internal sealed class SerialStream : Stream
|
||||
internal sealed partial class SerialStream : Stream
|
||||
{
|
||||
private const int ErrorEvents = (int)(SerialError.Frame | SerialError.Overrun |
|
||||
SerialError.RXOver | SerialError.RXParity | SerialError.TXFull);
|
||||
@@ -50,9 +50,9 @@ namespace System.IO.Ports
|
||||
private Interop.Kernel32.COMSTAT _comStat;
|
||||
private Interop.Kernel32.COMMPROP _commProp;
|
||||
|
||||
// internal-use members
|
||||
internal SafeFileHandle _handle = null;
|
||||
internal EventLoopRunner _eventRunner;
|
||||
private SafeFileHandle _handle = null;
|
||||
private ThreadPoolBoundHandle _threadPoolBinding = null;
|
||||
private EventLoopRunner _eventRunner;
|
||||
private Task _waitForComEventTask = null;
|
||||
|
||||
private byte[] _tempBuf; // used to avoid multiple array allocations in ReadByte()
|
||||
@@ -590,19 +590,16 @@ namespace System.IO.Ports
|
||||
internal SerialStream(string portName, int baudRate, Parity parity, int dataBits, StopBits stopBits, int readTimeout, int writeTimeout, Handshake handshake,
|
||||
bool dtrEnable, bool rtsEnable, bool discardNull, byte parityReplace)
|
||||
{
|
||||
int flags = NativeMethods.FILE_FLAG_OVERLAPPED;
|
||||
|
||||
if ((portName == null) || !portName.StartsWith("COM", StringComparison.OrdinalIgnoreCase))
|
||||
if ((portName == null) ||
|
||||
!portName.StartsWith("COM", StringComparison.OrdinalIgnoreCase) ||
|
||||
!uint.TryParse(portName.Substring(3), out uint portNumber))
|
||||
{
|
||||
throw new ArgumentException(SR.Arg_InvalidSerialPort, nameof(portName));
|
||||
}
|
||||
|
||||
// Error checking done in SerialPort.
|
||||
|
||||
SafeFileHandle tempHandle = Interop.Kernel32.CreateFileDefaultSecurity(
|
||||
@"\\?\" + portName,
|
||||
Interop.Kernel32.GenericOperations.GENERIC_READ | Interop.Kernel32.GenericOperations.GENERIC_WRITE,
|
||||
0, // comm devices must be opened w/exclusive-access
|
||||
FileMode.Open, // comm devices must use OPEN_EXISTING
|
||||
flags);
|
||||
SafeFileHandle tempHandle = OpenPort(portNumber);
|
||||
|
||||
if (tempHandle.IsInvalid)
|
||||
{
|
||||
@@ -705,10 +702,7 @@ namespace System.IO.Ports
|
||||
|
||||
if (_isAsync)
|
||||
{
|
||||
if (!ThreadPool.BindHandle(_handle))
|
||||
{
|
||||
throw new IOException(SR.IO_BindHandleFailed);
|
||||
}
|
||||
_threadPoolBinding = ThreadPoolBoundHandle.BindHandle(_handle);
|
||||
}
|
||||
|
||||
// monitor all events except TXEMPTY
|
||||
@@ -725,6 +719,7 @@ namespace System.IO.Ports
|
||||
// handle before we let them continue up.
|
||||
tempHandle.Close();
|
||||
_handle = null;
|
||||
_threadPoolBinding?.Dispose();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
@@ -805,6 +800,7 @@ namespace System.IO.Ports
|
||||
{
|
||||
_handle.Close();
|
||||
_handle = null;
|
||||
_threadPoolBinding.Dispose();
|
||||
}
|
||||
#pragma warning restore CA2002
|
||||
}
|
||||
@@ -812,6 +808,7 @@ namespace System.IO.Ports
|
||||
{
|
||||
_handle.Close();
|
||||
_handle = null;
|
||||
_threadPoolBinding.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
@@ -957,7 +954,12 @@ namespace System.IO.Ports
|
||||
// Free memory, GC handles.
|
||||
NativeOverlapped* overlappedPtr = afsar._overlapped;
|
||||
if (overlappedPtr != null)
|
||||
Overlapped.Free(overlappedPtr);
|
||||
{
|
||||
// Legacy behavior as indicated by tests (e.g.: System.IO.Ports.Tests.SerialStream_EndRead.EndReadAfterClose)
|
||||
// expects to be able to call EndRead after Close/Dispose - even if disposed _threadPoolBinding can free the
|
||||
// native overlapped.
|
||||
_threadPoolBinding.FreeNativeOverlapped(overlappedPtr);
|
||||
}
|
||||
|
||||
// Check for non-timeout errors during the read.
|
||||
if (afsar._errorCode != 0)
|
||||
@@ -1016,7 +1018,12 @@ namespace System.IO.Ports
|
||||
// Free memory, GC handles.
|
||||
NativeOverlapped* overlappedPtr = afsar._overlapped;
|
||||
if (overlappedPtr != null)
|
||||
Overlapped.Free(overlappedPtr);
|
||||
{
|
||||
// Legacy behavior as indicated by tests (e.g.: System.IO.Ports.Tests.SerialStream_EndWrite.EndWriteAfterSerialStreamClose)
|
||||
// expects to be able to call EndWrite after Close/Dispose - even if disposed _threadPoolBinding can free the
|
||||
// native overlapped.
|
||||
_threadPoolBinding.FreeNativeOverlapped(overlappedPtr);
|
||||
}
|
||||
|
||||
// Now check for any error during the write.
|
||||
if (afsar._errorCode != 0)
|
||||
@@ -1396,7 +1403,6 @@ namespace System.IO.Ports
|
||||
|
||||
unsafe private SerialStreamAsyncResult BeginReadCore(byte[] array, int offset, int numBytes, AsyncCallback userCallback, Object stateObject)
|
||||
{
|
||||
|
||||
// Create and store async stream class library specific data in the
|
||||
// async result
|
||||
SerialStreamAsyncResult asyncResult = new SerialStreamAsyncResult();
|
||||
@@ -1409,20 +1415,14 @@ namespace System.IO.Ports
|
||||
ManualResetEvent waitHandle = new ManualResetEvent(false);
|
||||
asyncResult._waitHandle = waitHandle;
|
||||
|
||||
// Create a managed overlapped class
|
||||
// We will set the file offsets later
|
||||
Overlapped overlapped = new Overlapped(0, 0, IntPtr.Zero, asyncResult);
|
||||
|
||||
// Pack the Overlapped class, and store it in the async result
|
||||
NativeOverlapped* intOverlapped = overlapped.Pack(s_IOCallback, array);
|
||||
NativeOverlapped* intOverlapped = _threadPoolBinding.AllocateNativeOverlapped(s_IOCallback, asyncResult, array);
|
||||
|
||||
asyncResult._overlapped = intOverlapped;
|
||||
|
||||
// queue an async ReadFile operation and pass in a packed overlapped
|
||||
//int r = ReadFile(_handle, array, numBytes, null, intOverlapped);
|
||||
int hr = 0;
|
||||
int r = ReadFileNative(array, offset, numBytes,
|
||||
intOverlapped, out hr);
|
||||
int r = ReadFileNative(array, offset, numBytes, intOverlapped, out hr);
|
||||
|
||||
// ReadFile, the OS version, will return 0 on failure. But
|
||||
// my ReadFileNative wrapper returns -1. My wrapper will return
|
||||
@@ -1462,12 +1462,7 @@ namespace System.IO.Ports
|
||||
ManualResetEvent waitHandle = new ManualResetEvent(false);
|
||||
asyncResult._waitHandle = waitHandle;
|
||||
|
||||
// Create a managed overlapped class
|
||||
// We will set the file offsets later
|
||||
Overlapped overlapped = new Overlapped(0, 0, IntPtr.Zero, asyncResult);
|
||||
|
||||
// Pack the Overlapped class, and store it in the async result
|
||||
NativeOverlapped* intOverlapped = overlapped.Pack(s_IOCallback, array);
|
||||
NativeOverlapped* intOverlapped = _threadPoolBinding.AllocateNativeOverlapped(s_IOCallback, asyncResult, array);
|
||||
|
||||
asyncResult._overlapped = intOverlapped;
|
||||
|
||||
@@ -1603,14 +1598,11 @@ namespace System.IO.Ports
|
||||
// This is a the callback prompted when a thread completes any async I/O operation.
|
||||
unsafe private static void AsyncFSCallback(uint errorCode, uint numBytes, NativeOverlapped* pOverlapped)
|
||||
{
|
||||
// Unpack overlapped
|
||||
Overlapped overlapped = Overlapped.Unpack(pOverlapped);
|
||||
|
||||
// Extract async the result from overlapped structure
|
||||
SerialStreamAsyncResult asyncResult =
|
||||
(SerialStreamAsyncResult)overlapped.AsyncResult;
|
||||
asyncResult._numBytes = (int)numBytes;
|
||||
(SerialStreamAsyncResult)ThreadPoolBoundHandle.GetNativeOverlappedState(pOverlapped);
|
||||
|
||||
asyncResult._numBytes = (int)numBytes;
|
||||
asyncResult._errorCode = (int)errorCode;
|
||||
|
||||
// Call the user-provided callback. Note that it can and often should
|
||||
@@ -1642,6 +1634,7 @@ namespace System.IO.Ports
|
||||
private WeakReference streamWeakReference;
|
||||
internal ManualResetEvent waitCommEventWaitHandle = new ManualResetEvent(false);
|
||||
private SafeFileHandle handle = null;
|
||||
private ThreadPoolBoundHandle threadPoolBinding = null;
|
||||
private bool isAsync;
|
||||
internal bool endEventLoop;
|
||||
private int eventsOccurred;
|
||||
@@ -1658,6 +1651,7 @@ namespace System.IO.Ports
|
||||
internal unsafe EventLoopRunner(SerialStream stream)
|
||||
{
|
||||
handle = stream._handle;
|
||||
threadPoolBinding = stream._threadPoolBinding;
|
||||
streamWeakReference = new WeakReference(stream);
|
||||
|
||||
callErrorEvents = new WaitCallback(CallErrorEvents);
|
||||
@@ -1703,9 +1697,8 @@ namespace System.IO.Ports
|
||||
asyncResult._waitHandle = waitCommEventWaitHandle;
|
||||
|
||||
waitCommEventWaitHandle.Reset();
|
||||
Overlapped overlapped = new Overlapped(0, 0, waitCommEventWaitHandle.SafeWaitHandle.DangerousGetHandle(), asyncResult);
|
||||
// Pack the Overlapped class, and store it in the async result
|
||||
intOverlapped = overlapped.Pack(freeNativeOverlappedCallback, null);
|
||||
intOverlapped = threadPoolBinding.AllocateNativeOverlapped(freeNativeOverlappedCallback, asyncResult, null);
|
||||
intOverlapped->EventHandle = waitCommEventWaitHandle.SafeWaitHandle.DangerousGetHandle();
|
||||
}
|
||||
|
||||
fixed (int* eventsOccurredPtr = &eventsOccurred)
|
||||
@@ -1763,7 +1756,7 @@ namespace System.IO.Ports
|
||||
if (isAsync)
|
||||
{
|
||||
if (Interlocked.Decrement(ref asyncResult._numBytes) == 0)
|
||||
Overlapped.Free(intOverlapped);
|
||||
threadPoolBinding.FreeNativeOverlapped(intOverlapped);
|
||||
}
|
||||
} // while (!ShutdownLoop)
|
||||
|
||||
@@ -1771,21 +1764,18 @@ namespace System.IO.Ports
|
||||
{
|
||||
// the rest will be handled in Dispose()
|
||||
endEventLoop = true;
|
||||
Overlapped.Free(intOverlapped);
|
||||
threadPoolBinding.FreeNativeOverlapped(intOverlapped);
|
||||
}
|
||||
}
|
||||
|
||||
private unsafe void FreeNativeOverlappedCallback(uint errorCode, uint numBytes, NativeOverlapped* pOverlapped)
|
||||
{
|
||||
// Unpack overlapped
|
||||
Overlapped overlapped = Overlapped.Unpack(pOverlapped);
|
||||
|
||||
// Extract the async result from overlapped structure
|
||||
SerialStreamAsyncResult asyncResult =
|
||||
(SerialStreamAsyncResult)overlapped.AsyncResult;
|
||||
SerialStreamAsyncResult asyncResult =
|
||||
(SerialStreamAsyncResult)ThreadPoolBoundHandle.GetNativeOverlappedState(pOverlapped);
|
||||
|
||||
if (Interlocked.Decrement(ref asyncResult._numBytes) == 0)
|
||||
Overlapped.Free(pOverlapped);
|
||||
threadPoolBinding.FreeNativeOverlapped(pOverlapped);
|
||||
}
|
||||
|
||||
private void CallEvents(int nativeEvents)
|
||||
@@ -1804,7 +1794,7 @@ namespace System.IO.Ports
|
||||
// We don't want to throw an exception from the background thread which is un-catchable and hence tear down the process.
|
||||
// At present we don't have a first class event that we can raise for this class of fatal errors. One possibility is
|
||||
// to overload SeralErrors event to include another enum (perhaps CE_IOE) that we can use for this purpose.
|
||||
// In the absene of that, it is better to eat this error silently than tearing down the process (lesser of the evil).
|
||||
// In the absence of that, it is better to eat this error silently than tearing down the process (lesser of the evil).
|
||||
// This uncleared comm error will most likely blow up when the device is accessed by other APIs (such as Read) on the
|
||||
// main thread and hence become known. It is bit roundabout but acceptable.
|
||||
//
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO.PortsTests;
|
||||
using System.Reflection;
|
||||
@@ -28,6 +29,9 @@ namespace System.IO.Ports.Tests
|
||||
/// 3. Verify that the fAbortOnError flag is clear
|
||||
///
|
||||
/// </summary>
|
||||
// This test requires access, via reflection, to internal type SerialStream and respective methods GetDcbFlag and
|
||||
// SetDcbFlag, however, that requires either changes to the public type (increasing its size) or to the test itself.
|
||||
[ActiveIssue("https://github.com/dotnet/corefx/issues/23234", TargetFrameworkMonikers.Uap)]
|
||||
[ConditionalFact(nameof(HasOneSerialPort))]
|
||||
public void AbortOnErrorShouldBeClearedOnOpen()
|
||||
{
|
||||
|
||||
@@ -51,7 +51,6 @@ namespace System.IO.Ports.Tests
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[ConditionalFact(nameof(HasNullModem))]
|
||||
public void BreakState_true()
|
||||
{
|
||||
@@ -73,7 +72,7 @@ namespace System.IO.Ports.Tests
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[ConditionalFact(nameof(HasNullModem))]
|
||||
public void BreakState_false()
|
||||
{
|
||||
|
||||
@@ -187,8 +187,6 @@ namespace System.IO.Ports.Tests
|
||||
using (SerialPort com2 = new SerialPort(TCSupport.LocalMachineSerialInfo.SecondAvailablePortName))
|
||||
{
|
||||
ErrorEventHandler errEventHandler = new ErrorEventHandler(com1);
|
||||
byte[] frameErrorBytes = new byte[1];
|
||||
Random rndGen = new Random();
|
||||
|
||||
Debug.WriteLine("Verifying Frame event");
|
||||
com1.DataBits = 7;
|
||||
@@ -199,16 +197,10 @@ namespace System.IO.Ports.Tests
|
||||
|
||||
com1.ErrorReceived += errEventHandler.HandleEvent;
|
||||
|
||||
for (int i = 0; i < frameErrorBytes.Length; i++)
|
||||
{
|
||||
frameErrorBytes[i] = (byte)rndGen.Next(0, 256);
|
||||
}
|
||||
|
||||
//This should cause a frame error since the 8th bit is not set
|
||||
//and com1 is set to 7 data bits ao the 8th bit will +12v where
|
||||
//com1 expects the stop bit at the 8th bit to be -12v
|
||||
frameErrorBytes[0] = 0x01;
|
||||
|
||||
var frameErrorBytes = new byte[] { 0x01 };
|
||||
for (int i = 0; i < NUM_TRYS; i++)
|
||||
{
|
||||
Debug.WriteLine("Verifying Frame event try: {0}", i);
|
||||
@@ -221,7 +213,7 @@ namespace System.IO.Ports.Tests
|
||||
errEventHandler.Validate(SerialError.Frame, -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
lock (com1)
|
||||
{
|
||||
if (com1.IsOpen)
|
||||
|
||||
@@ -179,6 +179,10 @@ namespace System.IO.Ports.Tests
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(pinChangedEventHandler.SuccessfulWait, "pinChangedEventHandler did not receive resume handle event");
|
||||
Assert.True(receivedEventHandler.SuccessfulWait, "receivedEventHandler did not receive resume handle event");
|
||||
Assert.True(errorEventHandler.SuccessfulWait, "errorEventHandler did not receive resume handle event");
|
||||
|
||||
if (!pinChangedEventHandler.WaitForEvent(MAX_TIME_WAIT, 3))
|
||||
{
|
||||
Fail("Err_2288ajied Expected 3 PinChangedEvents to be fired and only {0} occurred",
|
||||
@@ -249,8 +253,8 @@ namespace System.IO.Ports.Tests
|
||||
Thread.Sleep(5000);
|
||||
|
||||
pinChangedEventHandler.ResumeHandleEvent();
|
||||
|
||||
TCSupport.WaitForTaskCompletion(task);
|
||||
Assert.True(pinChangedEventHandler.SuccessfulWait, "pinChangedEventHandler did not receive resume handle event");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,8 +292,8 @@ namespace System.IO.Ports.Tests
|
||||
Thread.Sleep(5000);
|
||||
|
||||
receivedEventHandler.ResumeHandleEvent();
|
||||
|
||||
TCSupport.WaitForTaskCompletion(task);
|
||||
Assert.True(receivedEventHandler.SuccessfulWait, "receivedEventHandler did not receive resume handle event");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -327,6 +331,7 @@ namespace System.IO.Ports.Tests
|
||||
|
||||
errorEventHandler.ResumeHandleEvent();
|
||||
TCSupport.WaitForTaskCompletion(task);
|
||||
Assert.True(errorEventHandler.SuccessfulWait, "errorEventHandler did not receive resume handle event");
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace System.IO.Ports.Tests
|
||||
public class OpenDevices : PortsTest
|
||||
{
|
||||
[Fact]
|
||||
[ActiveIssue(21156, TargetFrameworkMonikers.Uap)]
|
||||
[ActiveIssue("https://github.com/dotnet/corefx/issues/23294", TargetFrameworkMonikers.Uap)]
|
||||
public void OpenDevices01()
|
||||
{
|
||||
DosDevices dosDevices = new DosDevices();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user