Fixed some bad memory leaks on sockets
This commit is contained in:
@@ -58,7 +58,7 @@ namespace Framework.Networking
|
||||
if (_newSockets.Empty())
|
||||
return;
|
||||
|
||||
foreach (var socket in _newSockets)
|
||||
foreach (var socket in _newSockets.ToArray())
|
||||
{
|
||||
if (!socket.IsOpen())
|
||||
{
|
||||
|
||||
@@ -31,7 +31,10 @@ namespace Framework.Networking
|
||||
_receiveBuffer = new byte[ushort.MaxValue];
|
||||
}
|
||||
|
||||
public virtual void Dispose() { }
|
||||
public virtual void Dispose()
|
||||
{
|
||||
_receiveBuffer = null;
|
||||
}
|
||||
|
||||
public abstract void Start();
|
||||
|
||||
@@ -57,10 +60,9 @@ namespace Framework.Networking
|
||||
|
||||
try
|
||||
{
|
||||
var socketEventargs = new SocketAsyncEventArgs();
|
||||
|
||||
using (var socketEventargs = new SocketAsyncEventArgs())
|
||||
{
|
||||
socketEventargs.SetBuffer(_receiveBuffer, 0, _receiveBuffer.Length);
|
||||
|
||||
socketEventargs.Completed += (sender, args) => ReadHandlerInternal(args);
|
||||
socketEventargs.SocketFlags = SocketFlags.None;
|
||||
socketEventargs.RemoteEndPoint = _socket.RemoteEndPoint;
|
||||
@@ -68,6 +70,7 @@ namespace Framework.Networking
|
||||
if (!_socket.ReceiveAsync(socketEventargs))
|
||||
ReadHandlerInternal(socketEventargs);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.outException(ex);
|
||||
@@ -82,16 +85,16 @@ namespace Framework.Networking
|
||||
|
||||
try
|
||||
{
|
||||
var socketEventargs = new SocketAsyncEventArgs();
|
||||
|
||||
using (var socketEventargs = new SocketAsyncEventArgs())
|
||||
{
|
||||
socketEventargs.SetBuffer(_receiveBuffer, 0, _receiveBuffer.Length);
|
||||
|
||||
socketEventargs.Completed += (sender, args) => callback(args);
|
||||
socketEventargs.UserToken = _socket;
|
||||
socketEventargs.SocketFlags = SocketFlags.None;
|
||||
if (!_socket.ReceiveAsync(socketEventargs))
|
||||
callback(socketEventargs);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.outException(ex);
|
||||
@@ -122,7 +125,8 @@ namespace Framework.Networking
|
||||
if (!IsOpen())
|
||||
return;
|
||||
|
||||
var socketEventargs = new SocketAsyncEventArgs();
|
||||
using (var socketEventargs = new SocketAsyncEventArgs())
|
||||
{
|
||||
socketEventargs.SetBuffer(data, 0, data.Length);
|
||||
socketEventargs.Completed += WriteHandlerInternal;
|
||||
socketEventargs.RemoteEndPoint = _socket.RemoteEndPoint;
|
||||
@@ -131,6 +135,7 @@ namespace Framework.Networking
|
||||
|
||||
_socket.SendAsync(socketEventargs);
|
||||
}
|
||||
}
|
||||
|
||||
void WriteHandlerInternal(object sender, SocketAsyncEventArgs args)
|
||||
{
|
||||
@@ -158,7 +163,7 @@ namespace Framework.Networking
|
||||
_socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, enable);
|
||||
}
|
||||
|
||||
public virtual void OnClose() { }
|
||||
public virtual void OnClose() { Dispose(); }
|
||||
|
||||
public bool IsOpen() { return !_closed; }
|
||||
|
||||
|
||||
@@ -29,12 +29,12 @@ namespace Game.Network
|
||||
{
|
||||
public class WorldSocket : SocketBase
|
||||
{
|
||||
string ClientConnectionInitialize = "WORLD OF WARCRAFT CONNECTION - CLIENT TO SERVER";
|
||||
string ServerConnectionInitialize = "WORLD OF WARCRAFT CONNECTION - SERVER TO CLIENT";
|
||||
static string ClientConnectionInitialize = "WORLD OF WARCRAFT CONNECTION - CLIENT TO SERVER";
|
||||
static string ServerConnectionInitialize = "WORLD OF WARCRAFT CONNECTION - SERVER TO CLIENT";
|
||||
|
||||
byte[] AuthCheckSeed = { 0xC5, 0xC6, 0x98, 0x95, 0x76, 0x3F, 0x1D, 0xCD, 0xB6, 0xA1, 0x37, 0x28, 0xB3, 0x12, 0xFF, 0x8A };
|
||||
byte[] SessionKeySeed = { 0x58, 0xCB, 0xCF, 0x40, 0xFE, 0x2E, 0xCE, 0xA6, 0x5A, 0x90, 0xB8, 0x01, 0x68, 0x6C, 0x28, 0x0B };
|
||||
byte[] ContinuedSessionSeed = { 0x16, 0xAD, 0x0C, 0xD4, 0x46, 0xF9, 0x4F, 0xB2, 0xEF, 0x7D, 0xEA, 0x2A, 0x17, 0x66, 0x4D, 0x2F };
|
||||
static byte[] AuthCheckSeed = { 0xC5, 0xC6, 0x98, 0x95, 0x76, 0x3F, 0x1D, 0xCD, 0xB6, 0xA1, 0x37, 0x28, 0xB3, 0x12, 0xFF, 0x8A };
|
||||
static byte[] SessionKeySeed = { 0x58, 0xCB, 0xCF, 0x40, 0xFE, 0x2E, 0xCE, 0xA6, 0x5A, 0x90, 0xB8, 0x01, 0x68, 0x6C, 0x28, 0x0B };
|
||||
static byte[] ContinuedSessionSeed = { 0x16, 0xAD, 0x0C, 0xD4, 0x46, 0xF9, 0x4F, 0xB2, 0xEF, 0x7D, 0xEA, 0x2A, 0x17, 0x66, 0x4D, 0x2F };
|
||||
|
||||
public WorldSocket(Socket socket) : base(socket)
|
||||
{
|
||||
@@ -43,6 +43,20 @@ namespace Game.Network
|
||||
worldCrypt = new WorldCrypt();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
_worldSession = null;
|
||||
_queryProcessor = null;
|
||||
_serverChallenge = null;
|
||||
worldCrypt = null;
|
||||
_encryptSeed = null;
|
||||
_decryptSeed = null;
|
||||
_sessionKey = null;
|
||||
_compressionStream = null;
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
string ip_address = GetRemoteIpAddress().ToString();
|
||||
@@ -317,11 +331,6 @@ namespace Game.Network
|
||||
return compressedSize;
|
||||
}
|
||||
|
||||
public override void OnClose()
|
||||
{
|
||||
_worldSession = null;
|
||||
}
|
||||
|
||||
public override bool Update()
|
||||
{
|
||||
if (!base.Update())
|
||||
|
||||
Reference in New Issue
Block a user