ConnectionState.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.Net.Sockets;
  10. using System.Text;
  11. using SCSI;
  12. using Utilities;
  13. namespace ISCSI.Server
  14. {
  15. /// <summary>
  16. /// iSCSI Connection state object
  17. /// </summary>
  18. internal class ConnectionState
  19. {
  20. public Socket ClientSocket = null;
  21. /// <summary>
  22. /// DataSegmentLength MUST not exceed MaxRecvDataSegmentLength for the direction it is sent and the total of all the DataSegmentLength of all PDUs in a sequence MUST not exceed MaxBurstLength (or FirstBurstLength for unsolicited data).
  23. /// </summary>
  24. public const int ReceiveBufferSize = 131072; // Note: FirstBurstLength, MaxBurstLength and MaxRecvDataSegmentLength put a cap on DataSegmentLength, NOT on the PDU length.
  25. public byte[] ReceiveBuffer = new byte[ReceiveBufferSize]; // immediate receive buffer
  26. public byte[] ConnectionBuffer = new byte[0]; // we append the receive buffer here until we have a complete PDU
  27. public ConnectionParameters ConnectionParameters = new ConnectionParameters();
  28. public CountdownLatch RunningSCSICommands = new CountdownLatch();
  29. public BlockingQueue<ISCSIPDU> SendQueue = new BlockingQueue<ISCSIPDU>();
  30. public void OnCommandCompleted(SCSIStatusCodeName status, byte[] responseBytes, object task)
  31. {
  32. RunningSCSICommands.Decrement();
  33. SCSICommandPDU command = (SCSICommandPDU)task;
  34. List<ISCSIPDU> responseList = TargetResponseHelper.PrepareSCSICommandResponse(command, status, responseBytes, ConnectionParameters);
  35. SendQueue.Enqueue(responseList);
  36. }
  37. public string ConnectionIdentifier
  38. {
  39. get
  40. {
  41. return ConnectionParameters.ConnectionIdentifier;
  42. }
  43. }
  44. public ISCSISession Session
  45. {
  46. get
  47. {
  48. return ConnectionParameters.Session;
  49. }
  50. }
  51. public ISCSITarget Target
  52. {
  53. get
  54. {
  55. return Session.Target;
  56. }
  57. }
  58. }
  59. }