HTTPServer single threaded?

2003-09-16
2003-12-15
  • Tim Malcolm
    Tim Malcolm
    2003-09-16

    Is the HTTPServer single threaded? And if it really is (which does appear to be the case), will making it multi-threaded "break" eventing, moderation, etc.?

    The reason I ask is that I'm implementing the AVTransport service of a UPnP Media Server, intend to add an HTTPRequestListener to the Media Server Device instance in order to "serve" Audio/Video content to various AVTransport instances.

    Thanks,
    -- Tim.

     
    • Tim Malcolm
      Tim Malcolm
      2003-11-13

      Satoshi sent me a reply on 9/18, and said
      > Yes, the servers of HTTP and SSDP is single
      > thread version now.

      Here's a little multithreaded version of HTTPServer.run() for anyone who's interested (not yet sent back to Satoshi). I'm doing fairly heavy network development and haven't had any issues with this so far! Note: it's not efficient - anyone want to change this to use thread pooling?

      -- Tim.

      public void run()
      {
      if (isOpened() == false)
      return;

      Thread thisThread = Thread.currentThread();

      while (httpServerThread == thisThread) {
      Thread.yield();
      final Socket sock;
      try {
      sock = accept();
      }
      catch (Exception e){
      break;
      }

      Thread runner = null;
      runner = new Thread(
      new Runnable() {
      public void run() {
      try {
      HTTPSocket httpSock = new HTTPSocket(sock);

      if (httpSock.open() == false)
      return;

      HTTPRequest httpReq = new HTTPRequest(httpSock);

      performRequestListener(httpReq);

      httpSock.close();

      } catch (Exception ex) {
      Debug.warning(ex);
      } catch (Throwable ex) {
      Debug.warning(ex.getMessage());
      }
      }
      }
      );
      runner.start();

      }
      }

       
    • Satoshi Konno
      Satoshi Konno
      2003-12-15

      I changed to use multithreading about the HTTP server and release the package as v1.2. Please check it.

      I think the SSDP servers don't have use multithread because the receive buffer is so big for the SSDP packets and the SSDP messages have to synchronize.