mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Don't forget to call EndSend to release cached async stuff
This commit is contained in:
parent
cb5310736d
commit
52dc099198
@ -33,12 +33,12 @@ namespace MCGalaxy.Network {
|
||||
get { return ((IPEndPoint)socket.RemoteEndPoint).Address.ToString(); }
|
||||
}
|
||||
|
||||
static AsyncCallback recvCallback = new AsyncCallback(Receive);
|
||||
static AsyncCallback recvCallback = new AsyncCallback(ReceiveCallback);
|
||||
public void ReceiveNextAsync() {
|
||||
socket.BeginReceive(tempbuffer, 0, tempbuffer.Length, SocketFlags.None, recvCallback, this);
|
||||
}
|
||||
|
||||
static void Receive(IAsyncResult result) {
|
||||
static void ReceiveCallback(IAsyncResult result) {
|
||||
TcpSocket s = (TcpSocket)result.AsyncState;
|
||||
Player p = s.player;
|
||||
if (p.disconnected) return;
|
||||
@ -73,6 +73,8 @@ namespace MCGalaxy.Network {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static AsyncCallback sendCallback = new AsyncCallback(SendCallback);
|
||||
public void Send(byte[] buffer, bool sync = false) {
|
||||
// Abort if socket has been closed
|
||||
if (player.disconnected || !socket.Connected) return;
|
||||
@ -81,7 +83,7 @@ namespace MCGalaxy.Network {
|
||||
if (sync)
|
||||
socket.Send(buffer, 0, buffer.Length, SocketFlags.None);
|
||||
else
|
||||
socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, delegate(IAsyncResult result) { }, null);
|
||||
socket.BeginSend(buffer, 0, buffer.Length, SocketFlags.None, sendCallback, this);
|
||||
buffer = null;
|
||||
} catch (SocketException e) {
|
||||
buffer = null;
|
||||
@ -95,6 +97,22 @@ namespace MCGalaxy.Network {
|
||||
}
|
||||
}
|
||||
|
||||
static void SendCallback(IAsyncResult result) {
|
||||
TcpSocket s = (TcpSocket)result.AsyncState;
|
||||
|
||||
try {
|
||||
int sent = s.socket.EndSend(result);
|
||||
} catch (SocketException e) {
|
||||
s.player.Disconnect();
|
||||
#if DEBUG
|
||||
Server.ErrorLog(e);
|
||||
#endif
|
||||
} catch (ObjectDisposedException) {
|
||||
// socket was already closed by another thread.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void Close() {
|
||||
// Try to close the socket.
|
||||
// Sometimes its already closed so these lines will cause an error
|
||||
|
@ -243,12 +243,6 @@ namespace MCGalaxy {
|
||||
return GroupList.Find(grp => (int)grp.Permission == Perm);
|
||||
}
|
||||
|
||||
|
||||
/// <summary> Get the group name that player /playerName/ is in </summary>
|
||||
/// <param name="name">The player Name</param>
|
||||
/// <returns>The group name</returns>
|
||||
public static string findPlayer(string name) { return findPlayerGroup(name).name; }
|
||||
|
||||
/// <summary> Find the group object that the player /playerName/ is in </summary>
|
||||
/// <param name="name">The player name</param>
|
||||
/// <returns>The group object that the player is in</returns>
|
||||
|
@ -59,7 +59,7 @@ namespace MCGalaxy {
|
||||
} if (perm > 119 || perm < -50) {
|
||||
Server.s.Log("Permission must be between -50 and 119 for ranks");
|
||||
grp = null;
|
||||
} else if (Group.GroupList.Find(g => g.Permission == (LevelPermission)perm) == null) {
|
||||
} else if (Group.findPermInt(perm) == null) {
|
||||
grp.Permission = (LevelPermission)perm;
|
||||
} else {
|
||||
Server.s.Log("Cannot have 2 ranks set at permission level " + value);
|
||||
|
Loading…
x
Reference in New Issue
Block a user