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.
 
 
 
 
 
 

123 lines
3.6 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_REACTOR_H
  9. #define BOOSTER_AIO_REACTOR_H
  10. #include <booster/config.h>
  11. #include <booster/aio/types.h>
  12. #include <booster/auto_ptr_inc.h>
  13. #include <string>
  14. namespace booster {
  15. namespace aio {
  16. class reactor_impl;
  17. ///
  18. /// \brief This class is an abstraction of platform dependent polling API.
  19. ///
  20. /// It abstracts platform specific APIs like epoll, /dev/poll, kqueue, poll
  21. /// and select.
  22. ///
  23. /// It provides platform independent functionality for polling file descriptions
  24. /// in an efficient way
  25. ///
  26. class BOOSTER_API reactor : public io_events {
  27. reactor(reactor const &);
  28. void operator=(reactor const &);
  29. public:
  30. static const int use_default = 0; //< Best polling device available on the OS
  31. static const int use_select = 1; //< select() API, default on Windows
  32. static const int use_poll = 2; //< poll() API default on POSIX platforms without better polling support
  33. static const int use_epoll = 3; //< epoll() available and default on Linux
  34. static const int use_dev_poll = 4; //< /dev/poll available and default on Solaris and HP-UX
  35. static const int use_kqueue = 5; //< kqueue available and default on BSD and Mac OS X.
  36. static const int use_max = use_kqueue; //< Maximal number
  37. /// \brief structure that defines output events
  38. struct event {
  39. native_type fd; //< A descriptor that event occurred on
  40. int events; //< a bit mask of events \see io_events
  41. };
  42. ///
  43. /// Create a new polling device using \a hint recommendation. If provided
  44. /// device is not supported the default is used
  45. ///
  46. reactor(int hint = use_default);
  47. ~reactor();
  48. ///
  49. /// Add \a fd to watch list, flags can be a or mask of \ref io_events::in, \ref io_events::out
  50. /// and \ref io_events::err
  51. ///
  52. /// If flags=0 removes the \a fd from the watch list
  53. ///
  54. /// If error occurs throws \ref system::system_error
  55. ///
  56. void select(native_type fd,int flags);
  57. ///
  58. /// Add \a fd to watch list, flags can be a or mask of \ref io_events::in,
  59. /// \ref io_events::out and \ref io_events::err
  60. ///
  61. /// If flags=0 removes the \a fd from the watch list
  62. ///
  63. /// If error occurs, the error code is assigned to \a e
  64. ///
  65. void select(native_type fd,int flags,system::error_code &e);
  66. ///
  67. /// Removes the \a fd from the watch list
  68. ///
  69. /// If error occurs throws \ref system::system_error
  70. ///
  71. void remove(native_type fd)
  72. {
  73. select(fd,0);
  74. }
  75. ///
  76. /// Removes the \a fd from the watch list
  77. ///
  78. /// If error occurs, the error code is assigned to \a e
  79. ///
  80. void remove(native_type fd,system::error_code &e)
  81. {
  82. select(fd,0,e);
  83. }
  84. ///
  85. /// Poll for the events, wait at most \a timeout microseconds.
  86. /// Save up to \a n values to the \a events vector.
  87. ///
  88. /// Returns number of events recorded. Returns 0 if timeout occurred.
  89. ///
  90. /// If error occurs throws \ref system::system_error
  91. ///
  92. int poll(event *events,int n,int timeout);
  93. ///
  94. /// Poll for the events, wait at most \a timeout microseconds.
  95. /// Save up to \a n values to the \a events vector.
  96. ///
  97. /// Returns number of events recorded. Returns 0 if timeout occurred.
  98. ///
  99. /// If error occurs, the error code is assigned to \a e
  100. ///
  101. int poll(event *events,int n,int timeout,system::error_code &e);
  102. ///
  103. /// Get the actual name of the polling device used.
  104. ///
  105. std::string name() const;
  106. private:
  107. std::auto_ptr<reactor_impl> impl_;
  108. };
  109. } // aio
  110. } // booster
  111. #endif