private void ProcessSendQueue(ConnectionState state) { LogTrace("Entering ProcessSendQueue"); while (true) { ISCSIPDU response; bool stopped = !state.SendQueue.TryDequeue(out response); if (stopped) { return; } Socket clientSocket = state.ClientSocket; PDUHelper.SetStatSN(response, state.ConnectionParameters.StatSN); if (state.Session != null) { PDUHelper.SetExpCmdSN(response, state.Session.ExpCmdSN, state.Session.ExpCmdSN + state.Session.CommandQueueSize); } if (response is SCSIResponsePDU || response is LoginResponsePDU || response is TextResponsePDU || (response is SCSIDataInPDU && ((SCSIDataInPDU)response).StatusPresent) || response is RejectPDU) { state.ConnectionParameters.StatSN++; } try { clientSocket.Send(response.GetBytes()); Log(Severity.Verbose, "[{0}] Sent response to initator, Operation: {1}, Size: {2}", state.ConnectionIdentifier, response.OpCode, response.Length); if (response is LogoutResponsePDU) { clientSocket.Close(); // We can close the connection now LogTrace("Leaving ProcessSendQueue"); return; } else if (response is LoginResponsePDU) { if (((LoginResponsePDU)response).Status != LoginResponseStatusName.Success) { // Login Response: If the Status Class is not 0, the initiator and target MUST close the TCP connection. clientSocket.Close(); // We can close the connection now LogTrace("Leaving ProcessSendQueue"); return; } } } catch (SocketException ex) { Log(Severity.Verbose, "[{0}] Failed to send response to initator. Operation: {1}, Size: {2}, SocketException: {3}", state.ConnectionIdentifier, response.OpCode, response.Length, ex.Message); LogTrace("Leaving ProcessSendQueue"); return; } catch (ObjectDisposedException) { Log(Severity.Verbose, "[{0}] Failed to send response to initator. Operation: {1}, Size: {2}. ObjectDisposedException", state.ConnectionIdentifier, response.OpCode, response.Length); LogTrace("Leaving ProcessSendQueue"); return; } } }
public static void TrySendPDU(StateObject state, ISCSIPDU response) { Socket clientSocket = state.ClientSocket; try { PDUHelper.SetStatSN(response, state.ConnectionParameters.StatSN); PDUHelper.SetExpCmdSN(response, state.SessionParameters.ExpCmdSN, state.SessionParameters.ExpCmdSN + state.SessionParameters.CommandQueueSize); if (response is SCSIResponsePDU || (response is SCSIDataInPDU && ((SCSIDataInPDU)response).StatusPresent)) { state.ConnectionParameters.StatSN++; } clientSocket.Send(response.GetBytes()); Log(LogLevel.Debug, "[{0}][TrySendPDU] Sent response to initator, Operation: {1}, Size: {2}", state.ConnectionIdentifier, response.OpCode, response.Length); } catch (SocketException ex) { Log(LogLevel.Warning, "[{0}][TrySendPDU] Failed to send response to initator (Operation: {1}, Size: {2}), SocketException: {3}", state.ConnectionIdentifier, response.OpCode, response.Length, ex.Message); } catch (ObjectDisposedException) { } }