polka dot socks

fuck man
This commit is contained in:
Malloc of Kuzkycyziklistan 2017-05-04 16:09:38 -05:00
parent c45cf59dac
commit 2393f94339
4 changed files with 29 additions and 13 deletions

View file

@ -13,7 +13,7 @@ namespace CircleScape {
server.Start(); server.Start();
while(true) { while(true) {
// physics and game logic processing loop // logic processing loop
} }
} }
} }

View file

@ -23,6 +23,8 @@ namespace Kneesocks {
private TcpClient Socket; private TcpClient Socket;
private NetworkStream Stream; private NetworkStream Stream;
private string RawBuffer = "";
private List<Frame> FrameBuffer = new List<Frame>();
public bool Disconnected { get; private set; } = false; public bool Disconnected { get; private set; } = false;
public string DisconnectReason { get; private set; } = null; public string DisconnectReason { get; private set; } = null;
@ -55,6 +57,14 @@ namespace Kneesocks {
Headers = conn.Headers; Headers = conn.Headers;
} }
public byte[] Parse() {
if(!Handshaked) {
} else {
}
}
public void Disconnect(string reason = null) { public void Disconnect(string reason = null) {
Disconnect(Frame.kClosingReason.Normal, reason); Disconnect(Frame.kClosingReason.Normal, reason);
} }

View file

@ -27,41 +27,49 @@ namespace Kneesocks {
public int Tolerance { get; set; } = 0; public int Tolerance { get; set; } = 0;
private int _fullThreadCount; private int _fullThreadCount;
private bool updateFullThreadCount = true; private volatile bool updateFullThreadCount = true;
private List<ThreadContext> Threads private List<ThreadContext> Threads
= new List<ThreadContext>(); = new List<ThreadContext>();
private UInt64 InternalCounter = 0; private long InternalCounter = 0;
private Dictionary<UInt64, Connection> Connections private Dictionary<UInt64, Connection> Connections
= new Dictionary<UInt64, Connection>(); = new Dictionary<UInt64, Connection>();
public Pool() { public Pool() {
for(var i = 0; i < InitialCount; ++i) for(var i = 0; i < InitialCount; ++i)
CreateThread(); CreateThread(runWithNoClients: true);
} }
private void IndexConnection(UInt64 id, Connection connection) { private void IndexConnection(UInt64 id, Connection connection) {
lock(Connections) { lock(Connections) {
if(id == 0) if(id == 0)
id = InternalCounter++; id = (ulong)Interlocked.Increment(ref InternalCounter);
connection.Id = id; connection.Id = id;
Connections.Add(id, connection); Connections.Add(id, connection);
} }
} }
public void InvalidateConnection(UInt64 id) {
lock(Connections) {
Connections.Remove(id);
}
}
public bool AddConnection(Connection connection, UInt64 id = 0) { public bool AddConnection(Connection connection, UInt64 id = 0) {
lock(Threads) { lock(Threads) {
foreach(var thread in Threads) { foreach(var thread in Threads) {
if(thread.Stack.Count < FullThreadSize) { if(thread.Stack.Count < FullThreadSize) {
thread.Stack.AddClient(connection); thread.Stack.AddClient(connection);
IndexConnection(id, connection);
return true; return true;
} }
} }
if(MaxCount == 0 || Threads.Count < MaxCount) { if(MaxCount == 0 || Threads.Count < MaxCount) {
CreateThread(connection); CreateThread(connection);
IndexConnection(id, connection);
return true; return true;
} }
} }
@ -69,12 +77,6 @@ namespace Kneesocks {
return false; return false;
} }
public void InvalidateConnection(Connection connection) {
lock(Connections) {
}
}
public void InvalidateThread(Stack<T> stackRef) { public void InvalidateThread(Stack<T> stackRef) {
lock(Threads) { lock(Threads) {
var ctx = Threads.FirstOrDefault(x => Object.ReferenceEquals(x.Stack, stackRef)); var ctx = Threads.FirstOrDefault(x => Object.ReferenceEquals(x.Stack, stackRef));

View file

@ -53,7 +53,11 @@ namespace Kneesocks {
while(Running && (Count > 0 || RunWithNoClients)) { while(Running && (Count > 0 || RunWithNoClients)) {
for(var i = Count - 1; i >= 0 && Running; ++i) { for(var i = Count - 1; i >= 0 && Running; ++i) {
var client = Clients[i]; var client = Clients[i];
client if(client.Handshaked) {
} else {
}
} }
} }