in reply to Win32::Daemon + socket->accept: service cannot be stopped [SOLVED]

I don't know whether there is a way to make timeout the accept(), I would probably use two threads instead. One thread would do the work (call the accept() and wait for the commands), the other would respond to the Service Manager request. And if the Service Manager requests that the service stops the second thread would connect to the first one and issue a stop command.

This way the worker thread would not need to timeout the accept() it would just wait for a connection either from a client or the other thread. Since you do not need to share any data between the threads it's enough to use fork() to create the threads. Do I make sense?

P.S.: You may want to have a look at Win32::Daemon::Simple, that'd make the service related part of the script much much simpler.

Jenda
XML sucks. Badly. SOAP on the other hand is the most powerfull vacuum pump ever invented.

  • Comment on Re: Win32::Daemon + socket->accept: service cannot be stopped

Replies are listed 'Best First'.
Re^2: Win32::Daemon + socket->accept: service cannot be stopped
by svenXY (Deacon) on Jun 24, 2005 at 09:01 UTC
    Hi All,

    Thanks for the help and ideas! It works with a fork() and kill() to kill the child.
    I'll just paste the code that I changed: Thanks again,
    Sven

      I think it would be better to connect to the listening socket and issue a specific command than to kill the working thread. You might kill it at a wrong time.

      If you want to be safe you may for example generate a random number before the fork() and then include the number in the stop command. If you then accept stop requests only from localhost and only if they contain the right number you should be fairly safe.

      Jenda
      XML sucks. Badly. SOAP on the other hand is the most powerfull vacuum pump ever invented.

        Hi Jenda,

        you are probably right and if expecting many clients, I would certainly go down that road.
        As I only have one connection at a time currently, I'm just too lazy to implement that right now. I might try it further.

        Thanks again, Sven