Skip to content

Commit

Permalink
Review fixes.
Browse files Browse the repository at this point in the history
Return old frameworks. Marked everything related to `UnixDomainSocketEndPoint` with `#if NET8_0_OR_GREATER` pragma.
  • Loading branch information
ArtManyak committed Jan 7, 2025
1 parent 285592c commit fcef20c
Show file tree
Hide file tree
Showing 16 changed files with 197 additions and 158 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net35;net472;net8.0;</TargetFrameworks>
<AssemblyName>JetBrains.RdFramework.Reflection</AssemblyName>
<RootNamespace>JetBrains.Rd.Reflection</RootNamespace>

Expand Down
3 changes: 1 addition & 2 deletions rd-net/RdFramework.Reflection/ReflectionRdActivator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ private object ActivateRd(Type type)
object instance;
try
{
instance = Activator.CreateInstance(implementingType)
?? throw new InvalidOperationException($"Unable to create instance of: {implementingType.ToString(true)}");
instance = Activator.CreateInstance(implementingType)!;
}
catch (MissingMethodException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ bool IsValidArray()
if (!typeInfo.IsArray) return false;
if (typeInfo.GetArrayRank() != 1) return false;

var elementType = typeInfo.GetElementType();
if (elementType == null) return false;

var arrayType = elementType.GetTypeInfo();
var arrayType = typeInfo.GetElementType()!.GetTypeInfo();
return IsFieldType(arrayType, false);
}

Expand Down
7 changes: 4 additions & 3 deletions rd-net/RdFramework.Reflection/SerializerReflectionUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ internal static FieldInfo[] GetBindableFields(TypeInfo typeInfo)
return list.ToArray();
}

private static IEnumerable<FieldInfo> GetFields(Type? type, Type baseType)
private static IEnumerable<FieldInfo> GetFields(Type type, Type baseType)
{
foreach (var field in type?.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) ?? Array.Empty<FieldInfo>())
foreach (var field in type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public))
yield return field;

// private fields only being returned for the current type
while ((type = type?.BaseType) != baseType && type != null)
while (type.BaseType != baseType && type.BaseType != null)
{
type = type.BaseType;
// but protected fields are returned in first step
foreach (var baseField in type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic))
if (baseField.IsPrivate)
Expand Down
11 changes: 9 additions & 2 deletions rd-net/RdFramework/Impl/EndPointWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public static EndPointWrapper CreateIpEndPoint(IPAddress? address = null, int? p
};
}

public static EndPointWrapper CreateUnixEndPoint(string? path = null)
#if NET8_0_OR_GREATER
public static EndPointWrapper CreateUnixEndPoint(UnixSocketConnectionParams connectionParams)
{
var path1 = path ?? Path.GetTempFileName();
var path1 = connectionParams.Path ?? Path.GetTempFileName();
return new EndPointWrapper(new UnixDomainSocketEndPoint(path1)) {
AddressFamily = AddressFamily.Unix,
SocketType = SocketType.Stream,
Expand All @@ -46,4 +47,10 @@ public static EndPointWrapper CreateUnixEndPoint(string? path = null)
LocalPath = path1,
};
}

public struct UnixSocketConnectionParams
{
public string? Path { get; set; }
}
#endif
}
23 changes: 17 additions & 6 deletions rd-net/RdFramework/Impl/SocketWire.cs
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,10 @@ public class Client : Base
public Client(Lifetime lifetime, IScheduler scheduler, int port, string? optId = null) :
this(lifetime, scheduler, EndPointWrapper.CreateIpEndPoint(IPAddress.Loopback, port), optId) {}

public Client(Lifetime lifetime, IScheduler scheduler, string path, string? optId = null) :
this(lifetime, scheduler, EndPointWrapper.CreateUnixEndPoint(path), optId) {}
#if NET8_0_OR_GREATER
public Client(Lifetime lifetime, IScheduler scheduler, EndPointWrapper.UnixSocketConnectionParams connectionParams, string? optId = null) :
this(lifetime, scheduler, EndPointWrapper.CreateUnixEndPoint(connectionParams), optId) {}
#endif

public Client(Lifetime lifetime, IScheduler scheduler, EndPointWrapper endPointWrapper, string? optId = null) :
base("ClientSocket-"+(optId ?? "<noname>"), lifetime, scheduler)
Expand Down Expand Up @@ -646,7 +648,7 @@ private Server(Lifetime lifetime, IScheduler scheduler, string? optId = null) :
public static Socket CreateServerSocket(EndPointWrapper? endPointWrapper)
{
Protocol.InitLogger.Verbose("Creating server socket on endpoint: {0}", endPointWrapper?.EndPointImpl);
// by default we will use IPEndpoint?
// by default we will use IPEndpoint
endPointWrapper ??= EndPointWrapper.CreateIpEndPoint(IPAddress.Loopback, 0);

var serverSocket = new Socket(endPointWrapper.AddressFamily, endPointWrapper.SocketType, endPointWrapper.ProtocolType);
Expand All @@ -673,14 +675,22 @@ private void StartServerSocket(Lifetime lifetime, Socket serverSocket)

var thread = new Thread(() =>
{
#if NET8_0_OR_GREATER
Log.Catch(async () =>
#else
Log.Catch(() =>
#endif
{
while (lifetime.IsAlive)
{
try
{
Log.Verbose("{0} : accepting, port: {1}", Id, Port);
#if NET8_0_OR_GREATER
var s = await serverSocket.AcceptAsync(lifetime);
#else
var s = serverSocket.Accept();
#endif
lock (Lock)
{
if (!lifetime.IsAlive)
Expand Down Expand Up @@ -751,13 +761,12 @@ public void Deconstruct(out IScheduler scheduler, out string? id)
}
}




public class ServerFactory
{
[PublicAPI] public readonly int? LocalPort;
#if NET8_0_OR_GREATER
[PublicAPI] public readonly string? LocalPath;
#endif
[PublicAPI] public readonly IViewableSet<Server> Connected = new ViewableSet<Server>();


Expand All @@ -779,7 +788,9 @@ public ServerFactory(
Base.CloseSocket(serverSocket);
});
LocalPort = (serverSocket.LocalEndPoint as IPEndPoint)?.Port;
#if NET8_0_OR_GREATER
LocalPath = endpointWrapper?.EndPointImpl is UnixDomainSocketEndPoint ? endpointWrapper.LocalPath : null;
#endif

void Rec()
{
Expand Down
2 changes: 1 addition & 1 deletion rd-net/RdFramework/RdFramework.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net35;net472;net8.0</TargetFrameworks>
<AssemblyName>JetBrains.RdFramework</AssemblyName>
<RootNamespace>JetBrains.Rd</RootNamespace>

Expand Down
5 changes: 4 additions & 1 deletion rd-net/RdFramework/Tasks/RdFault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ protected RdFault(SerializationInfo info, StreamingContext context) : base(info,
ReasonMessage = info.GetString(nameof(ReasonMessage));
}

// [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
#if NET8_0_OR_GREATER
[Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId = "SYSLIB0051", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
#else
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
#endif
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(nameof(ReasonTypeFqn), ReasonTypeFqn);
Expand Down
2 changes: 1 addition & 1 deletion rd-net/Test.Cross/Test.Cross.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>netcoreapp3.1;net8.0</TargetFrameworks>
<RootNamespace>Test.RdCross</RootNamespace>
<Configurations>CrossTests</Configurations>
<Platforms>AnyCPU</Platforms>
Expand Down
Loading

0 comments on commit fcef20c

Please sign in to comment.