Explorar o código

Complete support for EAP.

drieseng %!s(int64=9) %!d(string=hai) anos
pai
achega
e49dc1410b
Modificáronse 1 ficheiros con 30 adicións e 8 borrados
  1. 30 8
      src/Renci.SshNet/ForwardedPortDynamic.NET.cs

+ 30 - 8
src/Renci.SshNet/ForwardedPortDynamic.NET.cs

@@ -17,6 +17,10 @@ namespace Renci.SshNet
         private Socket _listener;
         private int _pendingRequests;
 
+#if FEATURE_SOCKET_EAP
+        private ManualResetEvent _stoppingListener;
+#endif // FEATURE_SOCKET_EAP
+
         partial void InternalStart()
         {
             var ip = IPAddress.Any;
@@ -42,19 +46,25 @@ namespace Renci.SshNet
                 {
                     try
                     {
-                        while (true)
-                        {
 #if FEATURE_SOCKET_EAP
-                            StartAccept();
+                        _stoppingListener = new ManualResetEvent(false);
 
-                            // TODO: wait for signal to stop
-#else
+                        StartAccept();
+
+                        _stoppingListener.WaitOne();
+#elif FEATURE_SOCKET_APM
+                        while (true)
+                        {
                             // accept new inbound connection
                             var asyncResult = _listener.BeginAccept(AcceptCallback, _listener);
                             // wait for the connection to be established
                             asyncResult.AsyncWaitHandle.WaitOne();
-#endif // FEATURE_SOCKET_EAP
                         }
+#elif FEATURE_SOCKET_TAP
+#error Accepting new socket connections is not implemented.
+#else
+#error Accepting new socket connections is not implemented.
+#endif
                     }
                     catch (ObjectDisposedException)
                     {
@@ -114,7 +124,7 @@ namespace Renci.SshNet
 
             ProcessAccept(acceptAsyncEventArgs.AcceptSocket);
         }
-#else
+#elif FEATURE_SOCKET_APM
         private void AcceptCallback(IAsyncResult ar)
         {
             // Get the socket that handles the client request
@@ -135,7 +145,7 @@ namespace Renci.SshNet
 
             ProcessAccept(clientSocket);
         }
-#endif // FEATURE_SOCKET_EAP
+#endif
 
         private void ProcessAccept(Socket remoteSocket)
         {
@@ -230,6 +240,10 @@ namespace Renci.SshNet
             if (!IsStarted)
                 return;
 
+#if FEATURE_SOCKET_EAP
+            _stoppingListener.Set();
+#endif // FEATURE_SOCKET_EAP
+
             // close listener socket
             _listener.Dispose();
             // wait for listener loop to finish
@@ -276,6 +290,14 @@ namespace Renci.SshNet
                     _listener.Dispose();
                     _listener = null;
                 }
+
+#if FEATURE_SOCKET_EAP
+                if (_stoppingListener != null)
+                {
+                    _stoppingListener.Dispose();
+                    _stoppingListener = null;
+                }
+#endif // FEATURE_SOCKET_EAP
             }
         }