From 3572f7297dceb065dafaa911414b2c4ab03cb554 Mon Sep 17 00:00:00 2001 From: Michael Nolan Date: Fri, 17 Mar 2023 08:58:08 -0500 Subject: [PATCH] revert change as it is still broken in mono --- Ooui/Session.cs | 15 ++------------- Ooui/UI.cs | 2 +- Ooui/WebSocketSession.cs | 22 ++++------------------ 3 files changed, 7 insertions(+), 32 deletions(-) diff --git a/Ooui/Session.cs b/Ooui/Session.cs index 5f40aed..0f7864c 100644 --- a/Ooui/Session.cs +++ b/Ooui/Session.cs @@ -13,17 +13,6 @@ namespace Ooui protected readonly List queuedMessages = new List (); - 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; readonly Action errorLogger; @@ -91,9 +80,9 @@ namespace Ooui protected virtual void QueueMessage (Message message) { - LockQueue(); + lock (queuedMessages) { QueueMessageLocked (message); - UnlockQueue(); + } } protected void Error (string message, Exception ex) diff --git a/Ooui/UI.cs b/Ooui/UI.cs index add80c6..3071a18 100644 --- a/Ooui/UI.cs +++ b/Ooui/UI.cs @@ -530,7 +530,7 @@ namespace Ooui // Create a new session and let it handle everything from here // 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, session.Arrived, session.Closed); } diff --git a/Ooui/WebSocketSession.cs b/Ooui/WebSocketSession.cs index 5837ac8..4abb22d 100644 --- a/Ooui/WebSocketSession.cs +++ b/Ooui/WebSocketSession.cs @@ -24,11 +24,11 @@ namespace Ooui DateTime lastTransmitTime = DateTime.MinValue; readonly TimeSpan throttleInterval = TimeSpan.FromSeconds (1.0 / UI.MaxFps); - public WebSocketSession (UI ui,Element element, bool disposeElementAfterSession, double initialWidth, double initialHeight, Action errorLogger, CancellationToken serverToken) + public WebSocketSession (Element element, bool disposeElementAfterSession, double initialWidth, double initialHeight, Action errorLogger, CancellationToken serverToken) : base (element, disposeElementAfterSession, initialWidth, initialHeight, errorLogger) { - this.ui = ui; + // // Create a new session cancellation token that will trigger // automatically if the server shutsdown or the session shutsdown. @@ -92,7 +92,7 @@ namespace Ooui // var messagesToSend = new List (); - LockQueue(); + lock (queuedMessages) { messagesToSend.AddRange (queuedMessages); queuedMessages.Clear (); @@ -107,21 +107,8 @@ namespace Ooui //Console.WriteLine ("TRANSMIT " + json); sendMsg?.Invoke(WebSocketMessage.Create(json)); //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) { Error ("Failed to send queued messages, aborting session", ex); @@ -135,7 +122,6 @@ namespace Ooui sendMsg = arg1; Init(); } - internal UI ui; internal void Arrived(WebSocketMessage obj) {