Made the GT server testable.

This commit is contained in:
Greg Edwards 2014-06-09 00:13:02 -04:00
parent dd93326fe8
commit 664fe2d89e
5 changed files with 38 additions and 1 deletions

View File

@ -91,6 +91,14 @@ namespace PkmnFoundations.GlobalTerminalService
}
}
public override string Title
{
get
{
return "Generation IV Global Terminal";
}
}
private byte[] m_pad;
}

View File

@ -7,6 +7,7 @@ using System.Threading;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
using System.Net;
namespace PkmnFoundations.GlobalTerminalService
{
@ -59,6 +60,8 @@ namespace PkmnFoundations.GlobalTerminalService
{
if (m_workers.Count > 0) return;
Console.WriteLine("{0} server running on port {1} with {2} threads.", Title, ((IPEndPoint)m_listener.LocalEndpoint).Port, Threads);
m_closing = false;
m_listener.Start();
for (int x = 0; x < Threads; x++)
@ -84,6 +87,9 @@ namespace PkmnFoundations.GlobalTerminalService
private void MainLoop(object o)
{
int threadIndex = m_workers.IndexOf(Thread.CurrentThread);
Console.WriteLine("Thread {0} begins.", threadIndex);
while (!m_closing)
{
if (!m_listener.Pending())
@ -108,6 +114,8 @@ namespace PkmnFoundations.GlobalTerminalService
byte[] response = ProcessRequest(data);
s.Write(response, 0, response.Length);
}
Console.WriteLine("Thread {0} ends.", threadIndex);
m_workers.Remove(Thread.CurrentThread);
}
@ -125,5 +133,7 @@ namespace PkmnFoundations.GlobalTerminalService
}
protected abstract byte[] ProcessRequest(byte[] data);
public abstract String Title { get; }
}
}

View File

@ -6,7 +6,7 @@
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{7AB1A65F-3AD1-4356-94E7-F1A669BF4CE0}</ProjectGuid>
<OutputType>WinExe</OutputType>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>PkmnFoundations.GlobalTerminalService</RootNamespace>
<AssemblyName>GlobalTerminalService</AssemblyName>
@ -34,6 +34,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />

View File

@ -13,12 +13,18 @@ namespace PkmnFoundations.GlobalTerminalService
/// </summary>
static void Main()
{
#if DEBUG
Service1 myService = new Service1();
myService.Start();
while (true) { }
#else
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new Service1()
};
ServiceBase.Run(ServicesToRun);
#endif
}
}
}

View File

@ -16,12 +16,22 @@ namespace PkmnFoundations.GlobalTerminalService
InitializeComponent();
}
private GTServer4 m_server;
protected override void OnStart(string[] args)
{
Start();
}
public void Start()
{
m_server = new GTServer4();
m_server.BeginPolling();
}
protected override void OnStop()
{
if (m_server != null) m_server.EndPolling();
}
}
}