public void Run()
{
// Server threads
Log("Starting server threads");
Thread netThread = new Thread((threadStart) =>
{
while (Running)
{
// Do a cycle
DoNetCycle();
// Sleep
Thread.Sleep(SERVER_THREAD_SLEEP);
}
});
netThread.Name = "SOEServer::NetThread";
netThread.Start();
// Create the packet worker threads
if (WANT_PACKET_THREADING)
{
for (int i = 0; i < THREAD_POOL_SIZE; i++)
{
Thread workerThread = new Thread((workerThreadStart) =>
{
while (Running)
{
// Get a packet and handle it.
SOEPendingPacket packet;
if (IncomingPackets.TryDequeue(out packet))
{
Protocol.HandlePacket(packet.Client, packet.Packet);
}
// Sleep
Thread.Sleep(SERVER_THREAD_SLEEP);
}
});
workerThread.Name = string.Format("SOEServer::PacketWorkerThread{0}", i + 1);
workerThread.Start();
}
}
// Create the message worker threads
if (WANT_PACKET_THREADING)
{
for (int i = 0; i < THREAD_POOL_SIZE; i++)
{
Thread workerThread = new Thread((workerThreadStart) =>
{
while (Running)
{
// Get a packet and handle it.
SOEPendingMessage message;
if (IncomingMessages.TryDequeue(out message))
{
Protocol.HandleMessage(message.Client, message.Message);
}
// Sleep
Thread.Sleep(SERVER_THREAD_SLEEP);
}
});
workerThread.Name = string.Format("SOEServer::MessageWorkerThread{0}", i + 1);
workerThread.Start();
}
}
// Create the idle connection thread
ConnectionManager.StartKeepAliveThread();
// Done
Log("Started listening");
}