Subject: Re: [Boost-bugs] [Boost C++ Libraries] #13364: steady_timer doesn't work in dll
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-12-26 00:10:16
#13364: steady_timer doesn't work in dll
-------------------------+-------------------------------------------------
Reporter: anonymous | Owner: chris_kohlhoff
Type: Bugs | Status: new
Milestone: To Be | Component: asio
Determined |
Version: Boost | Severity: Showstopper
1.66.0 | Keywords: boost::asio::steady_timer
Resolution: | boost::dll
-------------------------+-------------------------------------------------
Comment (by anonymous):
I'm working with Visual Studio 2017 V15.5.2.
Sorry, can't add attachments. So i list the source here:
api.h:
------
#include <boost/asio.hpp>
class my_api {
public:
virtual void startTimer(boost::asio::io_service& ioservice) = 0;
virtual ~my_api() {}
};
dll.cpp
-------
#include <iostream>
#include <boost/dll.hpp>
#include "api.h"
class my_plugin : public my_api {
public:
void startTimer(boost::asio::io_service& ioservice) {
std::cout << "start timer (15 sec)\n";
boost::asio::steady_timer timer{ ioservice,
std::chrono::seconds{ 15 } };
timer.async_wait([](const boost::system::error_code &ec) {
std::cout << "15 sec\n"; });
};
~my_plugin() {};
};
static boost::shared_ptr<my_api> createPlugin() {
return boost::shared_ptr<my_api>(new my_plugin());
}
BOOST_DLL_ALIAS(
createPlugin,
create_plugin
)
AsioProblem.cpp:
----------------
#include "stdafx.h"
#include <boost/dll/import.hpp>
#include <boost/function.hpp>
#include <boost/asio.hpp>
#include <iostream>
#include "../DLL/api.h"
namespace dll = boost::dll;
int main() {
boost::asio::io_service ioservice;
/* load dll */
boost::filesystem::path shared_library_path("..\\Debug");
shared_library_path /= "DLL";
boost::function<boost::shared_ptr<my_api>()> creator =
boost::dll::import_alias<boost::shared_ptr<my_api>()>(
shared_library_path,
"create_plugin",
boost::dll::load_mode::append_decorations
);
boost::shared_ptr<my_api> plugin = creator();
/* set timer 10 sec */
std::cout << "start timer (10 sec)\n";
boost::asio::steady_timer timer{ ioservice, std::chrono::seconds{
10 } };
timer.async_wait([](const boost::system::error_code &ec) {
std::cout << "10 sec\n"; });
/* create my_plugin in dll with timer 15 sec */
plugin->startTimer(ioservice);
ioservice.run();
return 0;
}
-- Ticket URL: <https://svn.boost.org/trac10/boost/ticket/13364#comment:1> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-12-26 00:16:35 UTC