Changeset 402 for binary-improvements2/WebServer/src/SSE/AbsEvent.cs
- Timestamp:
- Jan 27, 2023, 7:28:00 PM (22 months ago)
- File:
-
- 1 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 {
Note:
See TracChangeset
for help on using the changeset viewer.