2019-01-18 20:26:39 -02:00
|
|
|
using Ryujinx.HLE.HOS.Kernel.Common;
|
|
|
|
using Ryujinx.HLE.HOS.Kernel.Process;
|
2018-03-19 15:58:46 -03:00
|
|
|
|
2018-12-18 03:33:36 -02:00
|
|
|
namespace Ryujinx.HLE.HOS.Kernel.Ipc
|
2018-03-19 15:58:46 -03:00
|
|
|
{
|
2020-12-01 20:23:43 -03:00
|
|
|
class KSession : KAutoObject
|
2018-03-19 15:58:46 -03:00
|
|
|
{
|
2019-01-18 20:26:39 -02:00
|
|
|
public KServerSession ServerSession { get; }
|
|
|
|
public KClientSession ClientSession { get; }
|
2018-03-19 15:58:46 -03:00
|
|
|
|
2019-01-18 20:26:39 -02:00
|
|
|
private bool _hasBeenInitialized;
|
2018-04-06 02:38:59 -03:00
|
|
|
|
2020-07-17 01:19:07 -03:00
|
|
|
public KSession(KernelContext context, KClientPort parentPort = null) : base(context)
|
2018-03-19 15:58:46 -03:00
|
|
|
{
|
2020-12-09 19:20:05 -03:00
|
|
|
IncrementReferenceCount();
|
|
|
|
|
2020-05-04 00:41:29 -03:00
|
|
|
ServerSession = new KServerSession(context, this);
|
2020-07-17 01:19:07 -03:00
|
|
|
ClientSession = new KClientSession(context, this, parentPort);
|
2019-01-18 20:26:39 -02:00
|
|
|
|
|
|
|
_hasBeenInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DisconnectClient()
|
|
|
|
{
|
|
|
|
if (ClientSession.State == ChannelState.Open)
|
|
|
|
{
|
|
|
|
ClientSession.State = ChannelState.ClientDisconnected;
|
|
|
|
|
|
|
|
ServerSession.CancelAllRequestsClientDisconnected();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DisconnectServer()
|
|
|
|
{
|
|
|
|
if (ClientSession.State == ChannelState.Open)
|
|
|
|
{
|
|
|
|
ClientSession.State = ChannelState.ServerDisconnected;
|
|
|
|
}
|
2018-03-19 15:58:46 -03:00
|
|
|
}
|
|
|
|
|
2019-01-18 20:26:39 -02:00
|
|
|
protected override void Destroy()
|
|
|
|
{
|
|
|
|
if (_hasBeenInitialized)
|
|
|
|
{
|
2020-07-17 01:19:07 -03:00
|
|
|
ClientSession.DisconnectFromPort();
|
|
|
|
|
2019-01-18 20:26:39 -02:00
|
|
|
KProcess creatorProcess = ClientSession.CreatorProcess;
|
|
|
|
|
|
|
|
creatorProcess.ResourceLimit?.Release(LimitableResource.Session, 1);
|
|
|
|
creatorProcess.DecrementReferenceCount();
|
|
|
|
}
|
|
|
|
}
|
2018-03-19 15:58:46 -03:00
|
|
|
}
|
|
|
|
}
|