Changeset 402 for binary-improvements2/WebServer/src/SSE
- Timestamp:
- Jan 27, 2023, 7:28:00 PM (22 months ago)
- Location:
- binary-improvements2/WebServer/src/SSE
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements2/WebServer/src/SSE/AbsEvent.cs
r399 r402 4 4 using System.Net.Sockets; 5 5 using System.Text; 6 using AllocsFixes.JSON;7 6 using Webserver.UrlHandlers; 8 7 using HttpListenerResponse = SpaceWizards.HttpListener.HttpListenerResponse; … … 20 19 private readonly List<HttpListenerResponse> openStreams = new List<HttpListenerResponse> (); 21 20 22 private readonly BlockingQueue<(string _eventName, object_data)> sendQueue =23 new BlockingQueue<(string _eventName, object_data)> ();21 private readonly BlockingQueue<(string _eventName, string _data)> sendQueue = 22 new BlockingQueue<(string _eventName, string _data)> (); 24 23 25 24 private int currentlyOpen; … … 42 41 } 43 42 44 protected void SendData (string _eventName, object_data) {43 protected void SendData (string _eventName, string _data) { 45 44 sendQueue.Enqueue ((_eventName, _data)); 46 45 Parent.SignalSendQueue (); 47 46 } 48 47 49 50 48 public void ProcessSendQueue () { 51 49 while (sendQueue.HasData ()) { 52 (string eventName, objectdata) = sendQueue.Dequeue ();50 (string eventName, string data) = sendQueue.Dequeue (); 53 51 54 52 stringBuilder.Append ("event: "); 55 53 stringBuilder.AppendLine (eventName); 56 54 stringBuilder.Append ("data: "); 57 58 switch (data) { 59 case string dataString: 60 stringBuilder.AppendLine (dataString); 61 break; 62 case JsonNode dataJson: 63 dataJson.ToString (stringBuilder); 64 stringBuilder.AppendLine (""); 65 break; 66 default: 67 logError ("Data is neither string nor JSON.", false); 68 continue; 69 } 55 stringBuilder.AppendLine (data); 70 56 71 57 stringBuilder.AppendLine (""); 58 72 59 string output = stringBuilder.ToString (); 73 60 stringBuilder.Clear (); … … 111 98 if (e.InnerException is SocketException se) { 112 99 if (se.SocketErrorCode != SocketError.ConnectionAborted && se.SocketErrorCode != SocketError.Shutdown) { 113 logError ($"SocketError ({se.SocketErrorCode }) while trying to write", true);100 logError ($"SocketError ({se.SocketErrorCode.ToStringCached ()}) while trying to write", true); 114 101 } 115 102 } else { -
binary-improvements2/WebServer/src/SSE/EventLog.cs
r391 r402 1 1 using System; 2 using AllocsFixes.JSON;3 2 using JetBrains.Annotations; 4 3 using UnityEngine; 4 using Utf8Json; 5 5 using Webserver.UrlHandlers; 6 6 … … 12 12 } 13 13 14 private static readonly byte[] jsonMsgKey = JsonWriter.GetEncodedPropertyNameWithBeginObject ("msg"); 15 private static readonly byte[] jsonTypeKey = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("type"); 16 private static readonly byte[] jsonTraceKey = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("trace"); 17 private static readonly byte[] jsonIsotimeKey = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("isotime"); 18 private static readonly byte[] jsonUptimeKey = JsonWriter.GetEncodedPropertyNameWithPrefixValueSeparator ("uptime"); 19 14 20 private void LogCallback (string _formattedMsg, string _plainMsg, string _trace, LogType _type, DateTime _timestamp, long _uptime) { 15 21 string isotime = _timestamp.ToString ("o"); 16 22 string uptime = _uptime.ToString (); 17 23 18 JsonObject data = new JsonObject (); 19 data.Add ("msg", new JsonString (_plainMsg)); 20 data.Add ("type", new JsonString (_type.ToStringCached ())); 21 data.Add ("trace", new JsonString (_trace)); 22 data.Add ("isotime", new JsonString (isotime)); 23 data.Add ("uptime", new JsonString (uptime)); 24 25 SendData ("logLine", data); 24 JsonWriter writer = new JsonWriter (); 25 26 writer.WriteRaw (jsonMsgKey); 27 writer.WriteString (_plainMsg); 28 29 writer.WriteRaw (jsonTypeKey); 30 writer.WriteString (_type.ToStringCached ()); 31 32 writer.WriteRaw (jsonTraceKey); 33 writer.WriteString (_trace); 34 35 writer.WriteRaw (jsonIsotimeKey); 36 writer.WriteString (isotime); 37 38 writer.WriteRaw (jsonUptimeKey); 39 writer.WriteString (uptime); 40 41 writer.WriteEndObject (); 42 43 SendData ("logLine", writer.ToString ()); 26 44 } 27 45 }
Note:
See TracChangeset
for help on using the changeset viewer.