Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
a370594
Run clang-tidy with all checks.
deanberris Oct 28, 2015
44bd36b
Manual changes to update style and fix breakages
deanberris Oct 28, 2015
5f6e9ee
Changes to make things build
deanberris Oct 31, 2015
7b88a41
Reintroduce missing code for parsing query maps
deanberris Oct 31, 2015
6349c11
clang-tidy modernize-.* all the things
deanberris Nov 2, 2015
6d8879c
Upgrade travis config
deanberris Nov 2, 2015
65a0e6e
Fix typo in URL
deanberris Nov 2, 2015
feec209
Fix another typo on the URL.
deanberris Nov 2, 2015
4847865
Make travis wait for a Boost build to finish
deanberris Nov 2, 2015
e19af74
Change level of travis_wait call; chmod +x .sh files
deanberris Nov 2, 2015
abe68b4
Only support Boost 1.59 for now.
deanberris Nov 2, 2015
b10dfbb
Only produce shared+multithreaded debug & release boost libs
deanberris Nov 2, 2015
8cb4c16
Looks like we need static libs too
deanberris Nov 2, 2015
198dd07
Integrate travis; Use Boost 1.57 at least; Always use shared libs fro…
deanberris Nov 2, 2015
f6c7ee6
Use the dynamic version of Boost.Test always.
deanberris Nov 2, 2015
de7c710
Use v4 again instead of just address
deanberris Nov 4, 2015
39a2705
v4() for real this time
deanberris Nov 4, 2015
2e3340f
Change test to fetch different targets
deanberris Nov 12, 2015
7e0f93e
Simplify http test
deanberris Nov 12, 2015
552401b
Use ninja-build
deanberris Nov 12, 2015
19beafb
Update cmake
deanberris Nov 12, 2015
99f6168
Use updated cmake to support ninja-build
deanberris Nov 12, 2015
937d589
Travis cannot handle ninja builds yet, probably to lack of resources …
deanberris Nov 12, 2015
d5ec24e
j4 is too much. :(
deanberris Nov 12, 2015
d661fcc
Check with the sanitizers
deanberris Nov 12, 2015
5751338
Honor the CMAKE_CXX_FLAGS environment variable
deanberris Nov 12, 2015
511dd04
Print latest log properly
deanberris Nov 12, 2015
9fbc300
Fix some issues with the (deprecated) synchronous client implementati…
deanberris Nov 16, 2015
2f2239c
Only use libc++ if in OS X
deanberris Nov 16, 2015
4be4eae
Issue identified with memory sanitizer
deanberris Nov 16, 2015
600daff
Fix unsafe usage of boost::as_literal, caught by memory sanitiser
deanberris Nov 16, 2015
03870ca
Force use of size_t in distance calculation
deanberris Nov 16, 2015
9bad07c
Removing noexcept from defaulted move constructor
deanberris Nov 18, 2015
2f2c021
Track origins for memsan runs
deanberris Nov 18, 2015
7f70dac
Exclude msan builds from g++
deanberris Nov 18, 2015
8a8279a
Do not use msan yet; Boost seems to be not msan-clean
deanberris Nov 18, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix some issues with the (deprecated) synchronous client implementati…
…on running under tsan; also require C++11 in GNU compilers moving forward by default
  • Loading branch information
deanberris committed Nov 16, 2015
commit 9fbc3008679edf85bc866196e55fe2abf9580f43
14 changes: 5 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,12 @@ if (OPENSSL_FOUND)
endif()

if (${CMAKE_CXX_COMPILER_ID} MATCHES GNU)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
# Use C++11 when using GNU compilers.
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11")
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES Clang)
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# We want to link in C++11 mode if we're using Clang and on OS X.
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -ftemplate-depth=256 -std=c++11 -stdlib=libc++")
else()
# We just add the -Wall and a high enough template depth
# flag for Clang in other systems.
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -ftemplate-depth=256")
endif()
# We want to link in C++11 mode in Clang too, but also set a high enough
# template depth for the template metaprogramming.
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -ftemplate-depth=256 -std=c++11 -stdlib=libc++")
endif()


