io_service.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // This Source Code Form is subject to the terms of the Mozilla Public
  4. // License, v. 2.0. If a copy of the MPL was not distributed with this
  5. // file, You can obtain one at http://mozilla.org/MPL/2.0/.
  6. #ifndef ASIOLINK_IO_SERVICE_H
  7. #define ASIOLINK_IO_SERVICE_H 1
  8. #include <boost/function.hpp>
  9. namespace boost {
  10. namespace asio {
  11. class io_service;
  12. }
  13. }
  14. namespace isc {
  15. namespace asiolink {
  16. class IOServiceImpl;
  17. /// \brief The \c IOService class is a wrapper for the ASIO \c io_service
  18. /// class.
  19. ///
  20. class IOService {
  21. ///
  22. /// \name Constructors and Destructor
  23. ///
  24. /// Note: The copy constructor and the assignment operator are
  25. /// intentionally defined as private, making this class non-copyable.
  26. //@{
  27. private:
  28. IOService(const IOService& source);
  29. IOService& operator=(const IOService& source);
  30. public:
  31. /// \brief The constructor
  32. IOService();
  33. /// \brief The destructor.
  34. ~IOService();
  35. //@}
  36. /// \brief Start the underlying event loop.
  37. ///
  38. /// This method does not return control to the caller until
  39. /// the \c stop() method is called via some handler.
  40. void run();
  41. /// \brief Run the underlying event loop for a single event.
  42. ///
  43. /// This method return control to the caller as soon as the
  44. /// first handler has completed. (If no handlers are ready when
  45. /// it is run, it will block until one is.)
  46. void run_one();
  47. /// \brief Run the underlying event loop for a ready events.
  48. ///
  49. /// This method executes handlers for all ready events and returns.
  50. /// It will return immediately if there are no ready events.
  51. void poll();
  52. /// \brief Stop the underlying event loop.
  53. ///
  54. /// This will return the control to the caller of the \c run() method.
  55. void stop();
  56. /// \brief Return the native \c io_service object used in this wrapper.
  57. ///
  58. /// This is a short term work around to support other Kea modules
  59. /// that share the same \c io_service with the authoritative server.
  60. /// It will eventually be removed once the wrapper interface is
  61. /// generalized.
  62. boost::asio::io_service& get_io_service();
  63. /// \brief Post a callback to the end of the queue.
  64. ///
  65. /// Requests the callback be called sometime later. It is not guaranteed
  66. /// by the underlying asio, but it can reasonably be expected the callback
  67. /// is put to the end of the callback queue. It is not called from within
  68. /// this function.
  69. ///
  70. /// It may be used to implement "background" work, for example (doing stuff
  71. /// by small bits that are called from time to time).
  72. void post(const boost::function<void ()>& callback);
  73. private:
  74. IOServiceImpl* io_impl_;
  75. };
  76. /// @brief Defines a smart pointer to an IOService instance.
  77. typedef boost::shared_ptr<IOService> IOServicePtr;
  78. } // namespace asiolink
  79. } // namespace isc
  80. #endif // ASIOLINK_IO_SERVICE_H