Socket.Accept in AcceptThreadFunc() in HttpListener retries 5 times after exception

Currently the socket.Accept is repeated 5 times in case of a socket exception.
If the network is down ( socket error 10050) i gues it does not make sense to try 5 times. or??

I have multple threads running in an application. One of the threads is streaming audio (WAV / MP3) and this gets heavily interrupted if the network goes down, also as a result of locking in the network code.

Maybe this can be fixed in SDK 2015-R2 :slight_smile:

@ RobvanSchelven - I’m not sure exactly what issue you’re referring to. Can you show some code?

@ John - Its in the HttpListener class in file SDK file HttpListener.cs from NETMF 4.3

A piece of the mentioned function below


 private void AcceptThreadFunc()
    {
      Thread.CurrentThread.Priority = ThreadPriority.AboveNormal;
      this.m_ServiceRunning = true;
      int num = 0;
      this.m_RequestArrived.Set();
      while (this.m_ServiceRunning)
      {
        NetworkStream stream = (NetworkStream) null;
        Socket socket;
        try
        {
          socket = this.m_listener.Accept();
          num = 0;
          try
          {
            socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.Debug, true);
          }
          catch
          {
          }
        }
        catch (SocketException ex)
        {
          if (num > 5)
          {
            if (this.m_ServiceRunning && !this.m_Closed)
              this.Stop();
            this.m_RequestArrived.Set();
            break;
          }
          ++num;
          continue;
        }
        catch
        {
          if (this.m_ServiceRunning && !this.m_Closed)
            this.Stop();
          this.m_RequestArrived.Set();
          break;
        }

@ RobvanSchelven - We cannot make changes to the core NETMF libraries in our SDK.

@ John - Ahhh… I thought this was an improved piece of code by GHI