Expand Down
19 changes: 12 additions & 7 deletions boost/network/protocol/http/client/connection/sync_normal.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// http://www.boost.org/LICENSE_1_0.txt)

#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/streambuf.hpp>
#include <boost/network/protocol/http/algorithms/linearize.hpp>
#include <boost/network/protocol/http/response.hpp>
#include <boost/network/protocol/http/traits/resolver_policy.hpp>
Expand Down Expand Up @@ -97,7 +98,8 @@ struct http_sync_connection
connection_base::read_body(socket_, response_, response_buffer);
typename headers_range<basic_response<Tag> >::type connection_range =
headers(response_)["Connection"];
if (version_major == 1 && version_minor == 1 && !boost::empty(connection_range) &&
if (version_major == 1 && version_minor == 1 &&
!boost::empty(connection_range) &&
boost::iequals(boost::begin(connection_range)->second, "close")) {
close_socket();
} else if (version_major == 1 && version_minor == 0) {
Expand All @@ -109,19 +111,22 @@ struct http_sync_connection

void close_socket() {
timer_.cancel();
if (!is_open()) { return;
}
if (!is_open()) {
return;
}
boost::system::error_code ignored;
socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both, ignored);
if (ignored != nullptr) { return;
}
if (ignored != nullptr) {
return;
}
socket_.close(ignored);
}

private:
void handle_timeout(boost::system::error_code const& ec) {
if (!ec) { close_socket();
}
if (!ec) {
close_socket();
}
}

int timeout_;
Expand Down
77 changes: 42 additions & 35 deletions boost/network/protocol/http/policies/pooled_connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <boost/network/protocol/http/traits/resolver_policy.hpp>

#include <boost/algorithm/string/predicate.hpp>
#include <boost/network/protocol/http/client/connection/sync_base.hpp>
#include <boost/network/protocol/http/response.hpp>
#include <boost/network/protocol/http/traits/resolver_policy.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/unordered_map.hpp>
#include <utility>

Expand All @@ -37,7 +37,7 @@ struct pooled_connection_policy : resolver_policy<Tag>::type {
system::error_code const&)> body_callback_function_type;
typedef function<bool(string_type&)> body_generator_function_type;

void cleanup() { host_connection_map().swap(host_connections); }
void cleanup() { host_connection_map().swap(host_connections_); }

struct connection_impl {
typedef function<shared_ptr<connection_impl>(
Expand All @@ -47,10 +47,10 @@ struct pooled_connection_policy : resolver_policy<Tag>::type {
get_connection_function;

connection_impl(
resolver_type& resolver, bool follow_redirect, string_type /*unused*/const& host,
string_type const& port, resolver_function_type resolve,
get_connection_function get_connection, bool https,
bool always_verify_peer, int timeout,
resolver_type& resolver, bool follow_redirect,
string_type /*unused*/ const& host, string_type const& port,
resolver_function_type resolve, get_connection_function get_connection,
bool https, bool always_verify_peer, int timeout,
optional<string_type> const& certificate_filename =
optional<string_type>(),
optional<string_type> const& verify_path = optional<string_type>(),
Expand All @@ -77,7 +77,7 @@ struct pooled_connection_policy : resolver_policy<Tag>::type {
(void)port;
}

basic_response<Tag> send_request(string_type /*unused*/const& method,
basic_response<Tag> send_request(string_type const& method,
basic_request<Tag> request_, bool get_body,
body_callback_function_type callback,
body_generator_function_type generator) {
Expand All @@ -86,7 +86,7 @@ struct pooled_connection_policy : resolver_policy<Tag>::type {

private:
basic_response<Tag> send_request_impl(
string_type /*unused*/const& method, basic_request<Tag> request_, bool get_body,
string_type const& method, basic_request<Tag> request_, bool get_body,
body_callback_function_type callback,
body_generator_function_type generator) {
// TODO(dberris): review parameter necessity.
Expand All @@ -113,8 +113,7 @@ struct pooled_connection_policy : resolver_policy<Tag>::type {

try {
pimpl->read_status(response_, response_buffer);
}
catch (boost::system::system_error& e) {
} catch (boost::system::system_error& e) {
if (!retry && e.code() == boost::asio::error::eof) {
retry = true;
pimpl->init_socket(request_.host(),
Expand Down Expand Up @@ -182,49 +181,57 @@ struct pooled_connection_policy : resolver_policy<Tag>::type {

typedef shared_ptr<connection_impl> connection_ptr;

typedef unordered_map<string_type, connection_ptr> host_connection_map;
host_connection_map host_connections;
typedef unordered_map<string_type, weak_ptr<connection_impl>> host_connection_map;
boost::mutex host_mutex_;
host_connection_map host_connections_;
bool follow_redirect_;
int timeout_;

connection_ptr get_connection(
resolver_type& resolver, basic_request<Tag> const& request_,
bool always_verify_peer,
optional<string_type> /*unused*/const& certificate_filename =
optional<string_type> const& certificate_filename =
optional<string_type>(),
optional<string_type> const& verify_path = optional<string_type>(),
optional<string_type> const& certificate_file = optional<string_type>(),
optional<string_type> const& private_key_file = optional<string_type>(),
optional<string_type> const& ciphers = optional<string_type>()) {
string_type index =
(request_.host() + ':') + lexical_cast<string_type>(request_.port());
connection_ptr connection_;
typename host_connection_map::iterator it = host_connections.find(index);
if (it == host_connections.end()) {
connection_.reset(new connection_impl(
resolver, follow_redirect_, request_.host(),
lexical_cast<string_type>(request_.port()),
boost::bind(&pooled_connection_policy<Tag, version_major,
version_minor>::resolve,
this, boost::arg<1>(), boost::arg<2>(), boost::arg<3>()),
boost::bind(&pooled_connection_policy<Tag, version_major,
version_minor>::get_connection,
this, boost::arg<1>(), boost::arg<2>(),
always_verify_peer, boost::arg<3>(), boost::arg<4>(),
boost::arg<5>(), boost::arg<6>(), boost::arg<7>()),
boost::iequals(request_.protocol(), string_type("https")),
always_verify_peer, timeout_, certificate_filename, verify_path,
certificate_file, private_key_file, ciphers, 0));
host_connections.insert(std::make_pair(index, connection_));
return connection_;
boost::mutex::scoped_lock lock(host_mutex_);
auto it = host_connections_.find(index);
if (it != host_connections_.end()) {
// We've found an existing connection; but we should check if that
// connection hasn't been deleted yet.
auto result = it->second.lock();
if (!result) return result;
}
return it->second;

connection_ptr connection(new connection_impl(
resolver, follow_redirect_, request_.host(),
lexical_cast<string_type>(request_.port()),
// resolver function
boost::bind(&pooled_connection_policy<Tag, version_major,
version_minor>::resolve,
this, boost::arg<1>(), boost::arg<2>(), boost::arg<3>()),
// connection factory
boost::bind(&pooled_connection_policy<Tag, version_major,
version_minor>::get_connection,
this, boost::arg<1>(), boost::arg<2>(), always_verify_peer,
boost::arg<3>(), boost::arg<4>(), boost::arg<5>(),
boost::arg<6>(), boost::arg<7>()),
boost::iequals(request_.protocol(), string_type("https")),
always_verify_peer, timeout_, certificate_filename, verify_path,
certificate_file, private_key_file, ciphers, 0));
host_connections_.insert(std::make_pair(index, connection));
return connection;
}

pooled_connection_policy(bool cache_resolved, bool follow_redirect,
int timeout)
: resolver_base(cache_resolved),
host_connections(),
host_mutex_(),
host_connections_(),
follow_redirect_(follow_redirect),
timeout_(timeout) {}
};
Expand Down