Skip to content

Commit 48b6f2a

Browse files
committed
fix: handle new errors for listener
1 parent b42216d commit 48b6f2a

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/SharpWebserver/Program.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,29 +137,30 @@ void ContextReceivedCallback(IAsyncResult ar)
137137
#endregion
138138

139139
}
140-
catch (SocketException ex)
140+
catch (HttpListenerException ex)
141141
{
142+
143+
Logger.LogError("The server encountered an unrecoverable error during operation", [
144+
("Stack", ex)
145+
]);
146+
142147
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) || RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))
143148
if (GlobalConfig.PortNumber < 1025)
144149
{
145150
Console.WriteLine();
146151
Console.ForegroundColor = ConsoleColor.Red;
147-
Console.WriteLine("-FATAL-");
152+
Console.WriteLine("-NOTICE-");
148153
Console.ResetColor();
149-
Console.Write(" Unable to bind ports up to 1024 on Unix family OSes without superuser escalation.\n Please run the program again but with ");
154+
Console.Write(" Unable to bind ports up to 1024 on Unix family OSes without superuser escalation.\n If this error is occurring before the server even starts up fully then please try running the program again but with ");
150155
Console.ForegroundColor = ConsoleColor.Yellow;
151156
Console.Write("sudo");
152157
Console.ResetColor();
153-
Console.Write(" or your distro's equivalent superuser or edit ");
158+
Console.Write(" or your distro's equivalent superuser\n or edit ");
154159
Console.ForegroundColor = ConsoleColor.Magenta;
155160
Console.Write("SharpConfig.toml");
156161
Console.ResetColor();
157162
Console.WriteLine(" to change the port number.\n");
158163
}
159-
160-
Logger.LogError("Unable to bind ListenServer", [
161-
("Stack", ex.StackTrace)
162-
]);
163164
}
164165
catch (Exception ex)
165166
{
@@ -168,11 +169,6 @@ void ContextReceivedCallback(IAsyncResult ar)
168169
("Stack", ex.StackTrace)
169170
]);
170171
}
171-
finally
172-
{
173-
//Stop listening for new clients.
174-
listener.Stop();
175-
}
176172

177173
#region Cleanup
178174

0 commit comments

Comments
 (0)