fix sending stop working after a while with .NET core

This commit is contained in:
UnknownShadow200 2019-08-15 15:10:20 +10:00
parent 51ac5a1576
commit 7a3e1ba385
2 changed files with 6 additions and 6 deletions

View File

@ -786,7 +786,7 @@ namespace MCGalaxy.SQL {
} }
public float GetFloat(int i) { return (float)GetDouble(i); } 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 string GetName(int i) { return stmt.ColumnName(i); }
public int GetInt32(int i) { public int GetInt32(int i) {

View File

@ -177,7 +177,7 @@ namespace MCGalaxy.Network {
if (sendInProgress) { if (sendInProgress) {
sendQueue.Enqueue(buffer); sendQueue.Enqueue(buffer);
} else { } else {
if (!DoSendAsync(buffer)) sendInProgress = false; sendInProgress = TrySendAsync(buffer);
} }
} }
} catch (SocketException) { } catch (SocketException) {
@ -190,8 +190,7 @@ namespace MCGalaxy.Network {
// TODO: do this seprately // TODO: do this seprately
public override void SendLowPriority(byte[] buffer) { Send(buffer, false); } public override void SendLowPriority(byte[] buffer) { Send(buffer, false); }
bool DoSendAsync(byte[] buffer) { bool TrySendAsync(byte[] buffer) {
sendInProgress = true;
// BlockCopy has some overhead, not worth it for very small data // BlockCopy has some overhead, not worth it for very small data
if (buffer.Length <= 16) { if (buffer.Length <= 16) {
for (int i = 0; i < buffer.Length; i++) { for (int i = 0; i < buffer.Length; i++) {
@ -217,8 +216,9 @@ namespace MCGalaxy.Network {
while (s.sendQueue.Count > 0) { while (s.sendQueue.Count > 0) {
// DoSendAsync returns false if SendAsync completed sync // DoSendAsync returns false if SendAsync completed sync
// If that happens, SendCallback isn't called so we need to send data here instead // 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(); if (s.Disconnected) s.sendQueue.Clear();
} }
} }