ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

147 lines
4.5 KiB

  1. //
  2. // Copyright (C) 2009-2012 Artyom Beilis (Tonkikh)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. #ifndef BOOSTER_AIO_IO_SERVICE_H
  9. #define BOOSTER_AIO_IO_SERVICE_H
  10. #include <booster/config.h>
  11. #include <booster/aio/aio_config.h>
  12. #include <booster/aio/types.h>
  13. #include <booster/thread.h>
  14. #include <booster/system_error.h>
  15. #include <booster/aio/aio_category.h>
  16. #include <booster/callback.h>
  17. #include <booster/noncopyable.h>
  18. #include <string>
  19. #include <booster/auto_ptr_inc.h>
  20. namespace booster {
  21. class ptime;
  22. namespace aio {
  23. class event_loop_impl;
  24. ///
  25. /// \brief this is the central event loop that dispatches all requests.
  26. ///
  27. /// This all this class member functions are thread safe unless specified otherwise.
  28. ///
  29. /// However only \b single thread may execute run() member function and dispatch its handlers, this class
  30. /// also can be safely created before fork and used after it
  31. ///
  32. class BOOSTER_API io_service : public noncopyable, public io_events {
  33. public:
  34. ///
  35. /// Create io service using specific reactor type and not default one (see reactor's class use_* constants)
  36. ///
  37. io_service(int reactor_type);
  38. ///
  39. /// Create io service using default reactor
  40. ///
  41. io_service();
  42. ///
  43. /// Destroy io_service. It should be stopped before!.
  44. ///
  45. ~io_service();
  46. ///
  47. /// Set event handler \a h for file descriptor \a fd. \a event can be \ref io_events::in, \ref io_events::out
  48. /// or \ref io_events::in | \ref io_events::out.
  49. ///
  50. /// Error handling:
  51. ///
  52. /// - If invalid \a event type is given, std::invalid_argument is throw.
  53. /// - All other applicative errors are always reported using event handler \a h and never thrown directly.
  54. ///
  55. void set_io_event(native_type fd,int event,event_handler const &h);
  56. ///
  57. /// Cancel all io-events for file descriptor \a fd. Event handlers associated with this descriptor are
  58. /// dispatched asynchronously with aio_error::canceled error code.
  59. ///
  60. void cancel_io_events(native_type fd);
  61. ///
  62. /// Create a timer that expires in \a point time, that is handled with \a h handler.
  63. /// the handler will be called only in two cases:
  64. ///
  65. /// - When the current time >= \a point.
  66. /// - Timer was canceled. \a h will be dispatched with aio_error::canceled error code.
  67. ///
  68. /// The return value is special identification for the specific timer, it can be used for timer cancellation.
  69. /// Once cancel_timer_event is called with this unique identification, it should never be called again with
  70. /// this id as other timer may receive this identification.
  71. ///
  72. int set_timer_event(ptime const &point,event_handler const &h);
  73. ///
  74. /// Cancel timer created with set_timer_event() asynchronously,
  75. ///
  76. void cancel_timer_event(int event_id);
  77. ///
  78. /// Run main event loop. This function starts actual event loop. It does not return until stop
  79. /// is called or error occurs.
  80. ///
  81. /// If error occurs (exception is thrown) you may try to restart the event loop by calling run once again.
  82. ///
  83. /// However if run() is exited normally (i.e. by calling stop()) then you need to call reset() member function
  84. /// before next call of run().
  85. ///
  86. void run();
  87. ///
  88. /// Same as run(), but, event-loop specific errors are reported via \a e error code rather then by throwing.
  89. /// Note, event handlers still may throw.
  90. ///
  91. void run(system::error_code &e);
  92. ///
  93. /// Prepare the service after it was stopped. This function is not thread safe.
  94. ///
  95. void reset();
  96. ///
  97. /// Stop the service. All threads executing run() function will exit from it. You can't use this service
  98. /// till you call reset() function.
  99. ///
  100. void stop();
  101. ///
  102. /// Post a single handler \a h for immediate execution in the event loop queue. Useful for execution of some
  103. /// job in the thread that runs the event loop of the io_service.
  104. ///
  105. void post(handler const &h);
  106. ///
  107. /// Post event completion hander with its status
  108. ///
  109. /// \ver{v1_2}
  110. void post(event_handler const &h,booster::system::error_code const &e);
  111. ///
  112. /// Post event i/o completion hander with its status and i/o size
  113. ///
  114. /// \ver{v1_2}
  115. void post(io_handler const &h,booster::system::error_code const &e,size_t n);
  116. ///
  117. /// Get the real name of the reactor that io_service uses (calls reactor::name())
  118. ///
  119. std::string reactor_name();
  120. private:
  121. struct data;
  122. hold_ptr<data> d;
  123. std::auto_ptr<event_loop_impl> impl_;
  124. };
  125. } // aio
  126. } // booster
  127. #endif