Jelajahi Sumber

Renamed StateObject to ConnectionState

Tal Aloni 8 tahun lalu
induk
melakukan
b6c8abba25

+ 1 - 1
ISCSI/Client/StateObject.cs

@@ -10,7 +10,7 @@ using System.Text;
 
 namespace ISCSI.Client
 {
-    public class StateObject
+    public class ConnectionState
     {
         // Session parameters:
         public ulong ISID; // Initiator Session ID

+ 4 - 4
ISCSI/Client/ISCSIClient.cs

@@ -68,7 +68,7 @@ namespace ISCSI.Client
                 {
                     return false;
                 }
-                StateObject state = new StateObject();
+                ConnectionState state = new ConnectionState();
                 m_currentAsyncResult = m_clientSocket.BeginReceive(state.ReceiveBuffer, 0, state.ReceiveBuffer.Length, SocketFlags.None, new AsyncCallback(OnClientSocketReceive), state);
                 m_isConnected = true;
             }
@@ -306,7 +306,7 @@ namespace ISCSI.Client
                 return;
             }
 
-            StateObject state = (StateObject)ar.AsyncState;
+            ConnectionState state = (ConnectionState)ar.AsyncState;
 
             if (!m_clientSocket.Connected)
             {
@@ -355,7 +355,7 @@ namespace ISCSI.Client
             }
         }
 
-        public void ProcessCurrentBuffer(byte[] currentBuffer, StateObject state)
+        public void ProcessCurrentBuffer(byte[] currentBuffer, ConnectionState state)
         {
             if (state.ConnectionBuffer.Length == 0)
             {
@@ -430,7 +430,7 @@ namespace ISCSI.Client
             }
         }
 
