mirror of
https://github.com/ZuneDev/MicrosoftIris.git
synced 2026-07-27 13:13:29 -07:00
Remove OwlCore.Remoting
This commit is contained in:
+1
-22
@@ -1,44 +1,23 @@
|
||||
#if OPENZUNE
|
||||
|
||||
using OwlCore.Remoting;
|
||||
using System;
|
||||
|
||||
namespace Microsoft.Iris.Debug
|
||||
{
|
||||
[RemoteOptions(RemotingDirection.Bidirectional)]
|
||||
public class Bridge : IBridge, IDisposable
|
||||
public class Bridge : IBridge
|
||||
{
|
||||
private readonly MemberRemote _memberRemote;
|
||||
|
||||
public event EventHandler<Data.InterpreterEntry> InterpreterStep;
|
||||
public event Action<string> DispatcherStep;
|
||||
|
||||
public Bridge(RemotingMode mode)
|
||||
{
|
||||
// Pass the instance you want to remote into MemberRemote() with an ID that is identical on both machines for that instance.
|
||||
// An instance will not receive member changes until you do this.
|
||||
// Optionally leave out the message handler. Uses the default set by MemberRemote.SetDefaultMessageHandler(handler);
|
||||
TcpRemoteMessageHandler handler = new(mode);
|
||||
_memberRemote = new MemberRemote(this, typeof(Bridge).Assembly.FullName, handler);
|
||||
}
|
||||
|
||||
[RemoteMethod, RemoteOptions(RemotingDirection.HostToClient)]
|
||||
public void LogInterpreterOpCode(object context, Data.InterpreterEntry entry)
|
||||
{
|
||||
InterpreterStep?.Invoke(context, entry);
|
||||
}
|
||||
|
||||
[RemoteMethod, RemoteOptions(RemotingDirection.HostToClient)]
|
||||
public void LogDispatcher(string message)
|
||||
{
|
||||
DispatcherStep?.Invoke(message);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Dispose of the MemberRemote when finished. Forgetting to do this WILL result in a memory leak.
|
||||
_memberRemote.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Weavers>
|
||||
<Cauldron.Interception />
|
||||
</Weavers>
|
||||
@@ -1,202 +0,0 @@
|
||||
#if OPENZUNE
|
||||
|
||||
using OwlCore.Remoting;
|
||||
using OwlCore.Remoting.Transfer;
|
||||
using OwlCore.Remoting.Transfer.MessageConverters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.Iris.Debug
|
||||
{
|
||||
internal class TcpRemoteMessageHandler : IRemoteMessageHandler, IDisposable
|
||||
{
|
||||
// https://docs.microsoft.com/en-us/dotnet/framework/network-programming/asynchronous-client-socket-example
|
||||
// ManualResetEvent instances signal completion.
|
||||
private ManualResetEvent connectDone = new(false);
|
||||
private ManualResetEvent sendDone = new(false);
|
||||
private ManualResetEvent receiveDone = new(false);
|
||||
|
||||
private Socket _socket;
|
||||
|
||||
public RemotingMode Mode { get; set; }
|
||||
public MemberSignatureScope MemberSignatureScope { get; set; }
|
||||
|
||||
public IRemoteMessageConverter MessageConverter { get; }
|
||||
|
||||
public bool IsInitialized { get; private set; }
|
||||
|
||||
public string IP { get; private set; }
|
||||
|
||||
public int Port { get; private set; }
|
||||
|
||||
public event EventHandler<IRemoteMessage> MessageReceived;
|
||||
|
||||
public TcpRemoteMessageHandler(RemotingMode mode, string ip = "127.0.0.1", int port = 13000)
|
||||
{
|
||||
// The inbox newtonsoft converter. Tested with various types, structs, primitives, classes and more.
|
||||
// Provided by the lib for convenience, the underlying OwlCore.Remoting system doesn't use this property.
|
||||
MessageConverter = new NewtonsoftRemoteMessageConverter();
|
||||
|
||||
Mode = mode;
|
||||
|
||||
IP = ip;
|
||||
Port = port;
|
||||
}
|
||||
|
||||
public async Task InitAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
// Establish the remote endpoint for the socket.
|
||||
var ip = IPAddress.Parse(IP);
|
||||
|
||||
// Create a TCP/IP socket.
|
||||
_socket = new(ip.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||
|
||||
if (Mode == RemotingMode.Client)
|
||||
{
|
||||
// Connect to the remote endpoint.
|
||||
_socket.BeginConnect(ip, Port, ConnectCallback, _socket);
|
||||
}
|
||||
|
||||
Receive(_socket);
|
||||
|
||||
IsInitialized = true;
|
||||
}
|
||||
|
||||
public async Task SendMessageAsync(IRemoteMessage memberMessage, CancellationToken? cancellationToken = null)
|
||||
{
|
||||
// Serialize and send the message.
|
||||
byte[] data = await MessageConverter.SerializeAsync(memberMessage, cancellationToken);
|
||||
cancellationToken?.ThrowIfCancellationRequested();
|
||||
|
||||
// Begin sending the data to the remote device.
|
||||
_socket.BeginSend(data, 0, data.Length, 0, SendCallback, _socket);
|
||||
}
|
||||
|
||||
private void ConnectCallback(IAsyncResult result)
|
||||
{
|
||||
// Retrieve the socket from the state object.
|
||||
Socket client = (Socket)result.AsyncState;
|
||||
|
||||
// Complete the connection.
|
||||
client.EndConnect(result);
|
||||
|
||||
Console.WriteLine($"Socket connected to {client.RemoteEndPoint}");
|
||||
|
||||
// Signal that the connection has been made.
|
||||
connectDone.Set();
|
||||
}
|
||||
|
||||
private void Receive(Socket client)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Create the state object.
|
||||
StateObject state = new()
|
||||
{
|
||||
WorkSocket = client
|
||||
};
|
||||
|
||||
// Begin receiving the data from the remote device.
|
||||
client.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0, ReceiveCallback, state);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private async void ReceiveCallback(IAsyncResult ar)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve the state object and the client socket
|
||||
// from the asynchronous state object.
|
||||
StateObject state = (StateObject)ar.AsyncState;
|
||||
Socket client = state.WorkSocket;
|
||||
|
||||
// Read data from the remote device.
|
||||
int bytesRead = client.EndReceive(ar);
|
||||
|
||||
if (bytesRead > 0)
|
||||
{
|
||||
// There might be more data, so store the data received so far.
|
||||
state.Data.AddRange(state.Buffer);
|
||||
|
||||
// Get the rest of the data.
|
||||
client.BeginReceive(state.Buffer, 0, StateObject.BufferSize, 0, ReceiveCallback, state);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Signal that all bytes have been received.
|
||||
receiveDone.Set();
|
||||
|
||||
// Deserialize message.
|
||||
var msg = await MessageConverter.DeserializeAsync(state.Data.ToArray());
|
||||
MessageReceived?.Invoke(this, msg);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private void SendCallback(IAsyncResult ar)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Retrieve the socket from the state object.
|
||||
Socket client = (Socket)ar.AsyncState;
|
||||
|
||||
// Complete sending the data to the remote device.
|
||||
int bytesSent = client.EndSend(ar);
|
||||
Console.WriteLine($"Sent {bytesSent} bytes to server.");
|
||||
|
||||
// Signal that all bytes have been sent.
|
||||
sendDone.Set();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_socket?.Shutdown(SocketShutdown.Both);
|
||||
_socket?.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// State object for receiving data from remote device.
|
||||
/// </summary>
|
||||
private class StateObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Client socket.
|
||||
/// </summary>
|
||||
public Socket WorkSocket = null;
|
||||
|
||||
/// <summary>
|
||||
/// Size of receive buffer.
|
||||
/// </summary>
|
||||
public const int BufferSize = 256;
|
||||
|
||||
/// <summary>
|
||||
/// Receive buffer.
|
||||
/// </summary>
|
||||
public byte[] Buffer = new byte[BufferSize];
|
||||
|
||||
/// <summary>
|
||||
/// Total recieved data.
|
||||
/// </summary>
|
||||
public List<byte> Data = new(BufferSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
<ItemGroup Condition="$(UseOpenZune)">
|
||||
<PackageReference Include="OwlCore" Version="0.2.1" />
|
||||
<PackageReference Include="Cauldron.BasicInterceptors" Version="3.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -23,12 +23,7 @@ namespace Microsoft.Iris.Debug
|
||||
|
||||
public List<string> Breakpoints { get; } = new List<string>();
|
||||
|
||||
public Bridge Bridge { get; } =
|
||||
#if OPENZUNE
|
||||
new(OwlCore.Remoting.RemotingMode.None);
|
||||
#else
|
||||
new();
|
||||
#endif
|
||||
public Bridge Bridge { get; } = new();
|
||||
}
|
||||
|
||||
public class DecompilationResult
|
||||
|
||||
Reference in New Issue
Block a user