Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue #419 #446

Merged
merged 2 commits into from Sep 19, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion boost/network/protocol/http/algorithms/linearize.hpp
Expand Up @@ -2,6 +2,7 @@
#define BOOST_NETWORK_PROTOCOL_HTTP_ALGORITHMS_LINEARIZE_HPP_20101028

// Copyright 2010 Dean Michael Berris.
// Copyright 2014 Jussi Lyytinen
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -137,7 +138,7 @@ BOOST_CONCEPT_REQUIRES(((ClientRequest<Request>)), (OutputIterator))
*oi = consts::colon_char();
*oi = consts::space_char();
boost::copy(request.host(), oi);
boost::optional<boost::uint16_t> port_ = port(request);
boost::optional<boost::uint16_t> port_ = port(request).as_optional();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one in particular you may want to wrap in something like this:

boost::optional<boost::uint16_t> port_ =
#if (_MSC_VER >= 1600)
  port(port).as_optional();
#else
  port(port);
#endif

if (port_) {
string_type port_str = boost::lexical_cast<string_type>(*port_);
*oi = consts::colon_char();
Expand Down
24 changes: 11 additions & 13 deletions boost/network/protocol/http/message/wrappers/port.hpp
Expand Up @@ -4,6 +4,7 @@
// Copyright 2010, 2014 Dean Michael Berris <dberris@google.com>
// Copyright 2010 (c) Sinefunc, Inc.
// Copyright 2014 Google, Inc.
// Copyright 2014 Jussi Lyytinen
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
Expand Down Expand Up @@ -31,23 +32,20 @@ struct port_wrapper {

operator port_type() const { return message_.port(); }

#if (_MSC_VER >= 1600)
// We hack this so that we don't run into the issue of MSVC 2010 not doing the
// right thing when converting/copying Boost.Optional objects.
struct optional_wrapper {
boost::optional<boost::uint16_t> o_;
explicit optional_wrapper(boost::optional<boost::uint16_t> o) : o_(o) {}
operator boost::optional<boost::uint16_t>() const { return o_; }
};

operator optional_wrapper() const {
return optional_wrapper(uri::port_us(message_.uri()));
}
#else
#if !defined(_MSC_VER)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure this is what we want. Checking that the version is above a certain threshold would be preferred, in my opinion. Something like:

#if (_MSC_VER >= 1600 && BOOST_VERSION >= ...)
  // code for the MSVC 2010+ versions and Boost 1.56.0
#else
  // the normal non-broken conversion operator
#endif

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do that then. I deliberately did it this way though so that users would have the option not to use conditional directives in their code and instead just use the explicit conversion.

// Because of a breaking change in Boost 1.56 to boost::optional, implicit
// conversions no longer work correctly with MSVC. The conversion therefore
// has to be done explicitly with as_optional(). This method is here just
// to maintain backwards compatibility with compilers not affected by the
// change.
operator boost::optional<boost::uint16_t>() const {
return uri::port_us(message_.uri());
}
#endif

boost::optional<boost::uint16_t> as_optional() const {
return uri::port_us(message_.uri());
}

};

Expand Down