client-cpp  0.10.0
HttpUtils.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014-2016 CyberVision, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef HTTPUTILS_HPP_
18 #define HTTPUTILS_HPP_
19 
20 #include <cstdint>
21 #include <string>
22 
23 #ifdef QNX_650_CPP11_TO_STRING_PATCH
24 #include <custom/string.h>
25 #endif
26 
27 #include <boost/asio.hpp>
28 
29 namespace kaa {
30 
31 class HttpUtils {
32 public:
33  static boost::asio::ip::tcp::endpoint resolveEndpoint(std::string host,
34  std::uint16_t port,
35  boost::system::error_code& errorCode)
36  {
37  boost::asio::io_service io_service;
38  boost::asio::ip::tcp::resolver resolver(io_service);
39  boost::asio::ip::tcp::resolver::query query(host,
40  std::to_string(port),
41  boost::asio::ip::resolver_query_base::numeric_service);
42 
43  auto endpointIt = resolver.resolve(query, errorCode);
44 
45  if (errorCode) {
46  return boost::asio::ip::tcp::endpoint();
47  }
48 
49  return *endpointIt;
50  }
51 };
52 
53 }
54 
55 
56 #endif /* HTTPUTILS_HPP_ */
static boost::asio::ip::tcp::endpoint resolveEndpoint(std::string host, std::uint16_t port, boost::system::error_code &errorCode)
Definition: HttpUtils.hpp:33