Skip to content

Commit

Permalink
Improvements to how handle aborted connections
Browse files Browse the repository at this point in the history
  • Loading branch information
geoperez committed Sep 3, 2015
1 parent cba73b8 commit 4757ad6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Unosquare.Labs.EmbedIO.Command/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ internal class Options
[OptionList('a', "api", Separator = ',', HelpText = "Specify assemblies to load, separated by a comma.")]
public IList<string> ApiAssemblies { get; set; }

[Option('v', "noverb", HelpText = "Output Web server info.", DefaultValue = false)]
public bool NoVerbose { get; set; }

[HelpOption]
public string GetUsage()
{
Expand Down
6 changes: 5 additions & 1 deletion Unosquare.Labs.EmbedIO.Command/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ private static void Main(string[] args)

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

using (var server = WebServer.CreateWithConsole("http://localhost:" + options.Port + "/"))
var serverUrl = "http://localhost:" + options.Port + "/";
using (
var server = options.NoVerbose
? WebServer.Create(serverUrl)
: WebServer.CreateWithConsole(serverUrl))
{
if (Properties.Settings.Default.UseLocalSessionModule)
server.WithLocalSession();
Expand Down
2 changes: 1 addition & 1 deletion Unosquare.Labs.EmbedIO.Tests/StaticFilesModuleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,4 @@ public void Kill()
WebServer.Dispose();
}
}
}
}
2 changes: 2 additions & 0 deletions Unosquare.Labs.EmbedIO.Tests/TestObjects/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

public static class TestHelper
{
public static readonly bool IsMono = Type.GetType("Mono.Runtime") != null;

public const string BigDataFile = "bigdata.bin";

public const string SmallDataFile = "smalldata.bin";
Expand Down
5 changes: 5 additions & 0 deletions Unosquare.Labs.EmbedIO.Tests/WebSocketsModuleTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public void Init()
[Test]
public async void TestConnectWebSocket()
{
if (TestHelper.IsMono)
{
Assert.Inconclusive("Mono doesn't have support to WebSockets");
}

Assert.IsNotNull(WebServer.Module<WebSocketsModule>(), "WebServer has WebSocketsModule");

Assert.AreEqual(WebServer.Module<WebSocketsModule>().Handlers.Count, 1, "WebSocketModule has one handler");
Expand Down
10 changes: 9 additions & 1 deletion Unosquare.Labs.EmbedIO/Modules/StaticFilesModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,15 @@ private bool HandleGet(HttpListenerContext context, WebServer server, bool sendB
}

context.Response.ContentLength64 = size;
context.Response.OutputStream.Write(buffer, lrange, (int) size);

try
{
context.Response.OutputStream.Write(buffer, lrange, (int) size);
}
catch (HttpListenerException)
{
// Connection error, nothing else to do
}
}
else
{
Expand Down

0 comments on commit 4757ad6

Please sign in to comment.