Kea  1.5.0
asio_wrapper.h
Go to the documentation of this file.
1 // Copyright (C) 2016-2017 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 
9 // !!! IMPORTANT THIS IS A HACK FOR BOOST HEADERS ONLY BUILDING !!!!
10 //
11 // As of #5215 (Kea 1.3) The default build configuration is to link with
12 // Boost's system library (boost_system) rather than build with Boost's
13 // headers only. Linking with the boost_system eliminates the issue as
14 // detailed below. This file exists solely for the purpose of allowing
15 // people to attempt to build headers only. ISC DOES NOT RECOMMEND
16 // building Kea with Boost headers only.
17 //
18 // This file must be included anywhere one would normally have included
19 // boost/asio.hpp. Until the issue described below is resolved in some
20 // other fashion, (or we abandon support for headers only building)
21 // asio.hpp MUST NOT be included other than through this file.
22 //
23 // The optimizer as of gcc 5.2.0, may not reliably ensure a single value
24 // returned by boost::system::system_category() within a translation unit
25 // when building the header only version of the boost error handling.
26 // See Trac #4243 for more details. For now we turn off optimization for
27 // header only builds the under the suspect GCC versions.
28 //
29 // The issue arises from in-lining the above function, which returns a
30 // reference to a local static variable, system_category_const. This leads
31 // to situations where a construct such as the following:
32 //
33 // {{{
34 // if (ec == boost::asio::error::would_block
35 // || ec == boost::asio::error::try_again)
36 // return false;
37 // }}}
38 //
39 // which involve implicit conversion of enumerates to error_code instances
40 // to not evaluate correctly. During the implicit conversion the error_code
41 // instances may be assigned differing values error_code:m_cat. This
42 // causes two instances of error_code which should have been equal to
43 // to not be equal.
44 //
45 // The problem disappears if either error handling code is not built header
46 // only as this results in a single definition of system_category() supplied
47 // by libboost_system; or the error handling code is not optimized.
48 //
49 // We're doing the test here, rather than in configure to guard against the
50 // user supplying the header only flag via environment variables.
51 //
52 // We opened bugs with GNU and BOOST:
53 //
54 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69789
55 // https://svn.boost.org/trac/boost/ticket/11989
56 //
57 // @todo Version 6.0 will need to be tested.
58 //
59 // As of 2016-08-19, the version 5.4.0 from Ubuntu 16.04 is affected. Updated
60 // the check to cover everything that is not 6.0, hoping that 6.0 solves the
61 // problem.
62 
63 #define GNU_CC_VERSION (__GNUC__ * 10000 \
64  + __GNUC_MINOR__ * 100 \
65  + __GNUC_PATCHLEVEL__)
66 
67 #if (defined(__GNUC__) && \
68  ((GNU_CC_VERSION >= 50200) && (GNU_CC_VERSION < 60000)) \
69  && defined(BOOST_ERROR_CODE_HEADER_ONLY))
70 #pragma GCC push_options
71 #pragma GCC optimize ("O0")
72 #include <boost/asio.hpp>
73 #pragma GCC pop_options
74 #else
75 #include <boost/asio.hpp>
76 #endif
77 
78 #endif // ASIO_WRAPPER_H