Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External io_service #76

Open
pdgendt opened this issue Nov 19, 2014 · 2 comments
Open

External io_service #76

pdgendt opened this issue Nov 19, 2014 · 2 comments

Comments

@pdgendt
Copy link

pdgendt commented Nov 19, 2014

Is it possible to create an http server with an existing asio::io_service? If an application has an existing thread pool available could this be passed to a custom scheduler for example?

@pmed
Copy link
Contributor

pmed commented Nov 19, 2014

Yes, you need to derive from pion::scheduler class and to override its pion::scheduler::get_io_service() member function. Then pass the custom scheduler into a http server:

struct my_scheduler : public pion::scheduler
{
    explicit my_scheduler(boost::asio::io_service& io_service) : io_service(io_service)
   {
       set_num_threads(1); // actual thread count in existing pool
       startup();
   }
    ~my_scheduler()
    {
        shutdown();
    }
    boost::asio::io_service& get_io_service() { return io_service; }
    boost::asio::io_service& io_service;
};

boost::asio::io_service io_service;
my_scheduler scheduler(io_service);
pion::http_server server(scheduler, 8080);

@pdgendt
Copy link
Author

pdgendt commented Nov 20, 2014

Thx, I can use that to use as my scheduler, one issue though: If I then want to stop my application it doesn't close the connection which is waiting for the async_accept. So I get infinite messages:

946694190 INFO pion.tcp.server Waiting for open connections to finish
946694190 INFO pion.tcp.server Waiting for open connections to finish
946694190 INFO pion.tcp.server Waiting for open connections to finish
946694191 INFO pion.tcp.server Waiting for open connections to finish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants