Browse Source

API change: listener endpoint should now be passed to the Start method instead of the ISCSIServer constructor

Tal Aloni 8 years ago
parent
commit
a4cca156c0
2 changed files with 17 additions and 20 deletions
  1. 15 18
      ISCSI/ISCSI.Server/ISCSIServer.cs
  2. 2 2
      ISCSIConsole/Program.StartCommand.cs

+ 15 - 18
ISCSI/ISCSI.Server/ISCSIServer.cs

@@ -22,8 +22,6 @@ namespace ISCSI.Server
     {
         public const int DefaultPort = 3260;
 
-        private IPEndPoint m_listenerEP;
-
         private Socket m_listenerSocket;
         private bool m_listening;
         private TargetList m_targets = new TargetList();
@@ -31,25 +29,12 @@ namespace ISCSI.Server
         private ConnectionManager m_connectionManager = new ConnectionManager();
 
         public event EventHandler<LogEntry> OnLogEntry;
-        
-        public ISCSIServer() : this(DefaultPort)
-        { }
-
-        /// <summary>
-        /// Server needs to be started with Start()
-        /// </summary>
-        /// <param name="port">The port on which the iSCSI server will listen</param>
-        public ISCSIServer(int port) : this(new IPEndPoint(IPAddress.Any, port))
-        {
-        }
 
         /// <summary>
         /// Server needs to be started with Start()
         /// </summary>
-        /// <param name="listenerEP">The endpoint on which the iSCSI server will listen</param>
-        public ISCSIServer(IPEndPoint listenerEP)
+        public ISCSIServer()
         {
-            m_listenerEP = listenerEP;
         }
 
         public void AddTarget(ISCSITarget target)
@@ -81,13 +66,25 @@ namespace ISCSI.Server
 
         public void Start()
         {
+            Start(DefaultPort);
+        }
+
+        /// <param name="listenerPort">The port on which the iSCSI server will listen</param>
+        public void Start(int listenerPort)
+        {
+            Start(new IPEndPoint(IPAddress.Any, listenerPort));
+        }
+
+        /// <param name="listenerEP">The endpoint on which the iSCSI server will listen</param>
+        public void Start(IPEndPoint listenerEndPoint)
+        {
             if (!m_listening)
             {
                 Log(Severity.Information, "Starting Server");
                 m_listening = true;
 
-                m_listenerSocket = new Socket(m_listenerEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
-                m_listenerSocket.Bind(m_listenerEP);
+                m_listenerSocket = new Socket(listenerEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
+                m_listenerSocket.Bind(listenerEndPoint);
                 m_listenerSocket.Listen(1000);
                 m_listenerSocket.BeginAccept(ConnectRequestCallback, m_listenerSocket);
             }

+ 2 - 2
ISCSIConsole/Program.StartCommand.cs

@@ -45,7 +45,7 @@ namespace ISCSIConsole
                     {
                         logFile = parameters.ValueOf("log");
                     }
-                    m_server = new ISCSIServer(port);
+                    m_server = new ISCSIServer();
                     m_server.AddTargets(m_targets);
                     m_server.OnLogEntry += new EventHandler<LogEntry>(OnLogEntry);
                     if (logFile != String.Empty)
@@ -63,7 +63,7 @@ namespace ISCSIConsole
 
                     try
                     {
-                        m_server.Start();
+                        m_server.Start(port);
                         Console.WriteLine("Server started, listening on port {0}", port);
                     }
                     catch (SocketException)