mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-23 12:42:22 -04:00
Quick fix for stack overflow
This commit is contained in:
parent
610332863d
commit
cc2f97161c
@ -52,6 +52,7 @@ namespace MCGalaxy.Network {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public bool LowLatency { set { socket.NoDelay = value; } }
|
public bool LowLatency { set { socket.NoDelay = value; } }
|
||||||
|
bool Connected { get { return !player.disconnected && socket.Connected; } }
|
||||||
|
|
||||||
|
|
||||||
static EventHandler<SocketAsyncEventArgs> recvCallback = RecvCallback;
|
static EventHandler<SocketAsyncEventArgs> recvCallback = RecvCallback;
|
||||||
@ -63,7 +64,7 @@ namespace MCGalaxy.Network {
|
|||||||
static void RecvCallback(object sender, SocketAsyncEventArgs e) {
|
static void RecvCallback(object sender, SocketAsyncEventArgs e) {
|
||||||
TcpSocket s = (TcpSocket)e.UserToken;
|
TcpSocket s = (TcpSocket)e.UserToken;
|
||||||
Player p = s.player;
|
Player p = s.player;
|
||||||
if (p.disconnected) return;
|
if (!s.Connected) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
int recvLen = e.BytesTransferred;
|
int recvLen = e.BytesTransferred;
|
||||||
@ -102,8 +103,7 @@ namespace MCGalaxy.Network {
|
|||||||
|
|
||||||
static EventHandler<SocketAsyncEventArgs> sendCallback = SendCallback;
|
static EventHandler<SocketAsyncEventArgs> sendCallback = SendCallback;
|
||||||
public void Send(byte[] buffer, bool sync = false) {
|
public void Send(byte[] buffer, bool sync = false) {
|
||||||
// Abort if socket has been closed
|
if (!Connected) return;
|
||||||
if (player.disconnected || !socket.Connected) return;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (sync) {
|
if (sync) {
|
||||||
@ -148,8 +148,12 @@ namespace MCGalaxy.Network {
|
|||||||
int sent = e.BytesTransferred;
|
int sent = e.BytesTransferred;
|
||||||
lock (s.sendLock) {
|
lock (s.sendLock) {
|
||||||
s.sendInProgress = false;
|
s.sendInProgress = false;
|
||||||
if (s.sendQueue.Count > 0) {
|
if (s.sendQueue.Count == 0) return;
|
||||||
|
|
||||||
|
if (s.Connected) {
|
||||||
s.DoSendAsync(s.sendQueue.Dequeue());
|
s.DoSendAsync(s.sendQueue.Dequeue());
|
||||||
|
} else {
|
||||||
|
s.sendQueue.Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SocketException) {
|
} catch (SocketException) {
|
||||||
@ -164,6 +168,7 @@ namespace MCGalaxy.Network {
|
|||||||
// Try to close the socket. Sometimes socket is already closed, so just hide this.
|
// Try to close the socket. Sometimes socket is already closed, so just hide this.
|
||||||
try { socket.Shutdown(SocketShutdown.Both); } catch { }
|
try { socket.Shutdown(SocketShutdown.Both); } catch { }
|
||||||
try { socket.Close(); } catch { }
|
try { socket.Close(); } catch { }
|
||||||
|
|
||||||
lock (sendLock) { sendQueue.Clear(); }
|
lock (sendLock) { sendQueue.Clear(); }
|
||||||
try { recvArgs.Dispose(); } catch { }
|
try { recvArgs.Dispose(); } catch { }
|
||||||
try { sendArgs.Dispose(); } catch { }
|
try { sendArgs.Dispose(); } catch { }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user