Skip to content
This repository has been archived by the owner on Mar 19, 2019. It is now read-only.

Commit

Permalink
#283 Update naming, merge options
Browse files Browse the repository at this point in the history
  • Loading branch information
Tratcher committed Jan 3, 2017
1 parent 4c388e8 commit d7ce8d8
Show file tree
Hide file tree
Showing 32 changed files with 152 additions and 212 deletions.
10 changes: 5 additions & 5 deletions samples/HotAddSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.Configure<WebListenerOptions>(options =>
services.Configure<HttpSysOptions>(options =>
{
ListenerSettings = options.ListenerSettings;
ServerOptions = options;
});
}

public WebListenerSettings ListenerSettings { get; set; }
public HttpSysOptions ServerOptions { get; set; }

public void Configure(IApplicationBuilder app, ILoggerFactory loggerfactory)
{
loggerfactory.AddConsole(LogLevel.Information);

var addresses = ListenerSettings.UrlPrefixes;
var addresses = ServerOptions.UrlPrefixes;
addresses.Add("http://localhost:12346/pathBase/");

app.Use(async (context, next) =>
Expand Down Expand Up @@ -102,7 +102,7 @@ public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseStartup<Startup>()
.UseWebListener()
.UseHttpSys()
.Build();

host.Run();
Expand Down
12 changes: 6 additions & 6 deletions samples/SelfHostServer/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public class Startup
public void ConfigureServices(IServiceCollection services)
{
// Server options can be configured here instead of in Main.
services.Configure<WebListenerOptions>(options =>
services.Configure<HttpSysOptions>(options =>
{
options.ListenerSettings.Authentication.Schemes = AuthenticationSchemes.None;
options.ListenerSettings.Authentication.AllowAnonymous = true;
options.Authentication.Schemes = AuthenticationSchemes.None;
options.Authentication.AllowAnonymous = true;
});
}

Expand Down Expand Up @@ -49,10 +49,10 @@ public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseStartup<Startup>()
.UseWebListener(options =>
.UseHttpSys(options =>
{
options.ListenerSettings.Authentication.Schemes = AuthenticationSchemes.None;
options.ListenerSettings.Authentication.AllowAnonymous = true;
options.Authentication.Schemes = AuthenticationSchemes.None;
options.Authentication.AllowAnonymous = true;
})
.Build();

Expand Down
14 changes: 7 additions & 7 deletions src/Microsoft.AspNetCore.Server.HttpSys/AsyncAcceptContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ internal unsafe class AsyncAcceptContext : IAsyncResult, IDisposable
internal static readonly IOCompletionCallback IOCallback = new IOCompletionCallback(IOWaitCallback);

private TaskCompletionSource<RequestContext> _tcs;
private WebListener _server;
private HttpSysListener _server;
private NativeRequestContext _nativeRequestContext;

internal AsyncAcceptContext(WebListener server)
internal AsyncAcceptContext(HttpSysListener server)
{
_server = server;
_tcs = new TaskCompletionSource<RequestContext>();
Expand All @@ -40,7 +40,7 @@ private TaskCompletionSource<RequestContext> Tcs
}
}

internal WebListener Server
internal HttpSysListener Server
{
get
{
Expand All @@ -58,12 +58,12 @@ private static void IOCompleted(AsyncAcceptContext asyncResult, uint errorCode,
if (errorCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS &&
errorCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_MORE_DATA)
{
asyncResult.Tcs.TrySetException(new WebListenerException((int)errorCode));
asyncResult.Tcs.TrySetException(new HttpSysException((int)errorCode));
complete = true;
}
else
{
WebListener server = asyncResult.Server;
HttpSysListener server = asyncResult.Server;
if (errorCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
{
// at this point we have received an unmanaged HTTP_REQUEST and memoryBlob
Expand Down Expand Up @@ -106,7 +106,7 @@ private static void IOCompleted(AsyncAcceptContext asyncResult, uint errorCode,
{
// someother bad error, possible(?) return values are:
// ERROR_INVALID_HANDLE, ERROR_INSUFFICIENT_BUFFER, ERROR_OPERATION_ABORTED
asyncResult.Tcs.TrySetException(new WebListenerException((int)statusCode));
asyncResult.Tcs.TrySetException(new HttpSysException((int)statusCode));
complete = true;
}
}
Expand Down Expand Up @@ -169,7 +169,7 @@ internal uint QueueBeginGetContext()
retry = true;
}
else if (statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS
&& WebListener.SkipIOCPCallbackOnSuccess)
&& HttpSysListener.SkipIOCPCallbackOnSuccess)
{
// IO operation completed synchronously - callback won't be called to signal completion.
IOCompleted(this, statusCode, bytesTransferred);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
namespace Microsoft.AspNetCore.Server.HttpSys
{
[SuppressMessage("Microsoft.Usage", "CA2237:MarkISerializableTypesWithSerializable")]
public class WebListenerException : Win32Exception
public class HttpSysException : Win32Exception
{
internal WebListenerException()
internal HttpSysException()
: base(Marshal.GetLastWin32Error())
{
}

internal WebListenerException(int errorCode)
internal HttpSysException(int errorCode)
: base(errorCode)
{
}

internal WebListenerException(int errorCode, string message)
internal HttpSysException(int errorCode, string message)
: base(errorCode, message)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
/// <summary>
/// An HTTP server wrapping the Http.Sys APIs that accepts requests.
/// </summary>
public sealed class WebListener : IDisposable
public sealed class HttpSysListener : IDisposable
{
// Win8# 559317 fixed a bug in Http.sys's HttpReceiveClientCertificate method.
// Without this fix IOCP callbacks were not being called although ERROR_IO_PENDING was
Expand All @@ -40,16 +40,15 @@ public sealed class WebListener : IDisposable

private object _internalLock;

public WebListener()
: this(new WebListenerSettings())
public HttpSysListener(HttpSysOptions options, ILoggerFactory loggerFactory)
{
}

public WebListener(WebListenerSettings settings)
{
if (settings == null)
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
if (loggerFactory == null)
{
throw new ArgumentNullException(nameof(settings));
throw new ArgumentNullException(nameof(loggerFactory));
}

if (!HttpApi.Supported)
Expand All @@ -59,7 +58,9 @@ public WebListener(WebListenerSettings settings)

Debug.Assert(HttpApi.ApiVersion == HttpApi.HTTP_API_VERSION.Version20, "Invalid Http api version");

Settings = settings;
Options = options;

Logger = LogHelper.CreateLogger(loggerFactory, typeof(HttpSysListener));

_state = State.Stopped;
_internalLock = new object();
Expand Down Expand Up @@ -99,10 +100,7 @@ internal enum State
Disposed,
}

internal ILogger Logger
{
get { return Settings.Logger; }
}
internal ILogger Logger { get; private set; }

internal UrlGroup UrlGroup
{
Expand All @@ -119,7 +117,7 @@ internal DisconnectListener DisconnectListener
get { return _disconnectListener; }
}

public WebListenerSettings Settings { get; }
public HttpSysOptions Options { get; }

public bool IsListening
{
Expand Down Expand Up @@ -148,18 +146,18 @@ public void Start()
return;
}

Settings.Authentication.SetUrlGroupSecurity(UrlGroup);
Settings.Timeouts.SetUrlGroupTimeouts(UrlGroup);
Settings.SetRequestQueueLimit(RequestQueue);
Options.Authentication.SetUrlGroupSecurity(UrlGroup);
Options.Timeouts.SetUrlGroupTimeouts(UrlGroup);
Options.SetRequestQueueLimit(RequestQueue);

_requestQueue.AttachToUrlGroup();

// All resources are set up correctly. Now add all prefixes.
try
{
Settings.UrlPrefixes.RegisterAllPrefixes(UrlGroup);
Options.UrlPrefixes.RegisterAllPrefixes(UrlGroup);
}
catch (WebListenerException)
catch (HttpSysException)
{
// If an error occurred while adding prefixes, free all resources allocated by previous steps.
_requestQueue.DetachFromUrlGroup();
Expand Down Expand Up @@ -191,7 +189,7 @@ private void Stop()
return;
}

Settings.UrlPrefixes.UnregisterAllPrefixes();
Options.UrlPrefixes.UnregisterAllPrefixes();

_state = State.Stopped;

Expand Down Expand Up @@ -285,7 +283,7 @@ public Task<RequestContext> AcceptAsync()
// some other bad error, possible(?) return values are:
// ERROR_INVALID_HANDLE, ERROR_INSUFFICIENT_BUFFER, ERROR_OPERATION_ABORTED
asyncResult.Dispose();
throw new WebListenerException((int)statusCode);
throw new HttpSysException((int)statusCode);
}
}
catch (Exception exception)
Expand All @@ -310,10 +308,10 @@ internal unsafe bool ValidateRequest(NativeRequestContext requestMemory)

internal unsafe bool ValidateAuth(NativeRequestContext requestMemory)
{
if (!Settings.Authentication.AllowAnonymous && !requestMemory.CheckAuthenticated())
if (!Options.Authentication.AllowAnonymous && !requestMemory.CheckAuthenticated())
{
SendError(requestMemory.RequestId, StatusCodes.Status401Unauthorized,
AuthenticationManager.GenerateChallenges(Settings.Authentication.Schemes));
AuthenticationManager.GenerateChallenges(Options.Authentication.Schemes));
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,31 @@

namespace Microsoft.AspNetCore.Server.HttpSys
{
public class WebListenerSettings
public class HttpSysOptions
{
private const long DefaultRequestQueueLength = 1000; // Http.sys default.
internal static readonly int DefaultMaxAccepts = 5 * Environment.ProcessorCount;

// The native request queue
private long _requestQueueLength = DefaultRequestQueueLength;
private RequestQueue _requestQueue;
private ILogger _logger = NullLogger.Instance;

public WebListenerSettings()
public HttpSysOptions()
{
}

/// <summary>
/// The logger that will be used to create the WebListener instance. This should not be changed
/// after creating the listener.
/// The maximum number of concurrent accepts.
/// </summary>
public ILogger Logger
{
get { return _logger; }
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_logger = value;
}
}
public int MaxAccepts { get; set; } = DefaultMaxAccepts;

/// <summary>
/// Attempts kernel mode caching for responses with eligible headers. The response may not include
/// Set-Cookie, Vary, or Pragma headers. It must include a Cache-Control header with Public and
/// either a Shared-Max-Age or Max-Age value, or an Expires header.
/// </summary>
public bool EnableResponseCaching { get; set; } = true;

/// <summary>
/// The url prefixes to register with Http.Sys. These may be modified at any time prior to disposing
Expand Down

This file was deleted.

14 changes: 7 additions & 7 deletions src/Microsoft.AspNetCore.Server.HttpSys/MessagePump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
{
internal class MessagePump : IServer
{
private readonly WebListener _listener;
private readonly HttpSysListener _listener;
private readonly ILogger _logger;

private IHttpApplication<object> _application;
Expand All @@ -31,7 +31,7 @@ internal class MessagePump : IServer

private readonly ServerAddressesFeature _serverAddresses;

public MessagePump(IOptions<WebListenerOptions> options, ILoggerFactory loggerFactory)
public MessagePump(IOptions<HttpSysOptions> options, ILoggerFactory loggerFactory)
{
if (options == null)
{
Expand All @@ -43,7 +43,7 @@ public MessagePump(IOptions<WebListenerOptions> options, ILoggerFactory loggerFa
}

var optionsInstance = options.Value;
_listener = new WebListener(optionsInstance.ListenerSettings);
_listener = new HttpSysListener(optionsInstance, loggerFactory);
_logger = LogHelper.CreateLogger(loggerFactory, typeof(MessagePump));
Features = new FeatureCollection();
_serverAddresses = new ServerAddressesFeature();
Expand All @@ -55,7 +55,7 @@ public MessagePump(IOptions<WebListenerOptions> options, ILoggerFactory loggerFa
_shutdownSignal = new ManualResetEvent(false);
}

internal WebListener Listener
internal HttpSysListener Listener
{
get { return _listener; }
}
Expand All @@ -80,7 +80,7 @@ public void Start<TContext>(IHttpApplication<TContext> application)

_application = new ApplicationWrapper<TContext>(application);

if (_listener.Settings.UrlPrefixes.Count == 0)
if (_listener.Options.UrlPrefixes.Count == 0)
{
throw new InvalidOperationException("No address prefixes were defined.");
}
Expand Down Expand Up @@ -206,11 +206,11 @@ private static void SetFatalResponse(RequestContext context, int status)
context.Dispose();
}

private void ParseAddresses(ICollection<string> addresses, WebListener listener)
private void ParseAddresses(ICollection<string> addresses, HttpSysListener listener)
{
foreach (var value in addresses)
{
listener.Settings.UrlPrefixes.Add(UrlPrefix.Create(value));
listener.Options.UrlPrefixes.Add(UrlPrefix.Create(value));
}
}

Expand Down
Loading

0 comments on commit d7ce8d8

Please sign in to comment.