123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- // Copyright (C) 2011,2013 Internet Systems Consortium, Inc. ("ISC")
- //
- // Permission to use, copy, modify, and/or distribute this software for any
- // purpose with or without fee is hereby granted, provided that the above
- // copyright notice and this permission notice appear in all copies.
- //
- // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
- // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
- // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
- // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
- // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
- // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- #include <config.h>
- #include <unistd.h> // for some IPC/network system calls
- #include <netinet/in.h>
- #include <sys/socket.h>
- #include <asio.hpp>
- #include <asiolink/io_service.h>
- namespace isc {
- namespace asiolink {
- namespace {
- // A trivial wrapper for boost::function. SunStudio doesn't seem to be capable
- // of handling a boost::function object if directly passed to
- // io_service::post().
- class CallbackWrapper {
- public:
- CallbackWrapper(const boost::function<void()>& callback) :
- callback_(callback)
- {}
- void operator()() {
- callback_();
- }
- private:
- boost::function<void()> callback_;
- };
- }
- class IOServiceImpl {
- private:
- IOServiceImpl(const IOService& source);
- IOServiceImpl& operator=(const IOService& source);
- public:
- /// \brief The constructor
- IOServiceImpl() :
- io_service_(),
- work_(io_service_)
- {};
- /// \brief The destructor.
- ~IOServiceImpl() {};
- //@}
- /// \brief Start the underlying event loop.
- ///
- /// This method does not return control to the caller until
- /// the \c stop() method is called via some handler.
- void run() { io_service_.run(); };
- /// \brief Run the underlying event loop for a single event.
- ///
- /// This method return control to the caller as soon as the
- /// first handler has completed. (If no handlers are ready when
- /// it is run, it will block until one is.)
- void run_one() { io_service_.run_one();} ;
- /// \brief Stop the underlying event loop.
- ///
- /// This will return the control to the caller of the \c run() method.
- void stop() { io_service_.stop();} ;
- /// \brief Return the native \c io_service object used in this wrapper.
- ///
- /// This is a short term work around to support other BIND 10 modules
- /// that share the same \c io_service with the authoritative server.
- /// It will eventually be removed once the wrapper interface is
- /// generalized.
- asio::io_service& get_io_service() { return io_service_; };
- void post(const boost::function<void ()>& callback) {
- io_service_.post(CallbackWrapper(callback));
- }
- private:
- asio::io_service io_service_;
- asio::io_service::work work_;
- };
- IOService::IOService() {
- io_impl_ = new IOServiceImpl();
- }
- IOService::~IOService() {
- delete io_impl_;
- }
- void
- IOService::run() {
- io_impl_->run();
- }
- void
- IOService::run_one() {
- io_impl_->run_one();
- }
- void
- IOService::stop() {
- io_impl_->stop();
- }
- asio::io_service&
- IOService::get_io_service() {
- return (io_impl_->get_io_service());
- }
- void
- IOService::post(const boost::function<void ()>& callback) {
- return (io_impl_->post(callback));
- }
- } // namespace asiolink
- } // namespace isc
|