Changeset 372 for binary-improvements/MapRendering/Web/SSE/EventBase.cs
- Timestamp:
- Jul 27, 2022, 7:17:17 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/SSE/EventBase.cs
r367 r372 55 55 stringBuilder.Append ("data: "); 56 56 57 if (data is string dataString) { 58 stringBuilder.AppendLine (dataString); 59 } else if (data is JSONNode dataJson) { 60 dataJson.ToString (stringBuilder); 61 stringBuilder.AppendLine (""); 62 } else { 63 Log.Error ($"SSE ({Name}): Data is neither string nor JSON."); 64 continue; 57 switch (data) { 58 case string dataString: 59 stringBuilder.AppendLine (dataString); 60 break; 61 case JSONNode dataJson: 62 dataJson.ToString (stringBuilder); 63 stringBuilder.AppendLine (""); 64 break; 65 default: 66 logError ("Data is neither string nor JSON.", false); 67 continue; 65 68 } 66 69 … … 76 79 bytesToSend = Encoding.UTF8.GetBytes (output, 0, output.Length, buf, 0); 77 80 } catch (ArgumentException e) { 78 Log.Error ($"SSE ({Name}): Exception while encoding data for output, most likely exceeding buffer size:");81 logError ("Exception while encoding data for output, most likely exceeding buffer size:", false); 79 82 Log.Exception (e); 80 83 return; … … 95 98 totalClosed++; 96 99 97 Log.Out ( 98 $"SSE ({Name}): Can not write to endpoint, closing. (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed}"); 100 logError ("Can not write to endpoint, closing", true); 99 101 openStreams.RemoveAt (i); 100 102 resp.Close (); … … 107 109 108 110 if (e.InnerException is SocketException se) { 109 if (se.SocketErrorCode != SocketError.ConnectionAborted ) {110 Log.Error ($"SSE ({Name}): SocketError ({se.SocketErrorCode}) while trying to write: (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed}");111 if (se.SocketErrorCode != SocketError.ConnectionAborted && se.SocketErrorCode != SocketError.Shutdown) { 112 logError ($"SocketError ({se.SocketErrorCode}) while trying to write", true); 111 113 } 112 114 } else { 113 Log.Error ( 114 $"SSE ({Name}): IOException while trying to write: (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed}"); 115 logError ("IOException while trying to write:", true); 115 116 Log.Exception (e); 116 117 } … … 122 123 123 124 openStreams.RemoveAt (i); 124 Log.Error ( 125 $"SSE ({Name}): Exception while trying to write: (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed}"); 125 logError ("Exception while trying to write:", true); 126 126 Log.Exception (e); 127 127 resp.Close (); … … 131 131 } 132 132 133 protected void logError (string _message, bool _printConnections) { 134 Log.Error (_printConnections 135 ? $"SSE ({Name}): {_message} (Left open: {currentlyOpen}, total opened: {totalOpened}, closed: {totalClosed})" 136 : $"SSE ({Name}): {_message}"); 137 } 138 133 139 public virtual int DefaultPermissionLevel () { 134 140 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.