asio_wrapper.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 disappears if either error handling code is not built header
  37. // only as this results in a single definition 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 Version 6.0 will need to be tested.
  49. //
  50. // As of 2016-08-19, the version 5.4.0 from Ubuntu 16.04 is affected. Updated
  51. // the check to cover everything that is not 6.0, hoping that 6.0 solves the
  52. // problem.
  53. #define GNU_CC_VERSION (__GNUC__ * 10000 \
  54. + __GNUC_MINOR__ * 100 \
  55. + __GNUC_PATCHLEVEL__)
  56. #if (defined(__GNUC__) && \
  57. ((GNU_CC_VERSION >= 50200) && (GNU_CC_VERSION < 60000)) \
  58. && defined(BOOST_ERROR_CODE_HEADER_ONLY))
  59. #pragma GCC push_options
  60. #pragma GCC optimize ("O0")
  61. #include <boost/asio.hpp>
  62. #pragma GCC pop_options
  63. #else
  64. #include <boost/asio.hpp>
  65. #endif
  66. #endif // ASIO_WRAPPER_H