-        public void ProcessPDU(ISCSIPDU pdu, StateObject state)
+        public void ProcessPDU(ISCSIPDU pdu, ConnectionState state)
         {
             if (pdu is NOPInPDU)
             {

+ 2 - 2
ISCSI/ISCSI.csproj

@@ -38,7 +38,7 @@
     <Compile Include="Client\ISCSIDisk.cs" />
     <Compile Include="Client\PDUHelper.cs" />
     <Compile Include="Client\SessionParameters.cs" />
-    <Compile Include="Client\StateObject.cs" />
+    <Compile Include="Client\ConnectionState.cs" />
     <Compile Include="Client\ISCSIClient.cs" />
     <Compile Include="PDU\Enums\ISCSIResponseName.cs" />
     <Compile Include="PDU\Enums\LogoutReasonCode.cs" />
@@ -108,7 +108,7 @@
     <Compile Include="SCSI\SCSIReturnParameters\VPDPages\SupportedVitaLProductDataPages.cs" />
     <Compile Include="SCSI\SCSIReturnParameters\VPDPages\UnitSerialNumberVPDPage.cs" />
     <Compile Include="Server\ServerResponseHelper.cs" />
-    <Compile Include="Server\StateObject.cs" />
+    <Compile Include="Server\ConnectionState.cs" />
     <Compile Include="Server\TargetResponseHelper.cs" />
     <Compile Include="Utilities\SocketUtils.cs" />
   </ItemGroup>

+ 1 - 1
ISCSI/Server/StateObject.cs

@@ -15,7 +15,7 @@ namespace ISCSI.Server
     /// <summary>
     /// iSCSI Connection state object
     /// </summary>
-    public class StateObject
+    public class ConnectionState
     {
         public Socket ClientSocket = null;
         /// <summary>

+ 19 - 19
ISCSI/Server/ISCSIServer.cs

@@ -40,7 +40,7 @@ namespace ISCSI.Server
 
         private Socket m_listenerSocket;
         private bool m_listening;
-        private static List<StateObject> m_activeConnections = new List<StateObject>();
+        private static List<ConnectionState> m_activeConnections = new List<ConnectionState>();
 
         public static object m_logSyncLock = new object();
         private static FileStream m_logFile;
@@ -108,14 +108,14 @@ namespace ISCSI.Server
 
             Log("[OnConnectRequest] New connection has been accepted");
 
-            StateObject state = new StateObject();
-            state.ReceiveBuffer = new byte[StateObject.ReceiveBufferSize];
+            ConnectionState state = new ConnectionState();
+            state.ReceiveBuffer = new byte[ConnectionState.ReceiveBufferSize];
             // Disable the Nagle Algorithm for this tcp socket:
             clientSocket.NoDelay = true;
             state.ClientSocket = clientSocket;
             try
             {
-                clientSocket.BeginReceive(state.ReceiveBuffer, 0, StateObject.ReceiveBufferSize, 0, ReceiveCallback, state);
+                clientSocket.BeginReceive(state.ReceiveBuffer, 0, ConnectionState.ReceiveBufferSize, 0, ReceiveCallback, state);
             }
             catch (ObjectDisposedException)
             {
@@ -147,7 +147,7 @@ namespace ISCSI.Server
                 return;
             }
 
-            StateObject state = (StateObject)result.AsyncState;
+            ConnectionState state = (ConnectionState)result.AsyncState;
             Socket clientSocket = state.ClientSocket;
             if (!clientSocket.Connected)
             {
@@ -179,7 +179,7 @@ namespace ISCSI.Server
                 state.RunningSCSICommands.WaitUntilZero();
                 lock (m_activeConnections)
                 {
-                    int connectionIndex = GetStateObjectIndex(m_activeConnections, state.SessionParameters.ISID, state.SessionParameters.TSIH, state.ConnectionParameters.CID);
+                    int connectionIndex = GetConnectionStateIndex(m_activeConnections, state.SessionParameters.ISID, state.SessionParameters.TSIH, state.ConnectionParameters.CID);
                     if (connectionIndex >= 0)
                     {
                         m_activeConnections.RemoveAt(connectionIndex);
@@ -193,7 +193,7 @@ namespace ISCSI.Server
 
             try
             {
-                clientSocket.BeginReceive(state.ReceiveBuffer, 0, StateObject.ReceiveBufferSize, 0, ReceiveCallback, state);
+                clientSocket.BeginReceive(state.ReceiveBuffer, 0, ConnectionState.ReceiveBufferSize, 0, ReceiveCallback, state);
             }
             catch (ObjectDisposedException)
             {
@@ -205,7 +205,7 @@ namespace ISCSI.Server
             }
         }
 
-        private void ProcessCurrentBuffer(byte[] currentBuffer, StateObject state)
+        private void ProcessCurrentBuffer(byte[] currentBuffer, ConnectionState state)
         {
             Socket clientSocket = state.ClientSocket;
 
@@ -289,7 +289,7 @@ namespace ISCSI.Server
             }
         }
 
-        private void ProcessPDU(ISCSIPDU pdu, StateObject state)
+        private void ProcessPDU(ISCSIPDU pdu, ConnectionState state)
         {
             Socket clientSocket = state.ClientSocket;
             
@@ -335,12 +335,12 @@ namespace ISCSI.Server
                         // connection implies a logout of the connection followed by a Login
                         lock (m_activeConnections)
                         {
-                            int existingConnectionIndex = GetStateObjectIndex(m_activeConnections, request.ISID, request.TSIH, request.CID);
+                            int existingConnectionIndex = GetConnectionStateIndex(m_activeConnections, request.ISID, request.TSIH, request.CID);
                             if (existingConnectionIndex >= 0)
                             {
                                 // Perform implicit logout
                                 Log("[{0}][ProcessPDU] Initiating implicit logout", state.ConnectionIdentifier);
-                                StateObject existingConnection = m_activeConnections[existingConnectionIndex];
+                                ConnectionState existingConnection = m_activeConnections[existingConnectionIndex];
                                 // Wait for pending I/O to complete.
                                 existingConnection.RunningSCSICommands.WaitUntilZero();
                                 SocketUtils.ReleaseSocket(existingConnection.ClientSocket);
@@ -396,10 +396,10 @@ namespace ISCSI.Server
                 {
                     lock (m_activeConnections)
                     {
-                        int connectionIndex = GetStateObjectIndex(m_activeConnections, state.SessionParameters.ISID, state.SessionParameters.TSIH, state.ConnectionParameters.CID);
+                        int connectionIndex = GetConnectionStateIndex(m_activeConnections, state.SessionParameters.ISID, state.SessionParameters.TSIH, state.ConnectionParameters.CID);
                         if (connectionIndex >= 0)
                         {
-                            StateObject existingConnection = m_activeConnections[connectionIndex];
+                            ConnectionState existingConnection = m_activeConnections[connectionIndex];
                             // RFC 3720: A Logout for a CID may be performed on a different transport connection when the TCP connection for the CID has already been terminated.
                             if (existingConnection != state)
                             {
@@ -496,13 +496,13 @@ namespace ISCSI.Server
             }
         }
 
-        private static int GetStateObjectIndex(List<StateObject> stateObjects, ulong isid, ushort tsih, ushort cid)
+        private static int GetConnectionStateIndex(List<ConnectionState> Connections, ulong isid, ushort tsih, ushort cid)
         {
-            for (int index = 0; index < stateObjects.Count; index++)
+            for (int index = 0; index < Connections.Count; index++)
             {
-                if (stateObjects[index].SessionParameters.ISID == isid &&
-                    stateObjects[index].SessionParameters.TSIH == tsih &&
-                    stateObjects[index].ConnectionParameters.CID == cid)
+                if (Connections[index].SessionParameters.ISID == isid &&
+                    Connections[index].SessionParameters.TSIH == tsih &&
+                    Connections[index].ConnectionParameters.CID == cid)
                 {
                     return index;
                 }
@@ -510,7 +510,7 @@ namespace ISCSI.Server
             return -1;
         }
 
-        private static void TrySendPDU(StateObject state, ISCSIPDU response)
+        private static void TrySendPDU(ConnectionState state, ISCSIPDU response)
         {
             Socket clientSocket = state.ClientSocket;
             try

+ 3 - 3
ISCSI/Server/TargetResponseHelper.cs

@@ -22,7 +22,7 @@ namespace ISCSI.Server
             List<ISCSIPDU> responseList = new List<ISCSIPDU>();
             commandsToExecute = new List<SCSICommandPDU>();
             
-            string connectionIdentifier = StateObject.GetConnectionIdentifier(session, connection);
+            string connectionIdentifier = ConnectionState.GetConnectionIdentifier(session, connection);
 
             if (command.Write && command.DataSegmentLength < command.ExpectedDataTransferLength)
             {
@@ -62,7 +62,7 @@ namespace ISCSI.Server
             List<ISCSIPDU> responseList = new List<ISCSIPDU>();
             commandsToExecute = new List<SCSICommandPDU>();
 
-            string connectionIdentifier = StateObject.GetConnectionIdentifier(session, connection);
+            string connectionIdentifier = ConnectionState.GetConnectionIdentifier(session, connection);
             TransferEntry transfer = connection.GetTransferEntry(request.TargetTransferTag);
             if (transfer == null)
             {
@@ -125,7 +125,7 @@ namespace ISCSI.Server
 
         internal static List<ISCSIPDU> GetSCSICommandResponse(SCSICommandPDU command, ISCSITarget target, SessionParameters session, ConnectionParameters connection)
         {
-            string connectionIdentifier = StateObject.GetConnectionIdentifier(session, connection);
+            string connectionIdentifier = ConnectionState.GetConnectionIdentifier(session, connection);
             ISCSIServer.Log("[{0}] Executing Command: CmdSN: {1}", connectionIdentifier, command.CmdSN);
             byte[] scsiResponse;
             SCSIStatusCodeName status = target.ExecuteCommand(command.CommandDescriptorBlock, command.LUN, command.Data, out scsiResponse);