mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
Fixed the session dispose
Fixed the session dispose
This commit is contained in:
@@ -125,12 +125,14 @@ namespace TEngine.Core.Network
|
|||||||
NetworkThread.Instance?.RemoveChannel(networkId, channelId);
|
NetworkThread.Instance?.RemoveChannel(networkId, channelId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.NetworkId = 0;
|
||||||
|
this.ChannelId = 0;
|
||||||
|
base.Dispose();
|
||||||
Sessions.Remove(id);
|
Sessions.Remove(id);
|
||||||
#if NETDEBUG
|
#if NETDEBUG
|
||||||
Log.Debug($"Sessions Dispose Count:{Sessions.Count}");
|
Log.Debug($"Sessions Dispose Count:{Sessions.Count}");
|
||||||
#endif
|
#endif
|
||||||
base.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Send(object message, uint rpcId = 0, long routeId = 0)
|
public virtual void Send(object message, uint rpcId = 0, long routeId = 0)
|
||||||
|
@@ -7,20 +7,20 @@ namespace TEngine.Core.Network;
|
|||||||
public sealed class AddressableRouteComponent : Entity
|
public sealed class AddressableRouteComponent : Entity
|
||||||
{
|
{
|
||||||
private long _routeId;
|
private long _routeId;
|
||||||
private long _addressableId;
|
public long AddressableId { get; private set; }
|
||||||
|
|
||||||
public static readonly CoroutineLockQueueType AddressableRouteMessageLock = new CoroutineLockQueueType("AddressableRouteMessageLock");
|
public static readonly CoroutineLockQueueType AddressableRouteMessageLock = new CoroutineLockQueueType("AddressableRouteMessageLock");
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
_routeId = 0;
|
_routeId = 0;
|
||||||
_addressableId = 0;
|
this.AddressableId = 0;
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetAddressableId(long addressableId)
|
public void SetAddressableId(long addressableId)
|
||||||
{
|
{
|
||||||
_addressableId = addressableId;
|
this.AddressableId = addressableId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Send(IAddressableRouteMessage message)
|
public void Send(IAddressableRouteMessage message)
|
||||||
@@ -44,13 +44,13 @@ public sealed class AddressableRouteComponent : Entity
|
|||||||
var runtimeId = RuntimeId;
|
var runtimeId = RuntimeId;
|
||||||
IResponse iRouteResponse = null;
|
IResponse iRouteResponse = null;
|
||||||
|
|
||||||
using (await AddressableRouteMessageLock.Lock(_addressableId, "AddressableRouteComponent Call MemoryStream"))
|
using (await AddressableRouteMessageLock.Lock(this.AddressableId, "AddressableRouteComponent Call MemoryStream"))
|
||||||
{
|
{
|
||||||
while (!IsDisposed)
|
while (!IsDisposed)
|
||||||
{
|
{
|
||||||
if (_routeId == 0)
|
if (_routeId == 0)
|
||||||
{
|
{
|
||||||
_routeId = await AddressableHelper.GetAddressableRouteId(Scene, _addressableId);
|
_routeId = await AddressableHelper.GetAddressableRouteId(Scene, this.AddressableId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_routeId == 0)
|
if (_routeId == 0)
|
||||||
@@ -110,13 +110,13 @@ public sealed class AddressableRouteComponent : Entity
|
|||||||
var failCount = 0;
|
var failCount = 0;
|
||||||
var runtimeId = RuntimeId;
|
var runtimeId = RuntimeId;
|
||||||
|
|
||||||
using (await AddressableRouteMessageLock.Lock(_addressableId,"AddressableRouteComponent Call"))
|
using (await AddressableRouteMessageLock.Lock(this.AddressableId,"AddressableRouteComponent Call"))
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
if (_routeId == 0)
|
if (_routeId == 0)
|
||||||
{
|
{
|
||||||
_routeId = await AddressableHelper.GetAddressableRouteId(Scene, _addressableId);
|
_routeId = await AddressableHelper.GetAddressableRouteId(Scene, this.AddressableId);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_routeId == 0)
|
if (_routeId == 0)
|
||||||
|
@@ -6,31 +6,31 @@ namespace TEngine.Core.Network;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public sealed class RouteComponent : Entity
|
public sealed class RouteComponent : Entity
|
||||||
{
|
{
|
||||||
private readonly Dictionary<long, long> _routeAddress = new Dictionary<long, long>();
|
public readonly Dictionary<long, long> RouteAddress = new Dictionary<long, long>();
|
||||||
|
|
||||||
public void AddAddress(long routeType, long routeId)
|
public void AddAddress(long routeType, long routeId)
|
||||||
{
|
{
|
||||||
_routeAddress.Add(routeType, routeId);
|
this.RouteAddress.Add(routeType, routeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveAddress(long routeType)
|
public void RemoveAddress(long routeType)
|
||||||
{
|
{
|
||||||
_routeAddress.Remove(routeType);
|
this.RouteAddress.Remove(routeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long GetRouteId(long routeType)
|
public long GetRouteId(long routeType)
|
||||||
{
|
{
|
||||||
return _routeAddress.TryGetValue(routeType, out var routeId) ? routeId : 0;
|
return this.RouteAddress.TryGetValue(routeType, out var routeId) ? routeId : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool TryGetRouteId(long routeType, out long routeId)
|
public bool TryGetRouteId(long routeType, out long routeId)
|
||||||
{
|
{
|
||||||
return _routeAddress.TryGetValue(routeType, out routeId);
|
return this.RouteAddress.TryGetValue(routeType, out routeId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Dispose()
|
public override void Dispose()
|
||||||
{
|
{
|
||||||
_routeAddress.Clear();
|
this.RouteAddress.Clear();
|
||||||
base.Dispose();
|
base.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user