Skip to content

Commit 4757ad6

Browse files
committed
Improvements to how handle aborted connections
1 parent cba73b8 commit 4757ad6

File tree

6 files changed

+25
-3
lines changed

6 files changed

+25
-3
lines changed

Unosquare.Labs.EmbedIO.Command/Options.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ internal class Options
1818
[OptionList('a', "api", Separator = ',', HelpText = "Specify assemblies to load, separated by a comma.")]
1919
public IList<string> ApiAssemblies { get; set; }
2020

21+
[Option('v', "noverb", HelpText = "Output Web server info.", DefaultValue = false)]
22+
public bool NoVerbose { get; set; }
23+
2124
[HelpOption]
2225
public string GetUsage()
2326
{

Unosquare.Labs.EmbedIO.Command/Program.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ private static void Main(string[] args)
2424

2525
Console.WriteLine(" Command-Line Utility: Press any key to stop the server.");
2626

27-
using (var server = WebServer.CreateWithConsole("http://localhost:" + options.Port + "/"))
27+
var serverUrl = "http://localhost:" + options.Port + "/";
28+
using (
29+
var server = options.NoVerbose
30+
? WebServer.Create(serverUrl)
31+
: WebServer.CreateWithConsole(serverUrl))
2832
{
2933
if (Properties.Settings.Default.UseLocalSessionModule)
3034
server.WithLocalSession();

Unosquare.Labs.EmbedIO.Tests/StaticFilesModuleTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,4 +254,4 @@ public void Kill()
254254
WebServer.Dispose();
255255
}
256256
}
257-
}
257+
}

Unosquare.Labs.EmbedIO.Tests/TestObjects/TestHelper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
public static class TestHelper
88
{
9+
public static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;
10+
911
public const string BigDataFile = "bigdata.bin";
1012

1113
public const string SmallDataFile = "smalldata.bin";

Unosquare.Labs.EmbedIO.Tests/WebSocketsModuleTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public void Init()
2424
[Test]
2525
public async void TestConnectWebSocket()
2626
{
27+
if (TestHelper.IsMono)
28+
{
29+
Assert.Inconclusive("Mono doesn't have support to WebSockets");
30+
}
31+
2732
Assert.IsNotNull(WebServer.Module<WebSocketsModule>(), "WebServer has WebSocketsModule");
2833

2934
Assert.AreEqual(WebServer.Module<WebSocketsModule>().Handlers.Count, 1, "WebSocketModule has one handler");

Unosquare.Labs.EmbedIO/Modules/StaticFilesModule.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,15 @@ private bool HandleGet(HttpListenerContext context, WebServer server, bool sendB
329329
}
330330

331331
context.Response.ContentLength64 = size;
332-
context.Response.OutputStream.Write(buffer, lrange, (int) size);
332+
333+
try
334+
{
335+
context.Response.OutputStream.Write(buffer, lrange, (int) size);
336+
}
337+
catch (HttpListenerException)
338+
{
339+
// Connection error, nothing else to do
340+
}
333341
}
334342
else
335343
{

0 commit comments

Comments
 (0)