SessionManager.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /* Copyright (C) 2012-2016 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Threading;
  10. using Utilities;
  11. namespace ISCSI.Server
  12. {
  13. internal class SessionManager
  14. {
  15. private object m_syncLock = new object();
  16. private ushort m_nextTSIH = 1; // Next Target Session Identifying Handle
  17. public ushort GetNextTSIH()
  18. {
  19. // The iSCSI Target selects a non-zero value for the TSIH at
  20. // session creation (when an initiator presents a 0 value at Login).
  21. // After being selected, the same TSIH value MUST be used whenever the
  22. // initiator or target refers to the session and a TSIH is required.
  23. lock (m_syncLock)
  24. {
  25. ushort nextTSIH = m_nextTSIH;
  26. m_nextTSIH++;
  27. if (m_nextTSIH == 0)
  28. {
  29. m_nextTSIH++;
  30. }
  31. return nextTSIH;
  32. }
  33. }
  34. }
  35. }