ConnectionState.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. public static int ReceiveBufferSize = ISCSIPDU.BasicHeaderSegmentLength + ISCSIServer.DeclaredParameters.MaxRecvDataSegmentLength;
  22. public ISCSIConnectionReceiveBuffer ReceiveBuffer = new ISCSIConnectionReceiveBuffer(ReceiveBufferSize);
  23. public ConnectionParameters ConnectionParameters = new ConnectionParameters();
  24. public CountdownLatch RunningSCSICommands = new CountdownLatch();
  25. public BlockingQueue<ISCSIPDU> SendQueue = new BlockingQueue<ISCSIPDU>();
  26. public void OnCommandCompleted(SCSIStatusCodeName status, byte[] responseBytes, object task)
  27. {
  28. RunningSCSICommands.Decrement();
  29. SCSICommandPDU command = (SCSICommandPDU)task;
  30. List<ISCSIPDU> responseList = TargetResponseHelper.PrepareSCSICommandResponse(command, status, responseBytes, ConnectionParameters);
  31. SendQueue.Enqueue(responseList);
  32. }
  33. public string ConnectionIdentifier
  34. {
  35. get
  36. {
  37. return ConnectionParameters.ConnectionIdentifier;
  38. }
  39. }
  40. public ISCSISession Session
  41. {
  42. get
  43. {
  44. return ConnectionParameters.Session;
  45. }
  46. }
  47. public ISCSITarget Target
  48. {
  49. get
  50. {
  51. return Session.Target;
  52. }
  53. }
  54. }
  55. }