Boost logo

Boost Users :

Subject: Re: [Boost-users] running a server "in background mode" ??
From: Ryan McConnehey (mccorywork_at_[hidden])
Date: 2009-11-10 19:46:42


> io_service.run();
> printf("Writting a line 1 \n");

The io_service can't exit the run command until all the work is
complete. You need to put the io_service.run() into its own thread if
you want to still execute things in main.

boost::thread runningService(boost::bind(&boost::asio::io_service::run,
io_service));
printf("Writting a line 1 \n");
sleep(5);
printf("Writting a line 2 \n");
runningService.join();

This will allow you to continue and execute code in your main function.
The problem you'll run into is trying to close the thread properly. I
used the HTTP Server 2 example to create a class that ran my process but
responded to an outside event to signal the class to stop processing.

http://www.boost.org/doc/libs/1_40_0/doc/html/boost_asio/example/http/server2/win_main.cpp

Ryan


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net