From 7a3e1ba385e0e16769531d146d7f9e3abe680928 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Thu, 15 Aug 2019 15:10:20 +1000 Subject: [PATCH] fix sending stop working after a while with .NET core --- MCGalaxy/Database/Backends/SQLite.cs | 2 +- MCGalaxy/Network/Sockets.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/MCGalaxy/Database/Backends/SQLite.cs b/MCGalaxy/Database/Backends/SQLite.cs index 03ca3c312..9a7ceebca 100644 --- a/MCGalaxy/Database/Backends/SQLite.cs +++ b/MCGalaxy/Database/Backends/SQLite.cs @@ -786,7 +786,7 @@ namespace MCGalaxy.SQL { } public float GetFloat(int i) { return (float)GetDouble(i); } - public short GetInt16(int i) { return (short)GetInt16(i); } + public short GetInt16(int i) { return (short)GetInt32(i); } public string GetName(int i) { return stmt.ColumnName(i); } public int GetInt32(int i) { diff --git a/MCGalaxy/Network/Sockets.cs b/MCGalaxy/Network/Sockets.cs index 906c83e98..7dcead7c8 100644 --- a/MCGalaxy/Network/Sockets.cs +++ b/MCGalaxy/Network/Sockets.cs @@ -177,7 +177,7 @@ namespace MCGalaxy.Network { if (sendInProgress) { sendQueue.Enqueue(buffer); } else { - if (!DoSendAsync(buffer)) sendInProgress = false; + sendInProgress = TrySendAsync(buffer); } } } catch (SocketException) { @@ -190,8 +190,7 @@ namespace MCGalaxy.Network { // TODO: do this seprately public override void SendLowPriority(byte[] buffer) { Send(buffer, false); } - bool DoSendAsync(byte[] buffer) { - sendInProgress = true; + bool TrySendAsync(byte[] buffer) { // BlockCopy has some overhead, not worth it for very small data if (buffer.Length <= 16) { for (int i = 0; i < buffer.Length; i++) { @@ -217,8 +216,9 @@ namespace MCGalaxy.Network { while (s.sendQueue.Count > 0) { // DoSendAsync returns false if SendAsync completed sync // If that happens, SendCallback isn't called so we need to send data here instead - if (s.DoSendAsync(s.sendQueue.Dequeue())) return; - + s.sendInProgress = s.TrySendAsync(s.sendQueue.Dequeue()); + + if (s.sendInProgress) return; if (s.Disconnected) s.sendQueue.Clear(); } }