asio_wrapper.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (C) 2016 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 ASIO_WRAPPER_H
  7. #define ASIO_WRAPPER_H 1
  8. // !!! IMPORTANT !!!!
  9. // This file must be included anywhere one would normally have included
  10. // boost/asio.hpp. Until the issue described below is resolved in some
  11. // other fashion asio.hpp should not be included other than through
  12. // this file.
  13. //
  14. // The optimizer as of gcc 5.2.0, may not reliably ensure a single value
  15. // returned by boost::system::system_category() within a translation unit
  16. // when building the header only version of the boost error handling.
  17. // See Trac #4243 for more details. For now we turn off optimization for
  18. // header only builds the under the suspect GCC versions.
  19. //
  20. // The issue arises from in-lining the above function, which returns a
  21. // reference to a local static variable, system_category_const. This leads
  22. // to situations where a construct such as the following:
  23. //
  24. // {{{
  25. // if (ec == boost::asio::error::would_block
  26. // || ec == boost::asio::error::try_again)
  27. // return false;
  28. // }}}
  29. //
  30. // which involve implicit conversion of enumerates to error_code instances
  31. // to not evaluate correctly. During the implicit conversion the error_code
  32. // instances may be assigned differeing values error_code:m_cat. This
  33. // causes two instances of error_code which should have been equal to
  34. // to not be equal.
  35. //
  36. // The problem disappers if either error handling code is not built header
  37. // only as this results in a single definiton of system_category() supplied
  38. // by libboost_system; or the error handling code is not optimized.
  39. //
  40. // We're doing the test here, rather than in configure to guard against the
  41. // user supplying the header only flag via environment variables.
  42. //
  43. // We opened bugs with GNU and BOOST:
  44. //
  45. // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69789
  46. // https://svn.boost.org/trac/boost/ticket/11989
  47. //
  48. // @todo Currently, 5.3.0 is the latest released versio of GCC. Version 6.0 is
  49. // in development and will need to be tested.
  50. #define GNU_CC_VERSION (__GNUC__ * 10000 \
  51. + __GNUC_MINOR__ * 100 \
  52. + __GNUC_PATCHLEVEL__)
  53. #if (defined(__GNUC__) && \
  54. ((GNU_CC_VERSION >= 50200) && (GNU_CC_VERSION <= 50301)) \
  55. && defined(BOOST_ERROR_CODE_HEADER_ONLY))
  56. #pragma GCC push_options
  57. #pragma GCC optimize ("O0")
  58. #include <boost/asio.hpp>
  59. #pragma GCC pop_options
  60. #else
  61. #include <boost/asio.hpp>
  62. #endif
  63. #endif // ASIO_WRAPPER_H