Skip to content

Commit a4d0e1b

Browse files
committed
show runtime warning on OSC node. https://forum.vvvv.org/t/binding-bug/24507/2 it is a bit weird, that after changing the port and IP and back again you can have three working OSC nodes with the same configuration, but only after going through those steps. #7265
1 parent c294037 commit a4d0e1b

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

VL.CoreLib/src/IO/Socket/DatagramReceiver.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
using System;
1+
using Microsoft.Extensions.Logging;
2+
using System;
23
using System.Net;
34
using System.Net.Sockets;
5+
using System.Reactive.Disposables;
46
using System.Reactive.Subjects;
57
using System.Threading;
68
using System.Threading.Tasks;
79
using VL.Core;
810
using VL.Core.Import;
11+
using VL.Lang;
912
using VL.Lib.Basics.Resources;
1013
using VL.Lib.Collections;
1114
using VL.Lib.IO.Socket;
@@ -28,6 +31,17 @@ public class DatagramReceiver : IDisposable
2831
IResourceProvider<NetSocket> FLocalSocketProvider;
2932
Task FCurrentTask;
3033

34+
private readonly NodeContext FNodeContext;
35+
private readonly ILogger FLogger;
36+
private readonly IVLRuntime FRuntime;
37+
38+
public DatagramReceiver(NodeContext nodeContext)
39+
{
40+
FRuntime = IVLRuntime.Current;
41+
FNodeContext = nodeContext;
42+
FLogger = nodeContext.GetLogger();
43+
}
44+
3145
/// <summary>
3246
/// The observable sequence of datagrams. The datagrams will be pushed on the network thread.
3347
/// </summary>
@@ -88,8 +102,9 @@ void Start(IResourceProvider<NetSocket> provider)
88102
}
89103
}
90104
}
91-
catch (Exception)
105+
catch (Exception e)
92106
{
107+
Warn($"Error receiving datagram: {e.Message}");
93108
if (!token.IsCancellationRequested)
94109
// Try again
95110
await Task.Delay(100);
@@ -110,5 +125,22 @@ void IDisposable.Dispose()
110125
{
111126
Stop(1);
112127
}
128+
129+
private void Warn(string message)
130+
{
131+
ResourceProvider.NewPooledSystemWide(FNodeContext.Path,
132+
_ =>
133+
{
134+
var messages = new CompositeDisposable();
135+
foreach (var id in FNodeContext.Path.Stack)
136+
{
137+
FRuntime.AddPersistentMessage(new Message(id, MessageSeverity.Warning, message))
138+
.DisposeBy(messages);
139+
}
140+
return messages;
141+
}, delayDisposalInMilliseconds: 1000)
142+
.GetHandle()
143+
.Dispose(); // messages will stick for some seconds
144+
}
113145
}
114146
}

0 commit comments

Comments
 (0)