KSession.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using Ryujinx.HLE.HOS.Kernel.Common;
  2. using Ryujinx.HLE.HOS.Kernel.Process;
  3. using System;
  4. namespace Ryujinx.HLE.HOS.Kernel.Ipc
  5. {
  6. class KSession : KAutoObject
  7. {
  8. public KServerSession ServerSession { get; }
  9. public KClientSession ClientSession { get; }
  10. private bool _hasBeenInitialized;
  11. public KSession(KernelContext context, KClientPort parentPort = null) : base(context)
  12. {
  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. }