Search code examples
c++web-servicessoapgsoap

gSoap: how to gracefully shutdown the webservice application?


I'm using gSoap to write a webservice. It's running as a console application. In all gSoap examples I see, that requests are dispatched in infinite loop like for(;;;) even in multi-threaded version.

But how can I make my webservice to terminate gracefully when, say, user presses space on the console?

Preferably:

  1. stop accepting new connections;
  2. Serve existing ones;
  3. Exit from application

Solution

  • The section 7.2.4 How to Create a Multi-Threaded Stand-Alone Service in the documentation has example code for writing an accept loop. You need to write your own accept loop and add signal handling so it responds to Ctrl-C.

    1. stop accepting new connections:

      Leave the loop so you stop calling accept.

    2. Serve existing ones:

      The threads need to inform you when they are finished, so you can exit when the number of active clients is zero. (boost::thead_group has a join_all which does exactly that.)

    3. Exit from application: