fuck websocketsharp

time to die
This commit is contained in:
Malloc of Kuzkycyziklistan 2017-04-21 16:04:03 -05:00
parent ce6ad8d567
commit 91c4ce5360
9 changed files with 152 additions and 36 deletions

View file

@ -56,8 +56,12 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Server.cs" />
<Compile Include="Entrypoint.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Websocket\Connection.cs" />
<Compile Include="Websocket\Pool.cs" />
<Compile Include="Websocket\Server.cs" />
<Compile Include="Websocket\Stack.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />

13
server/Entrypoint.cs Normal file
View file

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CircleScape {
class Entrypoint {
static void Main(string[] args) {
}
}
}

View file

@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebSocketSharp;
using WebSocketSharp.Server;
namespace CircleScape {
class Connection : WebSocketBehavior {
Connection() {
}
protected override void OnOpen() {
if()
}
protected override void OnMessage(MessageEventArgs e) {
}
protected override void OnClose(CloseEventArgs e) {
}
}
class Server {
static void Main(string[] args) {
}
}
}

View file

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CircleScape.Websocket {
class Connection {
}
}

63
server/Websocket/Pool.cs Normal file
View file

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace CircleScape.Websocket {
class Pool {
private const int InitialCount = 3;
private const int InitialSize = 3;
private const int SizeGrowth = 1;
private const int MaxSize = 10;
private int _fullThreadCount;
private bool updateFullThreadCount = true;
private List<ThreadContext> Threads
= new List<ThreadContext>();
private Dictionary<UInt64, Connection> Connections
= new Dictionary<UInt64, Connection>();
public Pool() {
for(var i = 0; i < InitialCount; ++i) {
}
}
public bool AddConnection(Connection connection) {
foreach(var thread in Threads) {
}
}
private ThreadContext CreateThread(Connection initialConnection = null) {
var stack = new Stack(true);
var ctx = new ThreadContext {
Stack = stack,
Thread = new Thread(new ThreadStart(stack.ManageStack))
};
Threads.Add(ctx);
return ctx;
}
private int FullThreadCount {
get {
if(updateFullThreadCount) {
_fullThreadCount = Math.Min(
MaxSize,
InitialSize + SizeGrowth * (Threads.Count - InitialCount)
);
}
return _fullThreadCount;
}
}
class ThreadContext {
public Thread Thread { get; set; }
public Stack Stack { get; set; }
}
}
}

View file

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CircleScape.Websocket {
class Server {
}
}

48
server/Websocket/Stack.cs Normal file
View file

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace CircleScape.Websocket {
class Stack {
private List<Connection> Clients = new List<Connection>();
private Mutex ClientsMutex = new Mutex();
private bool RunWithNoClients = false;
public Stack(Connection initialConnection = null) {
if(initialConnection != null)
Clients.Add(initialConnection);
}
public Stack(bool runWithNoClients, Connection initialConnection = null)
: this(initialConnection)
{
RunWithNoClients = runWithNoClients;
}
public bool AddClient(Connection client) {
if(!ClientsMutex.WaitOne(5000))
return false;
Clients.Add(client);
ClientsMutex.ReleaseMutex();
return true;
}
public int ClientCount {
get {
return Clients.Count;
}
}
// USED FOR THREADING -- DO NOT CALL
public void ManageStack() {
int clientCount = ClientCount;
for(var i = 0; i < clientCount; ++i)
}
}
}

View file

@ -5,5 +5,4 @@
<package id="System.Data.SQLite.Core" version="1.0.105.0" targetFramework="net452" />
<package id="System.Data.SQLite.EF6" version="1.0.105.0" targetFramework="net452" />
<package id="System.Data.SQLite.Linq" version="1.0.105.0" targetFramework="net452" />
<package id="WebSocketSharp" version="1.0.3-rc11" targetFramework="net452" />
</packages>

View file

@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "server", "server.csproj", "{438DBAC1-BA37-40BB-9CCE-0FE1F23C6DC5}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CircleScape", "CircleScape.csproj", "{438DBAC1-BA37-40BB-9CCE-0FE1F23C6DC5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution