Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,9 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\LocalDb\LocalDbApi.Windows.cs">
<Link>Microsoft\Data\SqlClient\LocalDb\LocalDbApi.Windows.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\PacketHandle.netcore.Windows.cs">
<Link>Microsoft\Data\SqlClient\PacketHandle.netcore.Windows.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SqlColumnEncryptionCngProvider.Windows.cs">
<Link>Microsoft\Data\SqlClient\SqlColumnEncryptionCngProvider.Windows.cs</Link>
</Compile>
Expand All @@ -867,7 +870,6 @@
<Link>Microsoft\Data\SqlTypes\SqlFileStream.Windows.cs</Link>
</Compile>

<Compile Include="Microsoft\Data\SqlClient\PacketHandle.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\SessionHandle.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\LocalDB.Windows.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParser.Windows.cs" />
Expand All @@ -886,9 +888,11 @@
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\LocalDb\LocalDbApi.Unix.cs">
<Link>Microsoft\Data\SqlClient\LocalDb\LocalDbApi.Unix.cs</Link>
</Compile>
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\PacketHandle.netcore.Unix.cs">
<Link>Microsoft\Data\SqlClient\PacketHandle.netcore.Unix.cs</Link>
</Compile>

<Compile Include="Microsoft\Data\Sql\SqlDataSourceEnumerator.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\PacketHandle.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\SessionHandle.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\SNI\LocalDB.Unix.cs" />
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionCertificateStoreProvider.Unix.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
// 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;
#if NET

namespace Microsoft.Data.SqlClient
{
// this structure is used for transporting packet handle references between the TdsParserStateObject
// base class and Managed or Native implementations.
// It prevents the native IntPtr type from being boxed and prevents the need to cast from object which loses compile time type safety
// It carries type information so that assertions about the type of handle can be made in the implemented abstract methods
// it is a ref struct so that it can only be used to transport the handles and not store them
// This structure is used for transporting packet handle references between the
// TdsParserStateObject base class and Managed or Native implementations.
// It prevents the native IntPtr type from being boxed and prevents the need to cast from
// object which loses compile time type safety.
// It carries type information so that assertions about the type of handle can be made in the
// implemented abstract methods.
// It is a ref struct so that it can only be used to transport the handles and not store them

// N.B. If you change this type you must also change the version for the other platform

Expand All @@ -29,6 +31,9 @@ private PacketHandle(SNI.SNIPacket managedPacket, int type)
ManagedPacket = managedPacket;
}

public static PacketHandle FromManagedPacket(SNI.SNIPacket managedPacket) => new PacketHandle(managedPacket, ManagedPacketType);
public static PacketHandle FromManagedPacket(SNI.SNIPacket managedPacket) =>
new PacketHandle(managedPacket, ManagedPacketType);
}
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#if NET

using System;

namespace Microsoft.Data.SqlClient
{
// this structure is used for transporting packet handle references between the TdsParserStateObject
// base class and Managed or Native implementations.
// It prevents the native IntPtr type from being boxed and prevents the need to cast from object which loses compile time type safety
// It carries type information so that assertions about the type of handle can be made in the implemented abstract methods
// it is a ref struct so that it can only be used to transport the handles and not store them
// This structure is used for transporting packet handle references between the
// TdsParserStateObject base class and Managed or Native implementations.
// It prevents the native IntPtr type from being boxed and prevents the need to cast from
// object which loses compile time type safety.
// It carries type information so that assertions about the type of handle can be made in the
// implemented abstract methods.
// It is a ref struct so that it can only be used to transport the handles and not store them

// N.B. If you change this type you must also change the version for the other platform

Expand All @@ -20,10 +24,9 @@ internal readonly ref struct PacketHandle
public const int NativePacketType = 2;
public const int ManagedPacketType = 3;

public readonly IntPtr NativePointer;
public readonly SNIPacket NativePacket;

public readonly SNI.SNIPacket ManagedPacket;
public readonly SNIPacket NativePacket;
public readonly IntPtr NativePointer;
public readonly int Type;

private PacketHandle(IntPtr nativePointer, SNIPacket nativePacket, SNI.SNIPacket managedPacket, int type)
Expand All @@ -34,12 +37,17 @@ private PacketHandle(IntPtr nativePointer, SNIPacket nativePacket, SNI.SNIPacket
NativePacket = nativePacket;
}

public static PacketHandle FromManagedPacket(SNI.SNIPacket managedPacket) => new PacketHandle(default, default, managedPacket, ManagedPacketType);
public static PacketHandle FromManagedPacket(SNI.SNIPacket managedPacket) =>
new PacketHandle(default, default, managedPacket, ManagedPacketType);

public static PacketHandle FromNativePointer(IntPtr nativePointer) => new PacketHandle(nativePointer, default, default, NativePointerType);
public static PacketHandle FromNativePointer(IntPtr nativePointer) =>
new PacketHandle(nativePointer, default, default, NativePointerType);

public static PacketHandle FromNativePacket(SNIPacket nativePacket) => new PacketHandle(default, nativePacket, default, NativePacketType);
public static PacketHandle FromNativePacket(SNIPacket nativePacket) =>
new PacketHandle(default, nativePacket, default, NativePacketType);


}
}
}

#endif
Loading