KSession.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using Ryujinx.HLE.HOS.Kernel.Common;
  2. using Ryujinx.HLE.HOS.Kernel.Process;
  3. namespace Ryujinx.HLE.HOS.Kernel.Ipc
  4. {
  5. class KSession : KAutoObject
  6. {
  7. public KServerSession ServerSession { get; }
  8. public KClientSession ClientSession { get; }
  9. private bool _hasBeenInitialized;
  10. public KSession(KernelContext context, KClientPort parentPort = null) : base(context)
  11. {
  12. IncrementReferenceCount();
  13. ServerSession = new KServerSession(context, this);
  14. ClientSession = new KClientSession(context, this, parentPort);
  15. _hasBeenInitialized = true;
  16. }
  17. public void DisconnectClient()
  18. {
  19. if (ClientSession.State == ChannelState.Open)
  20. {
  21. ClientSession.State = ChannelState.ClientDisconnected;
  22. ServerSession.CancelAllRequestsClientDisconnected();
  23. }
  24. }
  25. public void DisconnectServer()
  26. {
  27. if (ClientSession.State == ChannelState.Open)
  28. {
  29. ClientSession.State = ChannelState.ServerDisconnected;
  30. }
  31. }
  32. protected override void Destroy()
  33. {
  34. if (_hasBeenInitialized)
  35. {
  36. ClientSession.DisconnectFromPort();
  37. KProcess creatorProcess = ClientSession.CreatorProcess;
  38. creatorProcess.ResourceLimit?.Release(LimitableResource.Session, 1);
  39. creatorProcess.DecrementReferenceCount();
  40. }
  41. }
  42. }
  43. }