revert change as it is still broken in mono

This commit is contained in:
Mike Nolan 2023-03-17 08:58:08 -05:00
parent 3aa03a719c
commit 3572f7297d
3 changed files with 7 additions and 32 deletions

View File

@ -13,17 +13,6 @@ namespace Ooui
protected readonly List<Message> queuedMessages = new List<Message> (); protected readonly List<Message> queuedMessages = new List<Message> ();
protected readonly System.Threading.SemaphoreSlim slimSema=new System.Threading.SemaphoreSlim(0,1);
protected void LockQueue()
{
slimSema.Wait();
}
protected void UnlockQueue()
{
slimSema.Release();
}
protected readonly bool disposeElementAfterSession; protected readonly bool disposeElementAfterSession;
readonly Action<string, Exception> errorLogger; readonly Action<string, Exception> errorLogger;
@ -91,9 +80,9 @@ namespace Ooui
protected virtual void QueueMessage (Message message) protected virtual void QueueMessage (Message message)
{ {
LockQueue(); lock (queuedMessages) {
QueueMessageLocked (message); QueueMessageLocked (message);
UnlockQueue(); }
} }
protected void Error (string message, Exception ex) protected void Error (string message, Exception ex)

View File

@ -530,7 +530,7 @@ namespace Ooui
// Create a new session and let it handle everything from here // Create a new session and let it handle everything from here
// //
try { try {
var session = new WebSocketSession (this,element, disposeElementWhenDone, w, h, Error, serverToken); var session = new WebSocketSession (element, disposeElementWhenDone, w, h, Error, serverToken);
listenerContext.StartWebSocketConnection(session.Opened, listenerContext.StartWebSocketConnection(session.Opened,
session.Arrived, session.Arrived,
session.Closed); } session.Closed); }

View File

@ -24,11 +24,11 @@ namespace Ooui
DateTime lastTransmitTime = DateTime.MinValue; DateTime lastTransmitTime = DateTime.MinValue;
readonly TimeSpan throttleInterval = TimeSpan.FromSeconds (1.0 / UI.MaxFps); readonly TimeSpan throttleInterval = TimeSpan.FromSeconds (1.0 / UI.MaxFps);
public WebSocketSession (UI ui,Element element, bool disposeElementAfterSession, double initialWidth, double initialHeight, Action<string, Exception> errorLogger, CancellationToken serverToken) public WebSocketSession (Element element, bool disposeElementAfterSession, double initialWidth, double initialHeight, Action<string, Exception> errorLogger, CancellationToken serverToken)
: base (element, disposeElementAfterSession, initialWidth, initialHeight, errorLogger) : base (element, disposeElementAfterSession, initialWidth, initialHeight, errorLogger)
{ {
this.ui = ui;
// //
// Create a new session cancellation token that will trigger // Create a new session cancellation token that will trigger
// automatically if the server shutsdown or the session shutsdown. // automatically if the server shutsdown or the session shutsdown.
@ -92,7 +92,7 @@ namespace Ooui
// //
var messagesToSend = new List<Message> (); var messagesToSend = new List<Message> ();
LockQueue(); lock (queuedMessages) {
messagesToSend.AddRange (queuedMessages); messagesToSend.AddRange (queuedMessages);
queuedMessages.Clear (); queuedMessages.Clear ();
@ -107,21 +107,8 @@ namespace Ooui
//Console.WriteLine ("TRANSMIT " + json); //Console.WriteLine ("TRANSMIT " + json);
sendMsg?.Invoke(WebSocketMessage.Create(json)); sendMsg?.Invoke(WebSocketMessage.Create(json));
//task = webSocket.SendAsync (outputBuffer, WebSocketMessageType.Text, true, token).ConfigureAwait (false); //task = webSocket.SendAsync (outputBuffer, WebSocketMessageType.Text, true, token).ConfigureAwait (false);
UnlockQueue();
}
catch ( System.AggregateException ex)
{
if(ex.ToString().Replace(" ","").ToLower().Contains("mutexisnotowned"))
{
if(ui.Verbose)
Console.WriteLine("Mutex is not owned error, continue going");
}else{
Error ("Failed to send queued messages, aborting session", ex);
element.MessageSent -= handleElementMessageSent;
sessionCts.Cancel ();
} }
_=ex;
} }
catch (Exception ex) { catch (Exception ex) {
Error ("Failed to send queued messages, aborting session", ex); Error ("Failed to send queued messages, aborting session", ex);
@ -135,7 +122,6 @@ namespace Ooui
sendMsg = arg1; sendMsg = arg1;
Init(); Init();
} }
internal UI ui;
internal void Arrived(WebSocketMessage obj) internal void Arrived(WebSocketMessage obj)
{ {