Renamed ServiceManager.cs to ServiceHostManager.cs

This commit is contained in:
sta
2013-01-28 19:42:47 +09:00
parent 95382924e0
commit a171b05740
40 changed files with 64 additions and 80 deletions

View File

@@ -4,7 +4,7 @@
*
* The MIT License
*
* Copyright (c) 2012 sta.blockhead
* Copyright (c) 2012-2013 sta.blockhead
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -40,12 +40,12 @@ namespace WebSocketSharp.Server {
#region Fields
private Thread _acceptRequestThread;
private bool _isWindows;
private HttpListener _listener;
private int _port;
private string _rootPath;
private ServiceManager _services;
private Thread _acceptRequestThread;
private bool _isWindows;
private HttpListener _listener;
private int _port;
private string _rootPath;
private ServiceHostManager _svcHosts;
#endregion
@@ -70,19 +70,19 @@ namespace WebSocketSharp.Server {
get { return _port; }
}
public IEnumerable<string> ServicePath {
public IEnumerable<string> ServicePaths {
get {
return _services.Path;
return _svcHosts.Paths;
}
}
public bool Sweeped {
get {
return _services.Sweeped;
return _svcHosts.Sweeped;
}
set {
_services.Sweeped = value;
_svcHosts.Sweeped = value;
}
}
@@ -136,7 +136,7 @@ namespace WebSocketSharp.Server {
{
_isWindows = false;
_listener = new HttpListener();
_services = new ServiceManager();
_svcHosts = new ServiceHostManager();
var os = Environment.OSVersion;
if (os.Platform != PlatformID.Unix && os.Platform != PlatformID.MacOSX)
@@ -278,7 +278,7 @@ namespace WebSocketSharp.Server {
var path = wsContext.Path.UrlDecode();
IServiceHost svcHost;
if (!_services.TryGetServiceHost(path, out svcHost))
if (!_svcHosts.TryGetServiceHost(path, out svcHost))
{
res.StatusCode = (int)HttpStatusCode.NotImplemented;
return false;
@@ -307,7 +307,7 @@ namespace WebSocketSharp.Server {
if (!Sweeped)
svcHost.Sweeped = Sweeped;
_services.Add(absPath, svcHost);
_svcHosts.Add(absPath, svcHost);
}
public byte[] GetFile(string path)
@@ -332,7 +332,7 @@ namespace WebSocketSharp.Server {
{
_listener.Close();
_acceptRequestThread.Join(5 * 1000);
_services.Stop();
_svcHosts.Stop();
}
#endregion

View File

@@ -1,10 +1,10 @@
#region MIT License
/*
* ServiceManager.cs
* ServiceHostManager.cs
*
* The MIT License
*
* Copyright (c) 2012 sta.blockhead
* Copyright (c) 2012-2013 sta.blockhead
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -31,20 +31,20 @@ using System.Collections.Generic;
namespace WebSocketSharp.Server {
public class ServiceManager {
internal class ServiceHostManager {
#region Field
#region Fields
private Dictionary<string, IServiceHost> _services;
private Dictionary<string, IServiceHost> _svcHosts;
private bool _sweeped;
#endregion
#region Constructor
public ServiceManager()
public ServiceHostManager()
{
_services = new Dictionary<string, IServiceHost>();
_svcHosts = new Dictionary<string, IServiceHost>();
_sweeped = true;
}
@@ -54,10 +54,22 @@ namespace WebSocketSharp.Server {
public int Count {
get {
return _services.Count;
return _svcHosts.Count;
}
}
public IEnumerable<string> Paths {
get {
return _svcHosts.Keys;
}
}
public IEnumerable<IServiceHost> ServiceHosts {
get {
return _svcHosts.Values;
}
}
public bool Sweeped {
get {
return _sweeped;
@@ -67,49 +79,38 @@ namespace WebSocketSharp.Server {
if (_sweeped ^ value)
{
_sweeped = value;
foreach (var svcHost in _services.Values)
foreach (var svcHost in _svcHosts.Values)
svcHost.Sweeped = value;
}
}
}
public IEnumerable<string> Path {
get {
return _services.Keys;
}
}
public IEnumerable<IServiceHost> ServiceHost {
get {
return _services.Values;
}
}
#endregion
#region Public Methods
public void Add(string absPath, IServiceHost svcHost)
{
_services.Add(absPath.UrlDecode(), svcHost);
_svcHosts.Add(absPath.UrlDecode(), svcHost);
}
public void Broadcast(string data)
{
foreach (var svcHost in _services.Values)
foreach (var svcHost in _svcHosts.Values)
svcHost.Broadcast(data);
}
public void Stop()
{
foreach (var svcHost in _services.Values)
foreach (var svcHost in _svcHosts.Values)
svcHost.Stop();
_services.Clear();
_svcHosts.Clear();
}
public bool TryGetServiceHost(string absPath, out IServiceHost svcHost)
{
return _services.TryGetValue(absPath, out svcHost);
return _svcHosts.TryGetValue(absPath, out svcHost);
}
#endregion

View File

@@ -46,7 +46,7 @@ namespace WebSocketSharp.Server {
{
#region Field
private ServiceManager _services;
private ServiceHostManager _svcHosts;
#endregion
@@ -155,7 +155,7 @@ namespace WebSocketSharp.Server {
var url = BaseUri.IsAbsoluteUri
? BaseUri.ToString().TrimEnd('/')
: String.Empty;
foreach (var path in _services.Path)
foreach (var path in _svcHosts.Paths)
yield return url + path;
}
}
@@ -168,11 +168,11 @@ namespace WebSocketSharp.Server {
/// </value>
public bool Sweeped {
get {
return _services.Sweeped;
return _svcHosts.Sweeped;
}
set {
_services.Sweeped = value;
_svcHosts.Sweeped = value;
}
}
@@ -182,7 +182,7 @@ namespace WebSocketSharp.Server {
private void init()
{
_services = new ServiceManager();
_svcHosts = new ServiceHostManager();
}
#endregion
@@ -201,7 +201,7 @@ namespace WebSocketSharp.Server {
var path = context.Path.UrlDecode();
IServiceHost svcHost;
if (!_services.TryGetServiceHost(path, out svcHost))
if (!_svcHosts.TryGetServiceHost(path, out svcHost))
{
socket.Close(HttpStatusCode.NotImplemented);
return;
@@ -243,7 +243,7 @@ namespace WebSocketSharp.Server {
if (!Sweeped)
svcHost.Sweeped = Sweeped;
_services.Add(absPath, svcHost);
_svcHosts.Add(absPath, svcHost);
}
/// <summary>
@@ -254,7 +254,7 @@ namespace WebSocketSharp.Server {
/// </param>
public void Broadcast(string data)
{
_services.Broadcast(data);
_svcHosts.Broadcast(data);
}
/// <summary>
@@ -263,7 +263,7 @@ namespace WebSocketSharp.Server {
public override void Stop()
{
base.Stop();
_services.Stop();
_svcHosts.Stop();
}
#endregion