mirror of
https://github.com/ZuneDev/MicrosoftIris.git
synced 2026-07-27 13:13:29 -07:00
Prevent crash when connection is closed during recieve
This commit is contained in:
@@ -5,6 +5,11 @@ namespace Microsoft.Iris.Debug;
|
|||||||
|
|
||||||
public interface IDebuggerClient
|
public interface IDebuggerClient
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The URI the client is connected to.
|
||||||
|
/// </summary>
|
||||||
|
string ConnectionUri { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fired when the UIX interpreter steps forward.
|
/// Fired when the UIX interpreter steps forward.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using NetMQ;
|
using NetMQ;
|
||||||
using NetMQ.Sockets;
|
using NetMQ.Sockets;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.Serialization;
|
using System.Runtime.Serialization;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -10,14 +11,19 @@ namespace Microsoft.Iris.Debug;
|
|||||||
|
|
||||||
public class ZmqDebuggerClient : IDebuggerClient, IDisposable
|
public class ZmqDebuggerClient : IDebuggerClient, IDisposable
|
||||||
{
|
{
|
||||||
|
private List<byte[]> _frames = new(2);
|
||||||
private readonly SubscriberSocket _subSocket;
|
private readonly SubscriberSocket _subSocket;
|
||||||
private readonly IFormatter _formatter;
|
private readonly IFormatter _formatter;
|
||||||
|
|
||||||
|
public string ConnectionUri { get; }
|
||||||
|
|
||||||
public event EventHandler<InterpreterEntry> InterpreterStep;
|
public event EventHandler<InterpreterEntry> InterpreterStep;
|
||||||
public event Action<string> DispatcherStep;
|
public event Action<string> DispatcherStep;
|
||||||
|
|
||||||
public ZmqDebuggerClient(string connectionUri)
|
public ZmqDebuggerClient(string connectionUri)
|
||||||
{
|
{
|
||||||
|
ConnectionUri = connectionUri;
|
||||||
|
|
||||||
_subSocket = new();
|
_subSocket = new();
|
||||||
_subSocket.Connect(connectionUri);
|
_subSocket.Connect(connectionUri);
|
||||||
_subSocket.SubscribeToAnyTopic();
|
_subSocket.SubscribeToAnyTopic();
|
||||||
@@ -34,7 +40,10 @@ public class ZmqDebuggerClient : IDebuggerClient, IDisposable
|
|||||||
{
|
{
|
||||||
while (!_subSocket.IsDisposed)
|
while (!_subSocket.IsDisposed)
|
||||||
{
|
{
|
||||||
var type = RecieveDebuggerMessage(_subSocket, out var bytes);
|
DebuggerMessageType type;
|
||||||
|
byte[] bytes;
|
||||||
|
while (!TryRecieveDebuggerMessage(out type, out bytes))
|
||||||
|
;
|
||||||
|
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
@@ -54,11 +63,17 @@ public class ZmqDebuggerClient : IDebuggerClient, IDisposable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DebuggerMessageType RecieveDebuggerMessage(SubscriberSocket socket, out byte[] bytes)
|
private bool TryRecieveDebuggerMessage(out DebuggerMessageType type, out byte[] bytes)
|
||||||
{
|
{
|
||||||
var frames = socket.ReceiveMultipartBytes(2);
|
if (!_subSocket.IsDisposed && _subSocket.TryReceiveMultipartBytes(ref _frames, 2))
|
||||||
|
{
|
||||||
|
type = (DebuggerMessageType)BitConverter.ToInt32(_frames[0], 0);
|
||||||
|
bytes = _frames[1];
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bytes = frames[1];
|
type = default;
|
||||||
return (DebuggerMessageType)BitConverter.ToInt32(frames[0], 0);
|
bytes = null;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user