Exemplo n.º 1
0
 /// <summary>
 /// Stops the capture process
 ///
 /// Throws an exception if the stop capture timeout is exceeded and the
 /// capture thread was aborted
 /// </summary>
 public virtual void StopCapture()
 {
     if (Started)
     {
         threadCancellationTokenSource.Cancel();
         threadCancellationTokenSource = new CancellationTokenSource();
         LibPcapSafeNativeMethods.pcap_breakloop(Handle);
         Task.WaitAny(new[] { captureThread }, StopCaptureTimeout);
         captureThread = null;
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Stops the capture process
 ///
 /// Throws an exception if the stop capture timeout is exceeded and the
 /// capture thread was aborted
 /// </summary>
 public virtual void StopCapture()
 {
     if (Started)
     {
         threadCancellationTokenSource.Cancel();
         threadCancellationTokenSource = new CancellationTokenSource();
         LibPcapSafeNativeMethods.pcap_breakloop(PcapHandle);
         if (!captureThread.Join(StopCaptureTimeout))
         {
             try
             {
                 captureThread.Abort();
             } catch (PlatformNotSupportedException)
             {
                 // ignore exception, .net platforms lack support for Thread.Abort() and aborting threads
                 // is a hack
             }
         }
         captureThread = null; // otherwise we will always return true from PcapDevice.Started
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Stops the capture process
        ///
        /// Throws an exception if the stop capture timeout is exceeded and the
        /// capture thread was aborted
        /// </summary>
        public virtual void StopCapture()
        {
            if (Started)
            {
                threadCancellationTokenSource.Cancel();
                LibPcapSafeNativeMethods.pcap_breakloop(PcapHandle);
                if (!captureThread.Join(StopCaptureTimeout))
                {
                    try
                    {
                        captureThread.Abort();
                    } catch (PlatformNotSupportedException)
                    {
                        // ignore exception, .net platforms lack support for Thread.Abort() and aborting threads
                        // is a hack
                    }

                    captureThread = null;
                    string error;

                    if (isLibPcap && !MonoUnixFound)
                    {
                        error = string.Format("captureThread was aborted after {0}. Using a Mono" +
                                              " version >= 2.4 and installing Mono.Posix should" +
                                              " enable smooth thread shutdown",
                                              StopCaptureTimeout.ToString());
                    }
                    else
                    {
                        error = string.Format("captureThread was aborted after {0}",
                                              StopCaptureTimeout.ToString());
                    }

                    throw new PcapException(error);
                }

                captureThread = null; // otherwise we will always return true from PcapDevice.Started
            }
        }