diff options
Diffstat (limited to 'src/rpcprotocol.h')
-rw-r--r-- | src/rpcprotocol.h | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/rpcprotocol.h b/src/rpcprotocol.h index 8b3df19621..5627077bfb 100644 --- a/src/rpcprotocol.h +++ b/src/rpcprotocol.h @@ -103,11 +103,27 @@ public: } bool connect(const std::string& server, const std::string& port) { - boost::asio::ip::tcp::resolver resolver(stream.get_io_service()); - boost::asio::ip::tcp::resolver::query query(server.c_str(), port.c_str()); - boost::asio::ip::tcp::resolver::iterator endpoint_iterator = resolver.resolve(query); - boost::asio::ip::tcp::resolver::iterator end; + using namespace boost::asio::ip; + tcp::resolver resolver(stream.get_io_service()); + tcp::resolver::iterator endpoint_iterator; +#if BOOST_VERSION >= 104300 + try { +#endif + // The default query (flags address_configured) tries IPv6 if + // non-localhost IPv6 configured, and IPv4 if non-localhost IPv4 + // configured. + tcp::resolver::query query(server.c_str(), port.c_str()); + endpoint_iterator = resolver.resolve(query); +#if BOOST_VERSION >= 104300 + } catch(boost::system::system_error &e) + { + // If we at first don't succeed, try blanket lookup (IPv4+IPv6 independent of configured interfaces) + tcp::resolver::query query(server.c_str(), port.c_str(), resolver_query_base::flags()); + endpoint_iterator = resolver.resolve(query); + } +#endif boost::system::error_code error = boost::asio::error::host_not_found; + tcp::resolver::iterator end; while (error && endpoint_iterator != end) { stream.lowest_layer().close(); @@ -125,7 +141,11 @@ private: }; std::string HTTPPost(const std::string& strMsg, const std::map<std::string,std::string>& mapRequestHeaders); -std::string HTTPReply(int nStatus, const std::string& strMsg, bool keepalive); +std::string HTTPError(int nStatus, bool keepalive, + bool headerOnly = false); +std::string HTTPReply(int nStatus, const std::string& strMsg, bool keepalive, + bool headerOnly = false, + const char *contentType = "application/json"); bool ReadHTTPRequestLine(std::basic_istream<char>& stream, int &proto, std::string& http_method, std::string& http_uri); int ReadHTTPStatus(std::basic_istream<char>& stream, int &proto); |